How to get stats for Github PRs code reviews - github

I want to get a list of people who did some PR code reviews in my organization in the past month. Also how many code reviews were done by each one of them. It would also be helpful if I can know how many comments each person made. Is there a way to get these stats in UI without doing any code changes?

You have a few options including: the Github API or a proprietary service like PR Stats.
With the Github API you can use the following:
curl \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/OWNER/REPO/pulls/PULL_NUMBER/reviews
With PR Stats you'll need to create a Github Action to include a table of PR stats in each PR you create within Github.

Related

How do I query the Github API using gh CLI for a PRs with specific keyword in title?

I am trying to query the Github API using gh CLI for all PRs with the word Bump in the title however I fail to figure how...
I have tried:
api --method GET /repos/my_name/my_project/pulls -H "Accept: application/vnd.github+json" -f q="Bump in:title"
and
api --method GET '/repos/my_name/my_project/pulls?q=Bump in:title' -H "Accept: application/vnd.github+json"
however the filtering does not apply
I needed to use the search api instead:
gh api '/search/issues?q=is:pr+repo:my_name/my_project+Bump+in:title

How to remove PR review comment?

I submited feedback suggesting changes for pull request and can't remove it.
There were two same blocks with my comment on PR timeline. I removed a second one, but can't do so for the first block, there is no such option, only edit.
The Pull Request Reviews API only includes:
Delete a review comment for a pull request
(using GitHub CLI gh api)
gh api \
--method DELETE \
-H "Accept: application/vnd.github+json" \
/repos/OWNER/REPO/pulls/comments/COMMENT_ID
Try and list all review comments to check the right ID for your review comment, and try to delete it that way.

How do I get the permissions granted directly to people in GitHub repositories via API

In the image below I would like to get the list of users and not the list of teams.
I tried to list the repositories of the members of the organization and later filter by the repositories that belong to the organization, but only the repositories created by the user appear.
$ gh api -H "Accept: application/vnd.github.v3+json" "users/drigos/repos" --jq '.[].name'
bashacks
drigos
genshin-garbage-collector
grafo
grid
hashicorp-vault-test
multimedia-cloud
nodejs-concepts
pulumi-contrib
regex
scripts
timeout
I tried to list teams from an organization repository, but it doesn't display the permission granted to people directly.
$ gh api -H "Accept: application/vnd.github.v3+json" "repos/${ORG_NAME}/${PROJECT_NAME}/teams" --jq '.[].slug'
all
retention
retention-projects
I also tried looking for other endpoints, but I didn't find any with this list of people with permissions, just collaborators, watchers, etc.
Finally I tried to use the API in GraphQL, but I didn't succeed either.

How can I dynamically add a **must** reviewer to Pull request on github via github API

Background:
In Github, we have a shared project which can be updated by all the teams. In this project we have a lot of files belong to one or multiple teams. We can identify a file belong to which team by checking the files(.py) header, like:
# protected-by: teamA, teamB
Now, I am working on protecting the file by adding the teamA and teamB as must reviewers when anyone send a PR having updates on the file.
Problem
So far, I can use CircleCI to detect the changed files, extract the protectors list and set them as reviewers by using Github API like this:
curl --location --request POST -u $GH_USER:$GH_TOKEN \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/OWNER/PROJECT/pulls/${pr_number}/requested_reviewers \
-d "{\"team_reviewers\":[$reviewers]}"
The problem is the reviewers I added are not must reviewers like CODEOWNER, users still could be able to merge without protectors' review. So I am thinking is there anyway to make PR must be reviewed by some reviewers, otherwise can not be merged by using Github API or other methods?

How to check if we are the owners of the repository?

I'm using Github API to fetch data from my repository like below:
curl \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world
documentation: https://docs.github.com/en/rest/reference/repos#get-a-repository
to run this query, in header, I'm also using my access token,
and I have one question, is there any way to check from github api response, that I'm the owner of the repository? I want to create a simple statement that check if responsed repository from github api is my or not(different public repo),
thanks for any help!