-
Notifications
You must be signed in to change notification settings - Fork 116
81 lines (75 loc) · 2.71 KB
/
automated_release.parse_pr_template.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
name: "Automated Release: Parse PR Change Type"
on:
pull_request:
branches:
- master
types: [opened, edited, reopened]
jobs:
parse-pr:
name: Parse PR and Add labels
permissions:
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Get PR change type
id: detect-change
uses: actions/github-script@v7
with:
script: |
const prBody = context.payload.pull_request.body || "";
let changeType = "unknown";
if (prBody.includes("[x] **Major**")) {
changeType = "major";
} else if (prBody.includes("[x] **Minor**")) {
changeType = "minor";
} else if (prBody.includes("[x] **Patch**")) {
changeType = "patch";
} else {
core.setFailed("No valid change type found in PR body.");
}
core.setOutput("change_type", changeType);
core.info(`Change type is: ${changeType}`);
- name: Set label
id: set-label
uses: actions/github-script@v7
env:
MAJOR_LABEL_NAME: major
MINOR_LABEL_NAME: minor
PATCH_LABEL_NAME: patch
with:
script: |
const changeType = "${{ steps.detect-change.outputs.change_type }}";
let labelName = "";
const majorLabel = "${{ env.MAJOR_LABEL_NAME }}";
const minorLabel = "${{ env.MINOR_LABEL_NAME }}";
const patchLabel = "${{ env.PATCH_LABEL_NAME }}";
if (changeType === "major") {
labelName = majorLabel;
} else if (changeType === "minor") {
labelName = minorLabel;
} else if (changeType === "patch") {
labelName = patchLabel;
} else {
core.setFail("Unknown Change Type Label");
}
core.info(`Desired label name is ${labelName}`)
const pr = context.payload.pull_request;
const labelsToRemove = [majorLabel, minorLabel, patchLabel];
await Promise.all(labelsToRemove.map(async (label) => {
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
name: label,
});
} catch (error) {
core.debug(`Error removing label '${label}': ${error.message}`);
}
}));
github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
labels: [labelName],
});