Find a commit by oid/sha via graphql (v4) api #24528
Replies: 13 comments 1 reply
-
I was able to find the global node id by using the REST api and then getting the commit via the graphql api:
This seems a bit counter-productive, since I’ve migrated to the graphql api to avoid over-fetching from the REST api. Additional question: Is there any way to see which branch the commit belongs to? I can see that Github Web UI uses an internal API to do this: https://github.com/elastic/kibana/branch_commits/6a97f9a7ee797d302cb4f05120ff935bfe22eba0 |
Beta Was this translation helpful? Give feedback.
-
The v4 equilivent for
is
|
Beta Was this translation helpful? Give feedback.
-
This is great, thanks! I was able to make it work for short sha’s as well:
|
Beta Was this translation helpful? Give feedback.
-
@wei Thanks again for your help. I’m only interested in commits from master - do you know how to limit the results by branch (in addition to sha)? Or alternatively: if it’s possible to see which branch the returned commit object belongs to? (that’ll allow me to discard non-master commits elsewhere in my application). |
Beta Was this translation helpful? Give feedback.
-
I’m also looking to filter by commits to master. Were you able to figure this out @sqren ? |
Beta Was this translation helpful? Give feedback.
-
Not with v4 unfortunately. You can do it with v3: https://developer.github.com/v3/search/#considerations-for-commit-search |
Beta Was this translation helpful? Give feedback.
-
Branch’s are just refs, like commits, and they are eaiser to get I think, because you just need to get it by it’s ref name
And for master it’s even eaiser, because Repisitory has a defaultBranchRef field that usually points to master. |
Beta Was this translation helpful? Give feedback.
-
Hey @jstacoder Thanks for chiming in. I tried your suggestion like:
The commit is retrieved regardless which branch I limit it to. I’d expect the commit to only be found if it’s in the given |
Beta Was this translation helpful? Give feedback.
-
i see what happend, you are going back up to the repo, but you are already there. |
Beta Was this translation helpful? Give feedback.
-
@sqren looks like my original format for the ref was off, because I was going from memory. But yea, it should be |
Beta Was this translation helpful? Give feedback.
-
sorry i answered without really looking at your question, you are getting the commit regardless because you are asking by oid, which doesnt limit itself by anything, to gaurentee you are in the correct repo you cou ask its name, or get the commit message from the latest commit ie:
|
Beta Was this translation helpful? Give feedback.
-
Hi again,
Thanks for the suggestion but I need to know whether the commit is on the given branch. Your suggestion seems to only get the head commit. |
Beta Was this translation helpful? Give feedback.
-
Not sure which commit you mean but you are welcome to use any of the code snippets in this thread. |
Beta Was this translation helpful? Give feedback.
-
With the REST api it is possible to find a commit by the commit sha via this endpoint:
and this
How can I achieve the same via the graphql api? I tried using the search resouce but it seems like it only supports searching across issues, repositories and users - not commits:
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions