Skip to content

Commit f5351b9

Browse files
authored
Merge pull request #216 from cloudfoundry/add_milestone_automation
chore: GH Action - PR Default Milestone
2 parents 7d3f4da + 260ecd2 commit f5351b9

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
2+
name: Set default values to PR
3+
# Add the PR to the central project (status in project is set via workflow in project)
4+
# Add the creator of the PR as assignee
5+
# Add the next available milestone to the PR
6+
7+
on:
8+
pull_request:
9+
types:
10+
- opened
11+
12+
permissions:
13+
issues: write
14+
pull-requests: write
15+
16+
jobs:
17+
set-default-values:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Add creator as assignee
21+
if: ${{ github.actor != 'dependabot[bot]' }}
22+
env:
23+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24+
run: |
25+
gh api \
26+
--method POST \
27+
-H "Accept: application/vnd.github+json" \
28+
-H "X-GitHub-Api-Version: 2022-11-28" \
29+
/repos/${{github.repository}}/issues/${{github.event.number}}/assignees \
30+
-f "assignees[]=${{github.actor}}"
31+
- name: Add next milestone
32+
uses: actions/github-script@v7
33+
with:
34+
script: |
35+
const milestones = await github.rest.issues.listMilestones({
36+
owner: context.repo.owner,
37+
repo: context.repo.repo,
38+
state: "open",
39+
sort: "due_on",
40+
direction: "asc"
41+
})
42+
43+
await github.rest.issues.update({
44+
owner: context.repo.owner,
45+
repo: context.repo.repo,
46+
issue_number: context.issue.number,
47+
milestone: milestones.data[0].number
48+
});
49+
50+
- name: Set default labels
51+
if: ${{ github.actor != 'dependabot[bot]' }}
52+
uses: actions/github-script@v7
53+
env:
54+
TITLE: ${{ github.event.pull_request.title }}
55+
with:
56+
script: |
57+
const title = process.env.TITLE;
58+
59+
let defaultLabels = [];
60+
if (title.startsWith("feat:")) {
61+
defaultLabels.push("enhancement");
62+
} else if (title.startsWith("fix:")) {
63+
defaultLabels.push("bug");
64+
} else if (title.startsWith("docs:")) {
65+
defaultLabels.push("documentation");
66+
} else if (title.startsWith("test:")) {
67+
defaultLabels.push("test setup", "internal", "ignore-for-release");
68+
} else if (title.startsWith("refactor:")) {
69+
defaultLabels.push("internal", "ignore-for-release", "refactoring");
70+
} else {
71+
defaultLabels.push("internal", "ignore-for-release");
72+
}
73+
74+
await github.rest.issues.addLabels({
75+
owner: context.repo.owner,
76+
repo: context.repo.repo,
77+
issue_number: context.issue.number,
78+
labels: defaultLabels
79+
});

0 commit comments

Comments
 (0)