-
Notifications
You must be signed in to change notification settings - Fork 0
171 lines (147 loc) · 5.57 KB
/
Copy pathsync-subtask-week.yml
File metadata and controls
171 lines (147 loc) · 5.57 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
name: Sync Subtask Week from Parent
on:
issues:
types: [opened, edited]
permissions:
issues: write
contents: read
jobs:
sync-iteration:
runs-on: ubuntu-latest
steps:
- name: Sync iteration from parent issue
uses: actions/github-script@v7
with:
github-token: ${{ secrets.ORG_PROJECT_TOKEN || secrets.GITHUB_TOKEN }}
script: |
const ORG = 'Commute-ai';
const PROJECT_NUM = 1; // Update with your project number
// Get issue node ID
const issue = await github.rest.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
});
const issueNodeId = issue.data.node_id;
// Query 1: Check if this is a subtask and get parent
const checkSubIssueQuery = `
query($issueId: ID!) {
node(id: $issueId) {
... on Issue {
parent {
id
number
repository {
owner {
login
}
name
}
}
}
}
}
`;
const subIssueData = await github.graphql(checkSubIssueQuery, {
issueId: issueNodeId,
headers: {
'GraphQL-Features': 'sub_issues'
}
});
const parent = subIssueData.node.parent;
if (!parent) {
console.log('⏭️ This issue is not a sub-issue, skipping');
return;
}
// Verify parent is in .github repo
if (parent.repository.name !== '.github') {
console.log(`⚠️ Parent is in ${parent.repository.name}, expected .github repo`);
return;
}
console.log(`✅ Found parent: ${parent.repository.owner.login}/.github#${parent.number}`);
// Query 2: Get project items for both parent and child
const projectQuery = `
query($org: String!, $projNum: Int!) {
organization(login: $org) {
projectV2(number: $projNum) {
id
items(first: 100) {
nodes {
id
content {
... on Issue {
id
number
repository {
name
}
}
}
fieldValues(first: 20) {
nodes {
... on ProjectV2ItemFieldIterationValue {
title
iterationId
field {
... on ProjectV2IterationField {
id
name
}
}
}
}
}
}
}
}
}
}
`;
const projectData = await github.graphql(projectQuery, {
org: ORG,
projNum: PROJECT_NUM
});
const project = projectData.organization.projectV2;
const allItems = project.items.nodes;
// Find parent and child items
const parentItem = allItems.find(item => item.content?.id === parent.id);
const childItem = allItems.find(item => item.content?.id === issueNodeId);
if (!parentItem) {
console.log('❌ Parent issue not in project board');
return;
}
if (!childItem) {
console.log('❌ Child issue not in project board yet. Add it first.');
return;
}
// Get parent's iteration
const parentIteration = parentItem.fieldValues.nodes.find(
fv => fv.field?.name === 'Week' && fv.iterationId
);
if (!parentIteration) {
console.log('❌ Parent has no iteration set');
return;
}
console.log(`✅ Parent iteration: ${parentIteration.title}`);
// Update child's iteration
const updateMutation = `
mutation($projId: ID!, $itemId: ID!, $fieldId: ID!, $iterId: String!) {
updateProjectV2ItemFieldValue(input: {
projectId: $projId
itemId: $itemId
fieldId: $fieldId
value: { iterationId: $iterId }
}) {
projectV2Item {
id
}
}
}
`;
await github.graphql(updateMutation, {
projId: project.id,
itemId: childItem.id,
fieldId: parentIteration.field.id,
iterId: parentIteration.iterationId
});
console.log(`✅ Synced iteration to: ${parentIteration.title}`);