Query Pull Requests by CommitID without Repository ID - azure-devops

Can I get the Pull Requests by commit ID without providing a repository ID? I am auditing releases and need information provided by PRs. I am starting without repository info in the data so currently need to query the Repository api and then associate the commits to the repositories before I can make the Pull Request query.
Additionally, can this be done with a Get requests? It seems like it should be a get request but currently requires a Post with a body. Instead of an additional api, shouldn't the filtering for PR type just be in the uri parameters?

Have you tried it with GetPullRequestByProject instead?
https://learn.microsoft.com/en-us/rest/api/azure/devops/git/pull%20requests/get%20pull%20requests%20by%20project?view=azure-devops-rest-5.1
Since you already have commit Id, from the response, you can query JSON to retrieve the required information. That will also fulfill the second requirement on GET operation.

Related

How to assign a pull request using the REST API?

I'm creating a GitHub pull request using the appropriate REST API. Specifying a single assignee or an assignees (using either the user login or GitHub's internal id) has no effect. The pull request will be created, but without an assignee set. There also seems to be no other endpoint to explicitly assign a pull request to a user. Now I'm wondering whether it's possible at all to set the assignee of a pull request using the REST API?
Every pull request is an issue, but not every issue is a pull request.
For this reason, "shared" actions for both features, like manipulating
assignees, labels and milestones, are provided within the Issues API.
From PR Doc
So, you can use Add assignees to an issue API to set an assignee(s) to a pull request After PR is created. You need to know its number, which is in the JSON body of Create Pull Request's response.
/repos/{owner}/{repo}/issues/{issue_number}/assignees
where issue_number is same as pr_number

Get the commit comments for a particular branch in stash REST API

My repo is profitmanagement and my branch is release/17.4.0.Apr17, I want to find all the commits and the comments provided during commit for the specific branch.
What is the rest API to use to get this info?
You can use following REST API endpoint provided by Stash:
{your-stash-url}/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/commits
To find commits on a specific branch, use 'until' request query parameter - e.g.:
{your-stash-url}/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/commits?until=refs/heads/{branch-name}
Commit message corresponding to each message can be retrieved from the JSON response returned by the REST API.
The documentation is on: https://docs.atlassian.com/DAC/rest/stash/3.11.6/stash-rest.html#idp2461680

Github Pull Request Checks

Is it possible to create a Github Check for pull requests? I know there are WebHooks, but is there a way to also hook into the UI?
Aim:
Pull Request made. Perform validation and update pull request if valid.
Pull Request merged. Create web call to URL. Update Github issue with confirmation.
What's the best way to do this? Is it only via Web Hooks, API calls and getting write oAuth credentials?
Note: you now (August 2018) officially have the notion of Checks
When checks are set up in a repository, pull requests have a Checks tab where you can view detailed build output from status checks and rerun failed checks.
I know there are WebHooks, but is there a way to also hook into the UI?
The recommended way of doing this is to use required status checks and the Status API, in combination with webhooks:
https://help.github.com/articles/about-required-status-checks/
https://developer.github.com/v3/repos/statuses/
Users set up required status checks on the repository so that merging a pull request is blocked if a specific status isn't success.
At the same time, webhooks trigger an external process when a pull request is updated, and that process creates statuses based on the output of that process. If the process completes successfully, then the process should create a success status which will be shown in the UI and unblock the merging of the pull request.
Is it only via Web Hooks, API calls and getting write oAuth credentials?
In order to create statuses, you will indeed need to authenticate with the credentials of a user that has push access to the repository (e.g. via a token from that user with the right scopes).

How to get pull requests references for an issue

Given a GitHub issue, is there any way to get the pull requests that reference to that issue via API?
That info is showed in the GitHub html page but I can't see nothing in the API documentation.
Is it really possible?
is there any way to get the pull requests that reference to that issue via API
Not directly.
Even the reverse is not possible, as a pull request has a link 'issue' pointing to... itself.
But as mentioned in the issue API:
In the past, pull requests and issues were more closely aligned than they are now.
As far as the API is concerned, every pull request is an issue, but not every issue is a pull request.
This endpoint may also return pull requests in the response. If an issue is a pull request, the object will include a pull_request key.
So you would need to list the comments of a pull request (using the Issue Comments API since comments on PR are done with it), and parse said comment to find a reference to an issue.

Organization level webhooks

Is there a way to receive callback after every action taken on any repo, by any user in my Github organization? I know that there are repo-level webhooks, but if you have many repos in your organization it may be problematic to always keep them up to date in all repos.
Yes, there are organization level hooks which you can configure provided you are an admin of the org. You can read more about it here.
To create a hook for an event on the organization, you would need to make a post request with the payload specified in the documentation to:
POST /orgs/:org/hooks
An events array is passed in the payload that specifies which events the hook is configured for. A config object is passed in the payload, using which you can specify the URL to which the payloads will be delivered.