How can I query about code owners for a PR? #24702
-
I’d like to fetch the code owners associated with a pull request or at least the repository. Is this possible through existing APIs or does this feature not exist? My backup plan is to write code owner evaluation logic myself, but that seems like it shouldn’t be necessary. |
Beta Was this translation helpful? Give feedback.
Replies: 17 comments 2 replies
-
Through the existing API, you can fetch pull request author, repo owner of the source of the pull request, assignees, users that merges the pull request, and get commits with committers and authors. What are you looking for specifically? |
Beta Was this translation helpful? Give feedback.
-
I want to find the code owners requested for review on a specific PR. It doesn’t seem possible through the API. |
Beta Was this translation helpful? Give feedback.
-
https://help.github.com/en/articles/about-code-owners > Code owners are automatically requested for review when someone opens a pull request that modifies code that they own. So you could query requested reviewers. |
Beta Was this translation helpful? Give feedback.
-
I wanted to identify if a requested reviewer was requested as a code owner. |
Beta Was this translation helpful? Give feedback.
-
Hi @chdsbd! While it’s not possible to do this with a single API, you can create a script that allows you to crossreference the requested reviewers with the content of the CODEOWNERS file using the Get Contents API endpoint. Since the CODEOWNERS file has a limited number of locations that it can be located, it should be easy to find with a couple of calls. Hope that helps! |
Beta Was this translation helpful? Give feedback.
-
Thanks. That’s what I’ve settled on. The challenge I see is that a user could be in the code owners file but not necessarily be requested because of their ownership. Another user could request their review for code they don’t own. |
Beta Was this translation helpful? Give feedback.
-
@chdsbd, that’s very true. You’d probably have to do some advanced checking of the files in the PR and how they compare to the CODEOWNERS file as well to be sure. |
Beta Was this translation helpful? Give feedback.
-
@that-pat, we have similiar request to check whether the approval is coming from code owner or not, does GitHub have any plan to expose one single API for code owner check? |
Beta Was this translation helpful? Give feedback.
-
Hi @payneChen o/ Since this OP, there have been some internal goings-on, with relation to CODEOWNERS data being available from our APIs. Within the Objects - GitHub DocsContinuing with GraphQL, we also have the Enums - GitHub DocsAs far as I’m aware (currently) we have no REST functionality, or a specific CODEOWNER endpoint as a single source for this information. Very curious to know if the above solves for your use case. If it doesn’t, I would highly recommend submitting your feedback, through this form: support.github.comShare feedback - GitHub Support…which gets reviewed directly by our PMs. Sincerely hope this helps! 🙇 |
Beta Was this translation helpful? Give feedback.
-
It seems like The |
Beta Was this translation helpful? Give feedback.
-
Hey @chdsbd thanks so much for voicing your experience. Very curious to know how your exchange goes with that internal support ticket. If anything seems relevant for the Community, would you mind posting back? Anyone else reading is also empowered to @ mention me and I can see if there was traction that might be suited for a broader audience, than the 1:1 ticket mentioned above. 🙇 |
Beta Was this translation helpful? Give feedback.
-
@nethgato I’m pinging you because we’d really need to have code owner reviews exposed for the REST API too. Is there anything we can help with? |
Beta Was this translation helpful? Give feedback.
-
Hi @jd o/ As-is, the best thing you could do, is to add your voice to those who would like to see similar data in REST, as we have in GraphQL. The most helpful path forward, would be to submit via our feedback form, here: support.github.comShare feedback - GitHub Support//support.github.com/contact/feedback |
Beta Was this translation helpful? Give feedback.
-
This is the best way I’ve found to do this:
Caveats of this approach:
|
Beta Was this translation helpful? Give feedback.
-
@KaranErry There are a few problems with the solution you proposed.
For example, see the below snippet of CODEOWNERS file
If the PR is raised for some file inside The GraphQL solution shared by @nethgato (https://github.com/orgs/community/discussions/24702#discussioncomment-3245124) might help but having a REST API is definitely solves the problem. Not sure why Github isn't exposing this endpoint despite many requests. Some special features related to CODEOWNERS are provided by Github to the cloud version but they aren't existing in on-prem/free version of github. |
Beta Was this translation helpful? Give feedback.
-
Any news on this ? It would be really helpful to be able to know the list of codeowners required to approve a specific PR. I believe it can just be as simple as a user having a special team in the list of reviewers of a PR. |
Beta Was this translation helpful? Give feedback.
-
I see the information is available, but not in the API .... e.g.
gives
When used on a private repo authentication has to be done using a |
Beta Was this translation helpful? Give feedback.
Hi @payneChen o/
Since this OP, there have been some internal goings-on, with relation to CODEOWNERS data being available from our APIs.
Within the
PullRequest
object for GraphQL, we have thereviewDecision
field, which you can see, here:docs.github.com
Objects - GitHub Docs
Continuing with GraphQL, we also have the
PullRequestReviewDecision
enum, which includes the status values for review requests:docs.github.com
Enums - GitHub Docs
As far as I’m aware (currently) we have no REST functionality, or a specific CODEOWNER endpoint as a single source for this information.
Very curious to know if the above solves for your use case. If it doesn’t, I would highly recommend submi…