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

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.

Related

Fetch AzureDevops build details by Pull Request

My requirement is to tell the user if his/her PR got deployed successfully or not
So I thought,
I can ask user about his PR#
Using PR# - Fetch Build Details
Using BuildID from Step 2, find deployment information
I stuck at step 2
I am using below documentation to fetch build details.
https://learn.microsoft.com/en-us/rest/api/azure/devops/build/builds/list?view=azure-devops-rest-6.0
Not able to find correct usage of reasonFilter parameter to pass pull request id to fetch build details
API URL Info
Build Reson
Can someone help how exactly to use reasonFilter parameter here
tried this _apis/build/builds?api-version=5.1&$top=1&reasonFilter=pullrequest=20056
Regarding the point you're stuck with: The reasonFilter is simply a number of predefined string values you can choose from. For instance, if you specify reasonFilter=pullrequest, you get all builds started by a pull request. Thus, you can't specify the exact PR ID here.
Regarding your requirement in general: I don't think there's an API to strictly tie the PR ID and its build(s). You should look into the Status API instead. The build is just one of the statuses that can be associated with the pull request or, more specifically, with the commit.
So, I would approach your task the following way (note that it's not an exact algorithm, but a number of steps I would try to find the solution):
get the pull request by the PR ID provided by user
find the lastMergeCommit in the response
get the statuses of that merge commit
investigate the collection of GitStatus objects returned back and find out how to filter the build you're looking for (I don't know the format of that response for sure, but I'm confident there's some attribute to judge by)
Hope this can lead you to the right direction.
how exactly to use reasonFilter parameter here tried this _apis/build/builds?api-version=5.1&$top=1&reasonFilter=pullrequest=20056
Based on your requirement, you need to filter the build via build reason and Pull Request ID.
I'm afraid there is no out-of-box parameter to filter by pull request ID in the Rest API.
For a workaround, you can try to add the tag to your build.
Here are the steps:
You can add a step in your build to use Pull Request ID as Build tag. Refer to this doc: AddBuildTag: Add a tag to the build
For example:
- powershell: |
Write-Host "##vso[build.addbuildtag]$env:SYSTEM_PULLREQUEST_PULLREQUESTID"
displayName: 'PowerShell Script'
condition: eq(variables['Build.reason'], 'pullrequest')
You can set the condition to make sure that when the pipeline is triggered by pull request, it will add build tag.
You can add the tagFilters in Rest API to filter the related build.
For example:
Get https://dev.azure.com/org/project/_apis/build/builds?reasonFilter=pullrequest&tagFilters=PullrequestID&api-version=6.0

Fetching PR status, comments, etc. from github API

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

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.

How to get the associated changes, check-in comments and linked work items for a particular build/release in VSTS

I am using SendGrid email extension to trigger a custom email notification after the CI/CD process is complete in VSTS. This email task has HTML content in it which includes some content fetched using standard build/release variables (https://learn.microsoft.com/en-us/vsts/build-release/concepts/definitions/build/variables?tabs=batch).
How do I include associated code changes, check-in comments and linked work items for a particular release in the custom email? Are there any variables I can use? Any work around?
There aren’t the built-in variables that can get code changes, check-in comments and linked work items.
You can get them through REST API during build or release:
Get build changes and work items through Get Build Changes REST API (Build id variable: Build.BuildId during build or Release.Artifacts.{Artifact alias}.BuildId during release) Note: using Build.SourceVersion to get latest version)
Git: Get commit message through Get a batch of commits by a list of commit IDs REST API
TFVC: Get check-in comment through Get list of changesets by a list of IDS REST API
To get changed items, you can use get commit with changed items or Get list of changes in a changeset REST API.
No API to get detail code changes, but you may refer to this related issue: Lines of Code modified in each Commit in TFS rest api. How do i get?
Assuming TFS (which isn't specified in the question or tags), you could also call tf.exe directly to get some of that info. If you don't care about the output format, then the output of the following command produces a report of the Changeset details.
tf vc changeset <changeset id> /loginType:OAuth /login:.,<token> /noprompt
Where <changeset id> is the numeric Build.SourceVersion, and <token> is the System.AccessToken.
Comments and source code edits listing are included in the report.
Note: the agent job has to be given the "Allow scripts to access the OAuth token" permission (check box on the Agent Job properties).
See the updated link below for details on how to access the build variables. Same content as in the question, but new link. Both currently work.
https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml

Github : Automated tagging on Merging of Pull Requests

Is there a way to trigger an automatic, custom tagging of a repository every time a pull request is merged in github ? for example...
After merging "pull request 8", id like to automatically tag the repository at that state as "$Major_Version.$pr_id".
The result might be "0.1.8".
Is this possible?
Worst case, if someone hasn't written a thing to do that yet, is to use the post-receive webhooks https://help.github.com/articles/post-receive-hooks
You'd need an internet-visible web server to do this, and some code to recognize the merge (it will have two parents) and see if it mentions a pull-request.