-
Notifications
You must be signed in to change notification settings - Fork 2
/
rebase-bot.yml
98 lines (85 loc) · 3.13 KB
/
rebase-bot.yml
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# Xamarin Rebase Bot build definition: https://devdiv.visualstudio.com/DevDiv/_apps/hub/ms.vss-ciworkflow.build-ci-hub?_a=edit-build-definition&id=13926&view=Tab_Tasks
trigger: none
parameters:
- name: RepoName
displayName: Repository Name
type: string
- name: RepoOrg
displayName: Repository Organization
type: string
- name: SourceBranch
displayName: Branch that needs to be repointed to the latest of the PR target
type: string
- name: TargetBranch
displayName: Target Branch of the PR
type: string
- name: PRNumber
displayName: Pull Request Number
type: number
variables:
- name: GitHubEndpoint
value: ${{ parameters.RepoOrg }}
- name: SourceRepo
value: ${{ parameters.RepoOrg }}/${{ parameters.RepoName }}
- name: SourceBranch
value: ${{ parameters.SourceBranch }}
- name: TargetBranch
value: ${{ parameters.TargetBranch }}
- group: Xamarin-Secrets
resources:
repositories:
- repository: rebaseRepo
type: github
# TODO: is there a way to not hardcode the endpoint?
endpoint: xamarin
name: $(SourceRepo)
ref: $(SourceBranch)
jobs:
- job: RebaseBot
pool:
vmImage: ubuntu-latest
variables:
- name: WorkingDir
value: $(Build.SourcesDirectory)/${{ parameters.RepoName }}
steps:
- checkout: self
- checkout: rebaseRepo
persistCredentials: true
# TODO: redundant, but echo git version
- powershell: |
git --version
git checkout $(SourceBranch)
git status > $(Build.ArtifactStagingDirectory)/git_status.txt
Get-Content $(Build.ArtifactStagingDirectory)/git_status.txt
git diff > $(Build.ArtifactStagingDirectory)/git_diff.txt
workingDirectory: $(WorkingDir)
displayName: Check Branch Status
- powershell: |
git config user.email "[email protected]"
git config user.name "vs-mobiletools-engineering-service2"
git fetch origin $(TargetBranch)
git rebase origin/$(TargetBranch)
git push --force-with-lease
workingDirectory: $(WorkingDir)
displayName: Perform Rebase
- powershell: |
if ("$(Agent.JobStatus)".Equals("Succeeded")) {
$state = "success"
$desc = "succeeded"
$message = "Hooray"
} else {
$state = "failure"
$desc = "failed"
$message = "Oh no"
}
$buildUri = "$(System.CollectionUri)$(System.TeamProject)/_build/results?buildId=$(Build.BuildId)"
$headers = @{ Authorization = "token $(github--pat--vs-mobiletools-engineering-service2)" }
# Comment on the original PR
$commentJson = @{
body = "$message! Rebase $desc`! Please see $buildUri for more details."
} | ConvertTo-Json -Compress
$commentApi = "https://api.github.com/repos/${{ parameters.RepoOrg }}/${{ parameters.RepoName }}/issues/${{ parameters.PRNumber }}/comments"
Write-Host "Commenting on original PR via $commentApi"
Invoke-WebRequest -UseBasicParsing -Method POST -Headers $headers -Uri $commentApi -Body $commentJson
displayName: Report Status on PR
condition: always()