Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 8

How can I query about code owners for a PR?

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.

7 Replies
wei
Pilot Lvl 2
Message 2 of 8

Re: How can I query about code owners for a PR?

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?

Copilot Lvl 2
Message 3 of 8

Re: How can I query about code owners for a PR?

I want to find the code owners requested for review on a specific PR. It doesn’t seem possible through the API.
wei
Pilot Lvl 2
Message 4 of 8

Re: How can I query about code owners for a PR?

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.
Copilot Lvl 2
Message 5 of 8

Re: How can I query about code owners for a PR?

I wanted to identify if a requested reviewer was requested as a code owner.
Community Manager
Message 6 of 8

Re: How can I query about code owners for a PR?

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!

Copilot Lvl 2
Message 7 of 8

Re: How can I query about code owners for a PR?

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.
Highlighted
Community Manager
Message 8 of 8

Re: How can I query about code owners for a PR?

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