Update project_automation.yml

This commit is contained in:
Eric Turgeon 2025-05-09 08:13:29 -03:00 committed by GitHub
parent 5bbd997ed2
commit 4f4e1a3459
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 67 additions and 47 deletions

View File

@ -39,7 +39,7 @@ jobs:
resource_node_id: ${{ github.event.issue.node_id }} resource_node_id: ${{ github.event.issue.node_id }}
status_value: ${{ env.new }} status_value: ${{ env.new }}
env: env:
DEBUG: true # Enable debug logging for project-beta-automations DEBUG: true
issue_assigned: issue_assigned:
name: issue_assigned name: issue_assigned
@ -146,8 +146,7 @@ jobs:
} }
} }
// Archive the project item if needed (not supported by project-beta-automations) // Handle project actions (add to project, update status, or archive)
if (shouldArchive) {
try { try {
// Fetch project node ID // Fetch project node ID
const projectData = await github.graphql(` const projectData = await github.graphql(`
@ -171,7 +170,7 @@ jobs:
query($org: String!, $projectNumber: Int!) { query($org: String!, $projectNumber: Int!) {
organization(login: $org) { organization(login: $org) {
projectV2(number: $projectNumber) { projectV2(number: $projectNumber) {
items(first: 100) { items(first: 1000) {
nodes { nodes {
id id
content { content {
@ -193,11 +192,32 @@ jobs:
}); });
console.log(`Project items fetched: ${projectItems.organization.projectV2.items.nodes.length} items`); console.log(`Project items fetched: ${projectItems.organization.projectV2.items.nodes.length} items`);
const projectItem = projectItems.organization.projectV2.items.nodes.find( let projectItem = projectItems.organization.projectV2.items.nodes.find(
item => item.content.id === nodeId item => item.content.id === nodeId
); );
if (projectItem) { // If item is not in project, add it
if (!projectItem) {
console.log(`Item with node ID ${nodeId} not found in project 4, adding it`);
const addItem = await github.graphql(`
mutation($projectId: ID!, $contentId: ID!) {
addProjectV2ItemById(input: { projectId: $projectId, contentId: $contentId }) {
item {
id
}
}
}
`, {
projectId: projectId,
contentId: nodeId
});
console.log(`Added item with node ID ${nodeId} to project 4, item ID: ${addItem.addProjectV2ItemById.item.id}`);
projectItem = { id: addItem.addProjectV2ItemById.item.id };
}
// Archive the project item if needed
if (shouldArchive) {
try {
await github.graphql(` await github.graphql(`
mutation($projectId: ID!, $itemId: ID!) { mutation($projectId: ID!, $itemId: ID!) {
archiveProjectV2Item(input: { projectId: $projectId, itemId: $itemId }) { archiveProjectV2Item(input: { projectId: $projectId, itemId: $itemId }) {
@ -211,15 +231,15 @@ jobs:
itemId: projectItem.id itemId: projectItem.id
}); });
console.log(`Archived item with node ID ${nodeId} in project 4`); console.log(`Archived item with node ID ${nodeId} in project 4`);
} else {
console.log(`Item with node ID ${nodeId} not found in project 4`);
}
} catch (error) { } catch (error) {
console.log(`Failed to archive item: ${error.message}`); console.log(`Failed to archive item: ${error.message}`);
} }
} }
core.setOutput('close_reason', closeReason); core.setOutput('close_reason', closeReason);
} catch (error) {
console.log(`Failed to manage project item: ${error.message}`);
}
} catch (error) { } catch (error) {
console.log(`Failed to fetch issue/PR: ${error.message}`); console.log(`Failed to fetch issue/PR: ${error.message}`);
throw error; throw error;
@ -235,4 +255,4 @@ jobs:
resource_node_id: ${{ steps.close-reason.outputs.node_id }} resource_node_id: ${{ steps.close-reason.outputs.node_id }}
status_value: ${{ steps.close-reason.outputs.status_value }} status_value: ${{ steps.close-reason.outputs.status_value }}
env: env:
DEBUG: true # Enable debug logging for project-beta-automations DEBUG: true