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:
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.