Skip to content

Commit a0ca016

Browse files
tloubrieu-jplclaude
andcommitted
Add automatic team/project assignment workflow
This workflow automatically, when team label is assigned to an issue: - Set podaac project status to triage - Assign to the team github project when it exists, with a New status. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a440041 commit a0ca016

1 file changed

Lines changed: 58 additions & 47 deletions

File tree

.github/workflows/team-assignment.yml

Lines changed: 58 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ jobs:
8686
const podaacStatusField = podaacProject.fields.nodes.find(field => field.name === 'Status');
8787
const triagedOption = podaacStatusField?.options.find(option => option.name === 'triaged');
8888
89+
let podaacProjectItem = null;
90+
let podaacStatusUpdated = false;
91+
8992
if (!triagedOption) {
9093
core.warning('Could not find "triaged" status option in podaac project');
9194
} else {
@@ -115,7 +118,7 @@ jobs:
115118
});
116119
117120
const projectItems = issueData.repository.issue.projectItems.nodes;
118-
const podaacProjectItem = projectItems.find(item => item.project.id === podaacProject.id);
121+
podaacProjectItem = projectItems.find(item => item.project.id === podaacProject.id);
119122
120123
if (!podaacProjectItem) {
121124
core.warning('Issue is not in podaac project, cannot update status');
@@ -128,6 +131,7 @@ jobs:
128131
value: triagedOption.id
129132
});
130133
134+
podaacStatusUpdated = true;
131135
console.log('✅ Successfully updated status to "triaged" in podaac project');
132136
}
133137
}
@@ -181,75 +185,82 @@ jobs:
181185
182186
console.log(`Found team project: ${teamProject.title} (number: ${teamProject.number})`);
183187
184-
// Add issue to team project
185-
const addToProjectMutation = `
186-
mutation($projectId: ID!, $contentId: ID!) {
187-
addProjectV2ItemById(input: {
188-
projectId: $projectId
189-
contentId: $contentId
190-
}) {
191-
item {
192-
id
193-
}
194-
}
195-
}
196-
`;
197-
198-
const issueNodeIdQuery = `
188+
// Check if issue is already in the team project
189+
const issueWithProjectsQuery = `
199190
query($org: String!, $repo: String!, $number: Int!) {
200191
repository(owner: $org, name: $repo) {
201192
issue(number: $number) {
202193
id
194+
projectItems(first: 20) {
195+
nodes {
196+
id
197+
project {
198+
id
199+
}
200+
}
201+
}
203202
}
204203
}
205204
}
206205
`;
207206
208-
const issueNodeData = await github.graphql(issueNodeIdQuery, {
207+
const issueWithProjects = await github.graphql(issueWithProjectsQuery, {
209208
org: org,
210209
repo: repo,
211210
number: issueNumber
212211
});
213212
214-
const issueNodeId = issueNodeData.repository.issue.id;
215-
216-
const addResult = await github.graphql(addToProjectMutation, {
217-
projectId: teamProject.id,
218-
contentId: issueNodeId
219-
});
220-
221-
const teamProjectItemId = addResult.addProjectV2ItemById.item.id;
222-
console.log(`✅ Successfully added issue to team project "${teamName}"`);
223-
224-
// ========================================
225-
// Step 3: Set status to "New" in team project
226-
// ========================================
213+
const issueNodeId = issueWithProjects.repository.issue.id;
214+
const existingTeamProjectItem = issueWithProjects.repository.issue.projectItems.nodes.find(
215+
item => item.project.id === teamProject.id
216+
);
227217
228-
console.log('Step 3: Setting status to "New" in team project...');
218+
let teamProjectItemId;
219+
let wasAlreadyInProject = false;
229220
230-
const teamStatusField = teamProject.fields.nodes.find(field => field.name === 'Status');
231-
const newStatusOption = teamStatusField?.options.find(option => option.name === '🆕 New');
232-
233-
if (!teamStatusField || !newStatusOption) {
234-
core.warning(`Could not find "Status" field or "New" option in team project "${teamName}"`);
235-
console.log(`⚠️ Team project "${teamName}" does not have a Status field with "🆕 New" option`);
221+
if (existingTeamProjectItem) {
222+
// Issue is already in team project
223+
teamProjectItemId = existingTeamProjectItem.id;
224+
wasAlreadyInProject = true;
225+
console.log(`ℹ️ Issue is already in team project "${teamName}"`);
236226
} else {
237-
await github.graphql(updateStatusMutation, {
227+
// Add issue to team project
228+
const addToProjectMutation = `
229+
mutation($projectId: ID!, $contentId: ID!) {
230+
addProjectV2ItemById(input: {
231+
projectId: $projectId
232+
contentId: $contentId
233+
}) {
234+
item {
235+
id
236+
}
237+
}
238+
}
239+
`;
240+
241+
const addResult = await github.graphql(addToProjectMutation, {
238242
projectId: teamProject.id,
239-
itemId: teamProjectItemId,
240-
fieldId: teamStatusField.id,
241-
value: newStatusOption.id
243+
contentId: issueNodeId
242244
});
243245
244-
console.log('✅ Successfully set status to "🆕 New" in team project');
246+
teamProjectItemId = addResult.addProjectV2ItemById.item.id;
247+
console.log(`✅ Successfully added issue to team project "${teamName}"`);
245248
}
246249
247250
// Summary
251+
const summaryItems = [`Processed team label: ${teamName}`];
252+
253+
if (podaacStatusUpdated) {
254+
summaryItems.push(`Updated podaac project status to "triaged"`);
255+
}
256+
257+
if (wasAlreadyInProject) {
258+
summaryItems.push(`Issue was already in team project "${teamName}"`);
259+
} else {
260+
summaryItems.push(`Added issue to team project "${teamName}"`);
261+
}
262+
248263
core.summary
249264
.addHeading(`Team Assignment Complete: ${teamName}`)
250-
.addList([
251-
`Updated podaac project status to "triaged"`,
252-
`Added issue to team project "${teamName}"`,
253-
`Set status to "🆕 New" in team project`
254-
])
265+
.addList(summaryItems)
255266
.write();

0 commit comments

Comments
 (0)