I need to get the file changes in a perticular Pull Request in Azure Devops using ResAPI or DotNet Library.
I don't want file changes from Commits in PR.
I didn't find Rest API, is there any way to find it.
Since a pull request is to merge the commits from BranchB to BranchA, we can use the API to get git diff between branches.
In my case, I created a PR to merge BranchB to BranchA.
"title": "PR: B->A",
"sourceRefName": "refs/heads/BranchB",
"targetRefName": "refs/heads/BranchA",
Then I called the sample API and got the response like below.
https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{TheRepoName}/diffs/commits?baseVersion=BranchA&targetVersion=BranchB&api-version=7.1-preview.1
Hope this workaround could be helpful.
Related
Using Azure Devops Api I need to check whether for given Pull Request all changes have been already merged into the target branch.
I can retrieve this info via browser:
Please take note that the conflict info may be outdated due to Microsoft's approach to PRs.
I can't find an answer to this question within json data from Devops Api.
Anyone has a clue?
If a PR have completed merging changes to the target branch, normally there is a new commit generated to the target branch with the commit message like as the format "Merged PR {PR Number}: {PR Title}" by default. You can find it from the commit history of target branch.
Then you can use the Azure DevOps REST API "Commits - Get Changes" to get all the changes for the new commit on the target branch. They also are all the changes merged from the PR.
Apparently this should be done via request to PullRequestCommits API. If the answer is empty, then there are no changes to merge in this particular pull request.
Is it possible to configure merge commit template on Azure DevOps?
I would like to for example to Azure add Pull Request link to merge commit when I'm completing Pull Request.
EDIT:
when I'm completing Pull Request then Azure DevOps shows window Complete pull request like on the picture. Azure DevOps automatically add line Related work items: #29272156 and I would like to Azure DevOps add also link to completed pull request.
You can use Pull request templates: Improve pull request descriptions using templates. All information from the pull request description will be moved to the commit description.
A link to a source pull request you can find in the details tab of your commit:
Additionally, you can find this info in Visual Studio:
I checked several sources, seems possible, but can't get it work.
What I want is that whenever a PR is created and PR build is successful, then a PR release is run and a site is created (either with PR Id or PR source branch, e.g. pr122--xxx.azuresite.net).
From an answer for this question,
Looks like I could use release.artifacts.alias.PULLREQUEST.ID, but when I tried it, this doesn't work at all. Also from the official doc, there is no mention of this variable. Is this only for the new YAML pipeline?
As most of our things are in classic pipeline, the solution I can think of is to parse the build source, which is refs/pull/11201/merge. Looks like 11201 is the Pull Request ID, so I just need to replace refs, pull,merge and "/". But I am not sure if better approaches available.
Following this doc: Deploy pull request Artifacts with Azure Pipelines, we can successfully create a pull request deployment by choosing Azure Repos as the source artifact.
If one pull request is created, a new release will be triggered. And as you have found, the source branch of build source is "refs/pull/{PullRequestId}/merge", so you are right.
In addition, if you set the Azure Repos as the primary artifact, we can get the pull request branch by using the predefined variable Release.Artifacts.{alias}.SourceBranch. In below example, we can use the PowerShell task to run below command.
Write-Host "Release.Artifacts._215.SourceBranch: $(Release.Artifacts._215.SourceBranch)
See: Default variables - General Artifact for details.
Recently I ran into the issue with not being able to publish in azure data factory integrated with azure devops/git. This happened because we tried using powershell to automatically create pipelines based on a json template. When this is done in the data factory using Set-AzDataFactoryV2Pipeline, you by-pass the azure devops integration and the pipeline gets published right away without any commits or pull requests. Below is the error message
Publishing Error
The publish branch is out of sync with the collaboration branch. This is likely due to publishing outside of Git mode. To recover from this state, please refer to our Git troubleshooting guide
The MS GIT troubleshooting guide suggests some hardcore measures to resolve this out-of-sync issues (by deleting and re-creating the repo I believe). In this case, there's an easier and less hardcore way of solving this.
You simply need to:
Create a new branch from your master branch in data factory
Create the same pipeline you created via Set-AzDataFactoryV2Pipeline
Create a pull request and merge it into master
Voila, you'll hopefully be able to publish again as it now will consider the branches to be in sync again
Micosoft now provides guidance on resolving this issue:
From: https://learn.microsoft.com/en-us/azure/data-factory/source-control#stale-publish-branch
Stale publish branch
If the publish branch is out of sync with the
master branch and contains out-of-date resources despite a recent
publish, try following these steps:
Remove your current Git repository
Reconfigure Git with the same
settings, but make sure Import existing Data Factory resources to
repository is selected and choose New branch
Create a pull request to
merge the changes to the collaboration branch
remove your git repo from data factory and create a new with exact same setting.
Go to azure devops and create a new pull request to merge new branch into master.
Link: https://www.datastackpros.com/2020/05/how-to-fix-data-factory-adfpublish.html
under manage -> git configuration -> over write live mode. Use this option this will reset the data factory with the live code.
I've checked VSTS REST API documentation, but I haven't found a method which allows me to get information about the repository creation date.
Is it possible to get such data via the VSTS API?
I don't think it is possible to get the exact date of the moment the operation create repo was completed. However, logically the birthday of the repository is usually considered its first commit date.
If that's what you're looking for, you can achieve your goal with a usual Git command:
git log -1 --reverse --format="format:%ci"
You need to check the first commit date for the repository. Check the Get Commits API:
GET https://{accountName}.visualstudio.com/_apis/git/repositories/{project}/commits?api-version=4.1