How to get all commits in a Git tag through GitHub API - github

I have to fetch all new commits that were a part when a new tag was created on a Git repo. This needs to be done through GitHub API.
For example the Git UI says Tagging Tag1 and has a sha associated with it... let's say the sha is : SHA1
Now how do I get all commits which happened or were a part of Tag1 through GitHub API? I want to store all these commits and perform some analysis on them.

Based on the clarification on your comment:
I want to get all commits between this newly created tag and previous tag
1. Get all the tags in a given repo, so you can get the current and the previous tag names
curl -X "GET" "https://api.github.com/repos/:owner/:repo/tags" \
-H "Authorization: token YOUR_GITHUB_ACCESS_TOKEN"
2. Get all the commits between the latest 2 tags
curl -X "GET" "https://api.github.com/repos/:owner/:repo/compare/:tag_1...:tag_2" \
-H "Authorization: token YOUR_GITHUB_ACCESS_TOKEN"
Doc links:
https://developer.github.com/v3/repos/#list-tags
https://developer.github.com/v3/repos/commits/#compare-two-commits

Related

How to get stats for Github PRs code reviews

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.

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 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!

GitHub unicorn when creating PR: "This page is taking too long to load."

When creating a Pull Request on GitHub, the page refuses to load and I am instead shown a unicorn error message:
This page is taking too long to load.
Sorry about that. Please try refreshing and contact us if the problem persists.
This repo's default branch is set to master, which is well behind the development branch we merge into. This error is likely a result of there being too many commits or the resulting PR being "too big".
Is there another URL or method to create a PR without calculating the full diff of the default branch?
If you push a branch, GitHub will helpfully show a Compare & pull request button as a shortcut to creating a PR for that branch:
That button is useful in most circumstances, but does automatically compare against the default branch using this URL:
https://github.com/user/repo/compare/branch?expand=1
If the resulting diff is too big or complicated, the unicorn error message will be shown.
Instead, press the New pull request button. The subsequent page will allow you to select the PR's base and compare branches prior to generating the diff.
https://github.com/user/repo/compare
The diff into your development branch will be simpler, and you should no longer get the error.
I managed to solve by creating the PR via the GitHub API e.g.
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
/repos/OWNER/REPO/pulls \
-f title='Amazing new feature' \
-f body='Please pull these awesome changes in!' \
-f head='octocat:new-feature' \
-f base='master'
https://docs.github.com/en/rest/pulls/pulls#create-a-pull-request