1
1
name : Create cherry pick PR
2
2
3
3
on :
4
- repository_dispatch :
5
- types : [create-cherry-pick-pr]
6
4
workflow_dispatch :
7
5
inputs :
8
6
pr :
13
11
description : Target branch to cherry-pick to
14
12
required : true
15
13
type : string
14
+
15
+ # Inputs provided by the bot
16
+ distinct_id :
17
+ description : ' (bot) A distinct ID'
18
+ required : false
19
+ default : ' '
20
+ source_issue :
21
+ description : ' (bot) The issue that triggered this workflow'
22
+ required : false
23
+ default : ' '
16
24
requesting_user :
17
- description : User who requested the cherry-pick
18
- required : true
19
- type : string
25
+ description : ' (bot) The user who requested this workflow'
26
+ required : false
27
+ default : ' '
28
+ status_comment :
29
+ description : ' (bot) The comment to update with the status of this workflow'
30
+ required : false
31
+ default : ' '
32
+
33
+ run-name : ${{ github.workflow }}${{ inputs.distinct_id && format(' (bot run {0})', inputs.distinct_id) || '' }}
20
34
21
35
permissions :
22
36
contents : read
@@ -40,15 +54,27 @@ jobs:
40
54
token : ${{ secrets.TS_BOT_GITHUB_TOKEN }}
41
55
42
56
- uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
57
+ id : open-pr
43
58
env :
44
- PR : ${{ inputs.pr || github.event.client_payload.pr }}
45
- TARGET_BRANCH : ${{ inputs.target_branch || github.event.client_payload.target_branch }}
46
- REQUESTING_USER : ${{ inputs.requesting_user || github.event.client_payload.requesting_user }}
59
+ PR : ${{ inputs.pr }}
60
+ TARGET_BRANCH : ${{ inputs.target_branch }}
61
+ DISTINCT_ID : ${{ inputs.distinct_id }}
62
+ SOURCE_ISSUE : ${{ inputs.source_issue }}
63
+ REQUESTING_USER : ${{ inputs.requesting_user }}
64
+ STATUS_COMMENT : ${{ inputs.status_comment }}
47
65
with :
48
66
retries : 3
49
67
github-token : ${{ secrets.TS_BOT_GITHUB_TOKEN }}
68
+ result-encoding : string
50
69
script : |
51
- const { PR, TARGET_BRANCH, REQUESTING_USER } = process.env;
70
+ const {
71
+ PR,
72
+ TARGET_BRANCH,
73
+ DISTINCT_ID,
74
+ SOURCE_ISSUE,
75
+ REQUESTING_USER,
76
+ STATUS_COMMENT,
77
+ } = process.env;
52
78
53
79
const pr = await github.rest.pulls.get({
54
80
owner: context.repo.owner,
75
101
head: `${context.repo.owner}:${pickBranch}`,
76
102
});
77
103
104
+ let commentBody;
105
+
78
106
if (existingPulls.data.length === 0) {
79
107
console.log(`No existing PRs found for ${pickBranch}`);
80
108
@@ -91,12 +119,7 @@ jobs:
91
119
reviewers: ["DanielRosenwasser", REQUESTING_USER],
92
120
});
93
121
94
- await github.rest.issues.createComment({
95
- owner: context.repo.owner,
96
- repo: context.repo.repo,
97
- issue_number: +PR,
98
- body: `Hey @${REQUESTING_USER}, I've created #${newPr.data.number} for you.`,
99
- });
122
+ commentBody = `I've created #${newPr.data.number} for you.`;
100
123
}
101
124
else {
102
125
const existing = existingPulls.data[0];
@@ -109,23 +132,18 @@ jobs:
109
132
title,
110
133
});
111
134
112
- await github.rest.issues.createComment({
113
- owner: context.repo.owner,
114
- repo: context.repo.repo,
115
- issue_number: +PR,
116
- body: `Hey @${REQUESTING_USER}, I've updated #${existing.number} for you.`,
117
- });
135
+ commentBody = `I've updated #${existing.number} for you.`;
118
136
}
119
137
120
- - run : |
121
- MESSAGE="Hey @$REQUESTING_USER, I was unable to cherry-pick this PR."
122
- MESSAGE+=$'\n\n'
123
- MESSAGE+="Check the logs at: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
138
+ return commentBody;
124
139
125
- gh pr comment "$PR" --repo ${{ github.repository }} --body "$MESSAGE"
126
- if: ${{ failure() }}
127
- env:
128
- PR: ${{ inputs.pr || github.event.client_payload.pr }}
129
- TARGET_BRANCH: ${{ inputs.target_branch || github.event.client_payload.target_branch }}
130
- REQUESTING_USER: ${{ inputs.requesting_user || github.event.client_payload.requesting_user }}
131
- GH_TOKEN: ${{ secrets.TS_BOT_GITHUB_TOKEN }}
140
+ - uses : microsoft/typescript-bot-test-triggerer/.github/actions/post-workflow-result@master
141
+ if : ${{ !cancelled() && inputs.distinct_id }}
142
+ with :
143
+ success_comment : ${{ steps.open-pr.outputs.result }}
144
+ failure_comment : ' I was unable to cherry-pick this PR.'
145
+ github_token : ${{ secrets.TS_BOT_GITHUB_TOKEN }}
146
+ distinct_id : ${{ inputs.distinct_id }}
147
+ source_issue : ${{ inputs.source_issue }}
148
+ requesting_user : ${{ inputs.requesting_user }}
149
+ status_comment : ${{ inputs.status_comment }}
0 commit comments