Is there a way to get the latest tag of a given repo using github API v3

后端 未结 4 809
南笙
南笙 2021-02-02 11:10

I am relatively new to the github api and I am struggling to get the latest tag of a given repo.

Q: Why I need that ?

A:

4条回答
  •  情书的邮戳
    2021-02-02 11:41

    You could consider, as an alternative to the GitHub API, a simple script mentioned in "Is there a simple way to “git describe” a remote repository?" (source, by svnpenn):

    #!/usr/bin/awk -f
    BEGIN {
      if (ARGC != 2) {
        print "git-describe-remote.awk https://github.com/stedolan/jq"
        exit
      }
      FS = "[ /^]+"
      while ("git ls-remote " ARGV[1] "| sort -Vk2" | getline) {
        if (!sha)
          sha = substr($0, 1, 7)
        tag = $3
      }
      while ("curl -s " ARGV[1] "/releases/tag/" tag | getline)
        if ($3 ~ "commits")
          com = $2
      printf com ? "%s-%s-g%s\n" : "%s\n", tag, com, sha
    }
    

    That does extract the tag (and more), without having to clone the repo.

    Note: as commented below by Joels Elf, make sure /usr/bin/awk refers to gawk, not mawk.

提交回复
热议问题