Skip to content

Commit

Permalink
Update issue_triage.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
Mayank77maruti authored Dec 19, 2024
1 parent 50cb04d commit 4787c44
Showing 1 changed file with 32 additions and 37 deletions.
69 changes: 32 additions & 37 deletions .github/workflows/issue_triage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,13 @@ jobs:
repository(owner: $owner, name: $repo) {
issue(number: $issueNumber) {
number
projectV2Items(first: 10) { # Changed from projectItems to projectV2Items
projectsV2(first: 10) {
nodes {
id
project {
title
id
}
fieldValues(first: 8) {
title
items(first: 1) {
nodes {
... on ProjectV2ItemFieldSingleSelectValue {
name
field {
... on ProjectV2SingleSelectField {
id
name
}
}
}
id
}
}
}
Expand All @@ -54,7 +43,7 @@ jobs:
};
const result = await github.graphql(query, variables);
const projects = result.repository.issue.projectV2Items.nodes;
const projects = result.repository.issue.projectsV2.nodes;
if (projects.length !== 1) {
const message = `This issue must belong to exactly one project. Currently assigned to ${projects.length} project(s).`;
Expand All @@ -66,31 +55,41 @@ jobs:
});
core.setOutput('projectValid', 'false');
} else {
const project = projects[0];
const itemId = project.items.nodes[0]?.id;
if (!itemId) {
core.setOutput('projectValid', 'false');
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: 'Could not find issue in project.'
});
return;
}
core.setOutput('projectValid', 'true');
core.setOutput('projectTitle', projects[0].project.title);
core.setOutput('projectId', projects[0].project.id);
core.setOutput('itemId', projects[0].id);
core.setOutput('projectTitle', project.title);
core.setOutput('projectId', project.id);
core.setOutput('itemId', itemId);
}
- name: Move Issue to "In Progress" on Self-Assignment
if: ${{ github.event.action == 'assigned' && github.event.assignee.login == github.actor && steps.check-projects.outputs.projectValid == 'true' }}
uses: actions/github-script@v6
with:
script: |
// First, get the status field ID
const statusFieldQuery = `
query($projectId: ID!) {
node(id: $projectId) {
... on ProjectV2 {
fields(first: 20) {
nodes {
... on ProjectV2SingleSelectField {
field(name: "Status") {
... on ProjectV2SingleSelectField {
id
options {
id
name
options {
id
name
}
}
}
}
Expand All @@ -100,17 +99,14 @@ jobs:
`;
const statusResult = await github.graphql(statusFieldQuery, {
projectId: steps.check-projects.outputs.projectId
projectId: "${{ steps.check-projects.outputs.projectId }}"
});
const statusField = statusResult.node.fields.nodes.find(
field => field.name.toLowerCase() === 'status'
);
if (!statusField) {
if (!statusResult.node?.field) {
throw new Error('Status field not found in project');
}
const statusField = statusResult.node.field;
const inProgressOption = statusField.options.find(
option => option.name.toLowerCase() === 'in progress'
);
Expand All @@ -119,9 +115,8 @@ jobs:
throw new Error('In Progress status option not found');
}
// Update the status
await github.graphql(`
mutation($itemId: ID!, $projectId: ID!, $fieldId: ID!, $optionId: String!) {
mutation($projectId: ID!, $itemId: ID!, $fieldId: ID!, $optionId: String!) {
updateProjectV2ItemFieldValue(
input: {
projectId: $projectId
Expand All @@ -138,8 +133,8 @@ jobs:
}
}
`, {
itemId: steps.check-projects.outputs.itemId,
projectId: steps.check-projects.outputs.projectId,
projectId: "${{ steps.check-projects.outputs.projectId }}",
itemId: "${{ steps.check-projects.outputs.itemId }}",
fieldId: statusField.id,
optionId: inProgressOption.id
});
Expand Down

0 comments on commit 4787c44

Please sign in to comment.