Fetching PR status, comments, etc. from github API - github

I'm trying to fetch PR status/comments using the github API. Two examples issues:
https://github.com/okta/okta-oidc-js/pull/950
https://github.com/okta/okta-signin-widget/pull/1545
I can get the original PR data via the API by GETting these resources:
https://github.com/okta/okta-oidc-js/pull/950
https://api.github.com/repos/okta/okta-signin-widget/issues/1545
But then I want to find information that these changes were approved, any comments, and the timestamp of those actions, etc. (e.g. "foo approved these changes" and "good catch! thanks for the submission. We'll get this merged.")
I've read the docs and tried following the resources returns from the API, but nothing. I thought the pull_request resource would be useful:
"pull_request": {
"url": "https://api.github.com/repos/okta/okta-signin-widget/pulls/1545
}
But I can still find nothing. I'm sure it's there... Can someone please point me in the right direction?

Well, I looked on the github API forums and found my answer:
It's the reviews resource:
https://api.github.com/repos/okta/okta-signin-widget/pulls/1545/reviews

Related

Is there a way to filter pull requests where my review is stale/dismissed?

On GitHub, I would like to be able to have a list of Pull Requests that require my attention. This must include any pull request that is created by a member of my team that was not authored by me, but requires a review from me. So far, I have this:
is:pr is:open user:<ORGANIZATION> involves:coworker involves:coworker -author:#me -reviewed-by:#me
The problem is, when my review is dismissed or becomes stale, -reviewed-by:#me filters out that pull request because I've previously reviewed it, even though that review has been dismissed. If I've already approved it or if the pull request has changes requested by me that are not outdated, I do not want to see them in the list.
Is there an online query to be able to list these pull requests from github.com/pulls?
Taking inspiration of this use-case which illustrate the power of GitHub CLI gh, you could, for each of the currently listed PR, do a check (using the "List reviews for a pull request" API):
gh api repos/<your repo name>/pulls/<PR ID>/reviews --jq '.[] | [.id,.state] | join("=")' | grep -Po '\d+(?=\=DISMISSED)'
You can add the .user.login attribute to filter on your name and check if you have, for a given PR, reviews in "DISMISSED" state.
If yes, you know you can filter you that PR from your intial query.
This is not straightforward, as some processing is needed, but it can help.

How to fetch JSON about a particular repository using github API

I've read the official documentation (GitHub docs) but it's not very clear about fetching information about a particular repo.
I want to fetch information (in JSON) about a particular repo of mine using browser only (and not Postman).
I tried this URL and it is fetching me all the repositories.
https://api.github.com/users/tmtanzeel/repos
But I need info about a particular repo only. I tried these:
https://api.github.com/users/tmtanzeel/repos/angular-project
https://api.github.com/users/tmtanzeel/repos?name=angular-project
https://api.github.com/users/tmtanzeel/repos?id=191101189
But none is working. Please pitch in.
Ok, I got it. I figured it out.
Solution:
Instaed of /<username>/repos we should be doing /repos/<username>.
Sample:
https://api.github.com/repos/tmtanzeel/repo-name
A lot more information you'll find with the above URL:

I am not able to filter issue via github search api

I am a collaborator for a private repository and able to edit, push code, create issues, close issues, etc on it. I am trying to create a report of issues open and closed on the repository. To achieve this I needed to get issues based on time interval and label. I found that the GitHub search API will be useful for me.
I started out by creating a token (PAT) giving it the whole repo scope
Then to test the API I hit the below URL with the token
https://api.github.com/search/issues?q=repo:orgname/reponame
I am able to get the results.
Then I tried to narrow down by adding is:issue and is:closed qualifier using the same token
https://api.github.com/search/issues?q=repo:orgname/reponame+is:issue+is:closed
I got the below response
{
"message": "Validation Failed",
"errors": [
{
"message": "The listed users and repositories cannot be searched either because the resources do not exist or you do not have permission to view them.",
"resource": "Search",
"field": "q",
"code": "invalid"
}
],
"documentation_url": "https://docs.github.com/v3/search/"
}
The issues are present and I can search it on Github website, but couldn't via github search api. I am able to apply a repo qualifier but couldn't add any other qualifiers.
What am I missing here?
There's two things I've found that can cause this.
In your case it's likely permissions since your encoding appears to be fine.
Searching specifically for PRs or Issues on private repos requires 'content' permissions (this is incorrectly documented in the GitHub docs as requiring metadata permissions). If a user has no public repos but they do have private ones then you get a permission error like the above, rather than the empty response that you get if they have no repos of any kind or only public repos but no matching results.
The other thing I've found that causes this is incorrect encoding of the query. An easy error to make there (from experience) is having the + sign in the query and then encoding it. This encodes the + as %3A whereas what you want is a space between each query term. The space is then encoded as +. Making this encoding mistake will also result in the same permission/not found error.
I appreciate this is probably a little late for you, but hopefully it helps others.

Reference Monday.com item ID in Github commit message

When I reference an Item ID from the Monday App in my git commit it should show up because I have following integration enabled: When a pulse ID is mentioned in a commit in this repository, create an update to the relevant pulse.
I can't get it to show in the item's updates. I tried it like #abc123 or just abc123, both don't do anything and the documentation doesn't seem to be offering an answer.
I am a developer on monday.com and i'll be glad to help you!
When stating the things you tried, yes the way to go to mention a pulse is
#{PULSE_ID} but I do wonder, where do you get your pulse id from?
For example, it is shown at the end of the URL:
Please note that the commit has to be pushed first to your branch/master for it to show up on monday, if it's only locally it won't send us webhooks about it.

Is there a way to get the amount of lines changed in a Pull Request via the Dev Ops Service REST API?

I am currently doing my thesis and analyzing the behavior for code reviews. For this I want to know the size of the pull request that is reviewed. The rest of the information for example authors, reviewers, times etc. I got already by calling the rest API. However I cannot seem to find a way to get the amount of lines changed in each file, or a total number (which is also sufficient).
I have browsed the documentation and found some ways to get amount of files changed, see https://learn.microsoft.com/en-us/rest/api/azure/devops/git/commits/get%20commits?view=azure-devops-rest-5.1. However, I didn't found a way to get the amount of changed lines per file or a total amount.
So is there a way to get amount of lines changed in a Pull Request or between two commits?
For your issue , I am afraid that there is currently no official released REST API to do that. A similar question has been answered in this case ,please refer to it for details, you can refer to these steps to achieve your requirements:
1.Get a list of commits to get a commit’s commit id.
2.Get a commit by commit id (steps 1) to get parents value and repository id (The value at the end of _links>Repository>href) (Using the URL of _links>Changes>href can get file path if you don’t know)
3.Get file diff by this POST request https://dev.azure.com/{organization}/{project}/ _api/_versioncontrol/fileDiff?__v=5&diffParameters=[data 1]&repositoryId=[repository id]
You could also add your request for this feature on our UserVoice site, which is our main forum for product suggestions,our PM and product team will kindly review your suggestion.