.github/workflows/move-issue-to-in-progress.yml #3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Move Issue to In Progress When Assigned | |
on: | |
issues: | |
types: | |
- assigned | |
jobs: | |
move_to_in_progress: | |
runs-on: ubuntu-latest | |
permissions: | |
issues: write | |
repository-projects: write # Corrected permission for interacting with repository projects | |
steps: | |
- name: Move issue to "🚧 In Progress" in project | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
// Set org and project number | |
const projectOwner = 'Computing-For-All'; | |
const projectNumber = 3; | |
// Set field name and status value | |
const statusFieldName = 'Status'; | |
const inProgressStatusValue = '🚧 In Progress'; | |
// Retrieve project ID and field ID for Status | |
const { data: { user } } = await github.graphql(` | |
query ($login: String!, $number: Int!) { | |
user(login: $login) { | |
projectV2(number: $number) { | |
id | |
fields(first: 20) { | |
nodes { | |
id | |
name | |
... on ProjectV2SingleSelectField { | |
options { | |
id | |
name | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
`, { | |
login: projectOwner, | |
number: projectNumber | |
}); | |
// Debug output | |
console.log('Project ID:', user.projectV2.id); | |
console.log('Fields:', user.projectV2.fields.nodes); | |
const projectId = user.projectV2.id; | |
const statusField = user.projectV2.fields.nodes.find(field => field.name === statusFieldName); | |
if (!statusField) { | |
throw new Error(`Field "${statusFieldName}" not found in project.`); | |
} | |
console.log('Status Field ID:', statusField.id); | |
const inProgressOption = statusField.options.find(option => option.name === inProgressStatusValue); | |
if (!inProgressOption) { | |
throw new Error(`Status option "${inProgressStatusValue}" not found in field "${statusFieldName}".`); | |
} | |
console.log('In Progress Option ID:', inProgressOption.id); | |
// Add the issue to the project or update its status if already in the project | |
const issueNodeId = context.payload.issue.node_id; | |
// Debug output for Issue ID | |
console.log('Issue Node ID:', issueNodeId); | |
// Move the issue to "In Progress" status | |
await github.graphql(` | |
mutation($projectId: ID!, $itemId: ID!, $fieldId: ID!, $optionId: String!) { | |
updateProjectV2ItemFieldValue(input: { | |
projectId: $projectId | |
itemId: $itemId | |
fieldId: $fieldId | |
value: { singleSelectOptionId: $optionId } | |
}) { | |
projectV2Item { | |
id | |
} | |
} | |
} | |
`, { | |
projectId: projectId, | |
itemId: issueNodeId, | |
fieldId: statusField.id, | |
optionId: inProgressOption.id | |
}); | |
console.log('Issue moved to "🚧 In Progress"'); |