-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathazure-pipelines.yaml
84 lines (68 loc) · 2.65 KB
/
azure-pipelines.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Auto-update PR branches with the latest target branch changes
# Version: 1.0
# Source: https://github.com/f1x3d/azure-devops-pr-branch-auto-update
trigger:
batch: true
branches:
include:
- '*'
pool:
vmImage: ubuntu-latest
steps:
- checkout: self
clean: true
persistCredentials: true
- pwsh: |
Write-Host '##[command]git config user.email "pipeline@localhost"'
git config user.email "pipeline@localhost"
Write-Host '##[command]git config user.name "Automated Workflow"'
git config user.name "Automated Workflow"
$TargetBranchName = "$(Build.SourceBranch)".replace('refs/heads/', '')
Write-Host "##[command]git fetch origin $TargetBranchName --depth=2147483647"
git fetch origin $TargetBranchName --depth=2147483647
Write-Host "##[command]git checkout $TargetBranchName"
git checkout $TargetBranchName
$PrCommentRequestBody = @{
comments = @(
@{
content = "Please resolve merge conflicts"
commentType = "text"
}
)
status = "active"
} | ConvertTo-Json
$PullRequests = Invoke-RestMethod `
-Method Get `
-Uri '$(System.CollectionUri)$(System.TeamProject)/_apis/git/repositories/$(Build.Repository.Name)/pullrequests?searchCriteria.targetRefName=$(Build.SourceBranch)&api-version=7.0' `
-Authentication Bearer `
-Token (ConvertTo-SecureString $Env:SYSTEM_ACCESSTOKEN -AsPlainText -Force)
foreach ($PullRequest in $PullRequests.value | where isDraft -eq $False)
{
$SourceBranchName = $PullRequest.sourceRefName.replace('refs/heads/', '')
Write-Host "##[command]git fetch origin $SourceBranchName --depth=2147483647"
git fetch origin $SourceBranchName --depth=2147483647
Write-Host "##[command]git checkout $SourceBranchName"
git checkout $SourceBranchName
Write-Host "##[command]git merge $TargetBranchName"
git merge $TargetBranchName
if ($?)
{
Write-Host '##[command]git push origin'
git push origin
}
else
{
Write-Host '##[command]git merge --abort'
git merge --abort
Invoke-RestMethod `
-Method Post `
-Uri "$(System.CollectionUri)/$(System.TeamProject)/_apis/git/repositories/$(Build.Repository.Name)/pullrequests/$($PullRequest.pullRequestId)/threads?api-version=7.0" `
-Authentication Bearer `
-Token (ConvertTo-SecureString $Env:SYSTEM_ACCESSTOKEN -AsPlainText -Force) `
-ContentType "application/json" `
-Body $PrCommentRequestBody
}
}
displayName: Merge changes into the open PRs
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)