4

I am experimenting with GitHub API using octokit ruby gem. My goal is to be able to extract the 'tag' that a commit SHA belongs to.

Now I can easily do this on command line using

> git describe 688ae0b --tags

and get output

> 3.0.1-122-g688ae0b

which tells me Tag, commits since tags, and last commit hash.

How do I get same info from GitHub API?

Answers using GitHub API or Octokit client would both do, as I can translate from one other just fine.

I have looked at a bunch of things like, releases, tags, commits etc.. but none of them give me this information that I can get in one line from command line.

I am not looking for 'how to use github api'. I am looking for specific request or set of requests that will let me derive this information.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Shaunak
  • 17,377
  • 5
  • 53
  • 84

1 Answers1

3

Since there is no easy way to run a query like git describe with the GitHub API, that leaves you with an iterative process involving:

(with base being the commit, and head being the tag)

If there are any result, the commit is accessible from the tag.

(I use a similar approach in "Github API: Finding untagged commits")

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks @VonC. That seems like a good way to proceed. I will try it out and see how it goes.. – Shaunak Jul 28 '15 at 15:24
  • Can you think of any other way without using GitHub API, but not having to have a local clone? May be something with ls-remote? I am looking to write a web-service that can inform the version of the project itself and show it in the footer. I can easily do this using capistrano, but then version will only get bumped when project is deployed.. – Shaunak Jul 28 '15 at 15:26
  • @Shaunak not really. Having an updated local copy of the repo remains the surest way to get that kind of information. – VonC Jul 28 '15 at 16:59
  • @VonC, is this answer still actual nowadays? – elect May 14 '21 at 20:58
  • @elect do you mean still current? Apparently so. Maybe with graphql V4 you might have better results. – VonC May 14 '21 at 21:54