-
Notifications
You must be signed in to change notification settings - Fork 4
76 lines (65 loc) · 2.53 KB
/
repository-add-issue-to-epic.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
---
name: Add issue to epic
on: # yamllint disable-line rule:truthy
issues:
types:
- labeled
concurrency:
group: add-issue-to-epic
cancel-in-progress: false
permissions: read-all
jobs:
add-issue-to-epic:
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: Add issue to Epic
id: add_issue_to_epic
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
console.log("Starting script...");
const payload = context.payload;
const issueNumber = payload.issue.number;
const issueTitle = payload.issue.title;
const labelName = payload.label.name;
console.log(`Issue Number: ${issueNumber}`);
console.log(`Issue Title: ${issueTitle}`);
console.log(`Label Name: ${labelName}`);
// Check if the label applied is an Epic label
if (!labelName.includes('(Epic #')) {
console.log('The applied label is not an Epic label. Exiting...');
return;
}
// Extract the Epic's issue number from the label name
const epicNumber = labelName.match(/\(Epic #(\d+)\)/)[1];
console.log(`Epic Number Extracted: ${epicNumber}`);
if (!epicNumber) {
console.log('Could not determine the Epic issue number. Exiting...');
return;
}
// Fetch the description of the Epic
const epic = await github.rest.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: epicNumber
});
const epicBody = epic.data.body;
console.log("Fetched Epic Body:");
console.log(epicBody);
// Amend the Epic description with a checkbox and link to the new issue
const newItemLink = `- [ ] #${issueNumber}`;
console.log(`New Item Link: ${newItemLink}`);
const updatedDescription = `${epicBody}\n${newItemLink}`;
console.log("Updated Description:");
console.log(updatedDescription);
// Update the Epic description
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: epicNumber,
body: updatedDescription
});
console.log("Epic description updated successfully.");