-
Notifications
You must be signed in to change notification settings - Fork 305
200 lines (176 loc) · 6.89 KB
/
Copy pathroadmap-update.yml
File metadata and controls
200 lines (176 loc) · 6.89 KB
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
name: Update Roadmap Date
on:
pull_request_target:
types: [labeled]
jobs:
update-roadmap-dates:
runs-on: ubuntu-latest
if: |
github.event.label.name == 'awaiting_tech_review' ||
github.event.label.name == 'publish'
permissions:
contents: read
pull-requests: read
repository-projects: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18.x'
- name: Install Octokit
run: npm install @octokit/rest
- name: Update Project Board Dates
uses: actions/github-script@v6
with:
github-token: ${{ secrets.PROJECT_TOKEN }}
script: |
const octokit = github;
const projectNumber = 4;
const orgLogin = 'ArmDeveloperEcosystem';
const prNumber = context.payload.pull_request.number;
const labelName = context.payload.label.name;
async function getProjectItemForPR() {
const projectQuery = `
query {
organization(login: "${orgLogin}") {
projectV2(number: ${projectNumber}) {
id
}
}
}
`;
const projectResponse = await octokit.graphql(projectQuery);
const project = projectResponse.organization?.projectV2;
if (!project) throw new Error("Project not found for organization.");
const projectId = project.id;
let cursor = null;
let itemId = null;
do {
const prQuery = `
query($after: String) {
organization(login: "${orgLogin}") {
projectV2(number: ${projectNumber}) {
items(first: 100, after: $after) {
nodes {
id
content {
... on PullRequest {
number
repository {
name
}
}
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
}
}
`;
const prResponse = await octokit.graphql(prQuery, { after: cursor });
const items = prResponse.organization.projectV2.items.nodes;
const foundItem = items.find(item =>
item.content &&
item.content.number === prNumber &&
item.content.repository.name === context.repo.repo
);
if (foundItem) {
itemId = foundItem.id;
break;
}
cursor = prResponse.organization.projectV2.items.pageInfo.endCursor;
} while (cursor);
return { projectId, itemId };
}
async function getFieldId(projectId, fieldName) {
const fieldsQuery = `
query {
node(id: "${projectId}") {
... on ProjectV2 {
fields(first: 50) {
nodes {
... on ProjectV2Field {
id
name
dataType
}
}
}
}
}
}
`;
const fieldsResponse = await octokit.graphql(fieldsQuery);
const fields = fieldsResponse.node?.fields?.nodes || [];
const field = fields.find(f => f.name === fieldName && f.dataType === 'DATE');
return field ? field.id : null;
}
async function updateDateField(projectId, itemId, fieldId, date) {
const mutation = `
mutation {
updateProjectV2ItemFieldValue(
input: {
projectId: "${projectId}"
itemId: "${itemId}"
fieldId: "${fieldId}"
value: { date: "${date}" }
}
) {
projectV2Item {
id
}
}
}
`;
const result = await octokit.graphql(mutation);
console.log('Mutation result:', result);
return result;
}
async function main() {
try {
const { projectId, itemId } = await getProjectItemForPR();
if (!itemId) {
console.log('PR not found in project board');
return;
}
const today = new Date().toISOString().split('T')[0];
if (labelName === 'awaiting_tech_review') {
const startDateFieldId = await getFieldId(projectId, 'Start Date');
if (startDateFieldId) {
await updateDateField(projectId, itemId, startDateFieldId, today);
console.log('Updated Start Date to', today);
} else {
console.log('Start Date field not found');
}
} else if (labelName === 'publish') {
// Publish Date
const publishDateFieldId = await getFieldId(projectId, 'Publish Date');
if (publishDateFieldId) {
await updateDateField(projectId, itemId, publishDateFieldId, today);
console.log('Updated Publish Date to', today);
} else {
console.log('Publish Date field not found');
}
// Last Reviewed Date (same as Publish Date)
const lastReviewedFieldId = await getFieldId(projectId, 'Last Reviewed Date');
if (lastReviewedFieldId) {
await updateDateField(projectId, itemId, lastReviewedFieldId, today);
console.log('Updated Last Reviewed Date to', today);
} else {
console.log('Last Reviewed Date field not found');
}
} else {
console.log('No action taken for label:', labelName);
}
} catch (error) {
console.error('Error updating project board:', error);
core.setFailed(`Error updating project board: ${error.message}`);
}
}
main();