-
Notifications
You must be signed in to change notification settings - Fork 297
169 lines (150 loc) · 6.43 KB
/
append_feature_proposal.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
name: Append Feature Proposal to Issue Description
on:
issues:
types: [assigned, unassigned, labeled]
jobs:
check-labels:
runs-on: ubuntu-latest
outputs:
status: ${{ steps.feature-proposal-tag-check.outputs.status }}
steps:
- id: feature-proposal-tag-check
name: Check if feature proposal tag added
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const issueNumber = context.payload.issue.number;
const owner = context.repo.owner;
const repo = context.repo.repo;
const issue = await github.rest.issues.get({
owner,
repo,
issue_number: issueNumber,
});
const hasFeatureProposalLabel = issue.data.labels.some(label => label.name === 'needs-feature-proposal');
if (hasFeatureProposalLabel) {
console.log('Feature Proposal label added. Proceeding...');
core.setOutput('status', 'success');
} else {
console.log('Feature Proposal label not added. Skipping action...');
core.setOutput('status', 'failure');
}
manage-feature-proposal:
needs: check-labels
if: needs.check-labels.outputs.status == 'success'
runs-on: ubuntu-latest
steps:
- name: Check if feature proposal tag added
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const issueNumber = context.payload.issue.number;
const owner = context.repo.owner;
const repo = context.repo.repo;
const issue = await github.rest.issues.get({
owner,
repo,
issue_number: issueNumber,
});
const hasFeatureProposalLabel = issue.data.labels.some(label => label.name === 'needs-feature-proposal');
if (hasFeatureProposalLabel) {
console.log('Feature Proposal label added. Proceeding...');
} else {
console.log('Feature Proposal label not added. Skipping action...');
process.exit(0);
}
- name: Checkout code
uses: actions/checkout@v4
- name: Append Feature Proposal Template to Issue Description
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const issueNumber = context.payload.issue.number;
const owner = context.repo.owner;
const repo = context.repo.repo;
const issue = await github.rest.issues.get({
owner,
repo,
issue_number: issueNumber,
});
// Check if the issue has a 'bug' label
const hasBugLabel = issue.data.labels.some(label => label.name === 'bug');
if (hasBugLabel) {
console.log("Issue is labeled as 'bug'. Skipping...");
return; // Exit the script if 'bug' label is found
}
const featureProposalMarker = '<!-- Feature Proposal Marker -->';
if (!issue.data.body.includes(featureProposalMarker)) {
const templateContent = await github.rest.repos.getContent({
owner,
repo,
path: '.github/ISSUE_TEMPLATE/feature-proposal--developer-.md'
});
let templateText = Buffer.from(templateContent.data.content, 'base64').toString();
// Add separator line and remove metadata section
templateText = '---\n' + templateText.split('---').slice(2).join('---').trim();
const updatedBody = issue.data.body + "\n" + templateText;
await github.rest.issues.update({
owner,
repo,
issue_number: issueNumber,
body: updatedBody,
});
}
- name: Update or Post instructions comment
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const issueNumber = context.payload.issue.number;
const owner = context.repo.owner;
const repo = context.repo.repo;
const issue = await github.rest.issues.get({
owner,
repo,
issue_number: issueNumber,
});
// Check if the issue has any assignees
if (issue.data.assignees.length === 0) {
console.log("No assignees for this issue. Skipping...");
return; // Exit the script if no assignees are found
}
// Check if the issue has a 'bug' label
const hasBugLabel = issue.data.labels.some(label => label.name === 'bug');
if (hasBugLabel) {
console.log("Issue is labeled as 'bug'. Skipping...");
return; // Exit the script if 'bug' label is found
}
const assignees = issue.data.assignees.map(assignee => '@' + assignee.login).join(', ');
const comments = await github.rest.issues.listComments({
owner,
repo,
issue_number: issueNumber,
});
const instructionCommentMarker = '<!-- Instruction Comment Marker -->';
let instructionCommentId = null;
for (const comment of comments.data) {
if (comment.body.includes(instructionCommentMarker)) {
instructionCommentId = comment.id;
break;
}
}
const commentBody = `Hello ${assignees},\n\nThank you for taking on this issue.\n\nTo ensure the Feature Proposal is accurately filled out, we kindly ask you to follow the structure provided.\n\n**For detailed instructions and best practices**, please refer to our **[Development Process Guidelines](https://docs.artemis.cit.tum.de/dev/development-process.html)**.\n\n${instructionCommentMarker}`;
if (instructionCommentId) {
await github.rest.issues.updateComment({
owner,
repo,
comment_id: instructionCommentId,
body: commentBody,
});
} else {
await github.rest.issues.createComment({
owner,
repo,
issue_number: issueNumber,
body: commentBody,
});
}