1+ name : Privileged Update Roadmap Dates
2+
3+ on :
4+ repository_dispatch :
5+ types : [update-project-dates]
6+
7+ jobs :
8+ update-project :
9+ runs-on : ubuntu-latest
10+
11+ steps :
12+ - name : Setup Node.js
13+ uses : actions/setup-node@v3
14+ with :
15+ node-version : ' 18.x'
16+
17+ - name : Install Octokit
18+ run : npm install @octokit/rest
19+
20+ - name : Update Project Board Dates
21+ uses : actions/github-script@v6
22+ with :
23+ script : |
24+ const { Octokit } = require('@octokit/rest');
25+ const octokit = new Octokit({ auth: github.token });
26+
27+ const projectNumber = 4; // Your project number
28+ const orgName = 'ArmDeveloperEcosystem';
29+ const prNumber = context.payload.pull_request.number;
30+ const labelName = context.payload.label.name;
31+
32+ async function getProjectItemForPR() {
33+ // Get the project ID
34+ const projectQuery = `
35+ query {
36+ organization(login:"${orgName}") {
37+ projectV2(number:${projectNumber}) {
38+ id
39+ }
40+ }
41+ }
42+ `;
43+
44+ const projectResponse = await octokit.graphql(projectQuery);
45+ const projectId = projectResponse.organization.projectV2.id;
46+
47+ // Find the PR in the project
48+ const prQuery = `
49+ query {
50+ organization(login:"${orgName}") {
51+ projectV2(number:${projectNumber}) {
52+ items(first:100) {
53+ nodes {
54+ id
55+ content {
56+ ... on PullRequest {
57+ number
58+ repository {
59+ name
60+ }
61+ }
62+ }
63+ }
64+ }
65+ }
66+ }
67+ }
68+ `;
69+
70+ const prResponse = await octokit.graphql(prQuery);
71+ const items = prResponse.organization.projectV2.items.nodes;
72+
73+ // Find the item that corresponds to this PR
74+ const item = items.find(item =>
75+ item.content &&
76+ item.content.number === prNumber &&
77+ item.content.repository.name === context.repo.repo
78+ );
79+
80+ return { projectId, itemId:item ? item.id:null };
81+ }
82+
83+ async function getFieldId(projectId, fieldName) {
84+ const fieldsQuery = `
85+ query {
86+ node(id:"${projectId}") {
87+ ... on ProjectV2 {
88+ fields(first:20) {
89+ nodes {
90+ ... on ProjectV2Field {
91+ id
92+ name
93+ }
94+ ... on ProjectV2IterationField {
95+ id
96+ name
97+ }
98+ ... on ProjectV2SingleSelectField {
99+ id
100+ name
101+ }
102+ ... on ProjectV2DateField {
103+ id
104+ name
105+ }
106+ }
107+ }
108+ }
109+ }
110+ }
111+ `;
112+
113+ const fieldsResponse = await octokit.graphql(fieldsQuery);
114+ const fields = fieldsResponse.node.fields.nodes;
115+ const field = fields.find(f => f.name === fieldName);
116+
117+ return field ? field.id :null;
118+ }
119+
120+ async function updateDateField(projectId, itemId, fieldId, date) {
121+ const mutation = `
122+ mutation {
123+ updateProjectV2ItemFieldValue(
124+ input:{
125+ projectId:"${projectId}"
126+ itemId:"${itemId}"
127+ fieldId:"${fieldId}"
128+ value:{
129+ date:"${date}"
130+ }
131+ }
132+ ) {
133+ projectV2Item {
134+ id
135+ }
136+ }
137+ }
138+ `;
139+
140+ return await octokit.graphql(mutation);
141+ }
142+
143+ async function main() {
144+ try {
145+ const { projectId, itemId } = await getProjectItemForPR();
146+ if (!itemId) {
147+ console.log('PR not found in project board');
148+ return;
149+ }
150+
151+ const today = new Date().toISOString().split('T')[0]; // YYYY-MM-DD format
152+
153+ if (labelName === 'awaiting_tech_review') {
154+ const startDateFieldId = await getFieldId(projectId, 'Start Date');
155+ if (startDateFieldId) {
156+ await updateDateField(projectId, itemId, startDateFieldId, today);
157+ console.log('Updated Start Date to', today);
158+ } else {
159+ console.log('Start Date field not found');
160+ }
161+ } else if (labelName === 'publish') {
162+ const publishDateFieldId = await getFieldId(projectId, 'Publish Date');
163+ if (publishDateFieldId) {
164+ await updateDateField(projectId, itemId, publishDateFieldId, today);
165+ console.log('Updated Publish Date to', today);
166+ } else {
167+ console.log('Publish Date field not found');
168+ }
169+ }
170+ } catch (error) {
171+ console.error('Error updating project board:', error);
172+ core.setFailed(`Error updating project board:${error.message}`);
173+ }
174+ }
175+ env :
176+ PROJECT_TOKEN : ${{ secrets.PROJECT_TOKEN }}
0 commit comments