Skip to content

Commit 6399d32

Browse files
committed
even more simple now
1 parent d88c24c commit 6399d32

File tree

2 files changed

+11
-24
lines changed

2 files changed

+11
-24
lines changed

.github/workflows/prs_create-cherry-pick-pr.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ jobs:
2222
outputs:
2323
targetBranches: ${{ steps.detect.outputs.TARGET_BRANCHES }}
2424
reviewers: ${{ steps.detect.outputs.REVIEWERS }}
25+
labels: ${{ steps.detect.outputs.LABELS }}
2526
steps:
2627
- name: Check out mui-public repo
2728
id: checkout
@@ -59,10 +60,13 @@ jobs:
5960
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6061
uses: carloscastrojumo/github-cherry-pick-action@503773289f4a459069c832dc628826685b75b4b3 # v1.0.10
6162
with:
63+
# the action will run for each value in matrix.branch
6264
branch: ${{ matrix.branch }}
6365
body: 'Cherry-pick of #{old_pull_request_id}'
6466
cherry-pick-branch: ${{ format('cherry-pick-{0}', github.event.number) }}
6567
title: '{old_title} (@${{ github.event.pull_request.user.login }})'
68+
# assigning the original reviewers to the new PR
6669
reviewers: ${{ needs.detect_cherry_pick_targets.outputs.reviewers }}
67-
labels: |
68-
cherry-pick
70+
# instead of inheriting labels (including target branch label, etc.), we filter and set the labels explicitly
71+
inherit_labels: false
72+
labels: ${{ needs.detect_cherry_pick_targets.outputs.labels }}

.github/workflows/scripts/prs/detectTargetBranch.js

+5-22
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ module.exports = async ({ core, context, github }) => {
2222

2323
core.info(`>>> PR fetched: ${pr.number}`);
2424

25+
const prLabels = pr.labels.map((label) => label.name);
26+
2527
// filter the target labels from the original PR
26-
const targetLabels = pr.labels
27-
.map((label) => label.name)
28-
.filter((label) => vBranchRegex.test(label));
28+
const targetLabels = prLabels.filter((label) => vBranchRegex.test(label));
29+
const otherLabels = prLabels.filter((label) => !vBranchRegex.test(label));
2930

3031
if (targetLabels.length === 0) {
3132
// there was no target branch present
@@ -49,25 +50,6 @@ module.exports = async ({ core, context, github }) => {
4950
const reviewers = pr.requested_reviewers.map((reviewer) => reviewer.login);
5051
core.info(`>>> Reviewers from original PR: ${reviewers.join(', ')}`);
5152

52-
// the others will be removed from the PR
53-
core.info(`>>> Removing target labels from the original PR`);
54-
for (const label of targetLabels) {
55-
await github.rest.issues.removeLabel({
56-
owner,
57-
repo,
58-
issue_number: pullNumber,
59-
name: label,
60-
});
61-
}
62-
63-
core.info(`>>> Removing "needs cherry-pick" label from the original PR`);
64-
await github.rest.issues.removeLabel({
65-
owner,
66-
repo,
67-
issue_number: pullNumber,
68-
name: 'needs cherry-pick',
69-
});
70-
7153
core.info(`>>> Creating explanatory comment on PR`);
7254
await github.rest.issues.createComment({
7355
owner,
@@ -78,6 +60,7 @@ module.exports = async ({ core, context, github }) => {
7860

7961
// set the target branches as output to be used as an input for the next step
8062
core.setOutput('TARGET_BRANCHES', targetLabels.join(','));
63+
core.setOutput('LABELS', ['cherry-pick', ...otherLabels].join(','));
8164
core.setOutput('REVIEWERS', reviewers.join(','));
8265
} catch (error) {
8366
core.error(`>>> Workflow failed with: ${error.message}`);

0 commit comments

Comments
 (0)