mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2026-03-26 18:22:08 -04:00
103 lines
3.3 KiB
YAML
103 lines
3.3 KiB
YAML
name: Sync Project Status
|
|
|
|
on:
|
|
issues:
|
|
types: [labeled]
|
|
|
|
jobs:
|
|
update-project:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
issues: write
|
|
repository-projects: write
|
|
|
|
steps:
|
|
- name: Update project status from label
|
|
uses: actions/github-script@v7
|
|
with:
|
|
script: |
|
|
|
|
const labelMap = {
|
|
"backlog": "BACKLOG_OPTION_ID",
|
|
"needs discussion": "DISCUSSION_OPTION_ID",
|
|
"approved": "APPROVED_OPTION_ID",
|
|
"ready": "READY_OPTION_ID",
|
|
"in progress": "IN_PROGRESS_OPTION_ID",
|
|
"in review": "IN_REVIEW_OPTION_ID",
|
|
"done": "DONE_OPTION_ID"
|
|
};
|
|
|
|
const label = context.payload.label.name.toLowerCase();
|
|
const optionId = labelMap[label];
|
|
|
|
if (!optionId) return;
|
|
|
|
const issueNodeId = context.payload.issue.node_id;
|
|
|
|
const configuredProjectId = "PVT_kwHOBeIeKs4AfmUO";
|
|
const fieldId = "PVTSSF_lAHOBeIeKs4AfmUOzgU5pCI";
|
|
|
|
// Find project items from the issue side.
|
|
const result = await github.graphql(`
|
|
query($issueId: ID!) {
|
|
node(id: $issueId) {
|
|
... on Issue {
|
|
projectItems(first: 100) {
|
|
nodes {
|
|
id
|
|
project {
|
|
id
|
|
title
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
`, {
|
|
issueId: issueNodeId
|
|
});
|
|
|
|
const issueProjectItems = result.node?.projectItems?.nodes ?? [];
|
|
const exactMatch = issueProjectItems.find(
|
|
(node) => node.project?.id === configuredProjectId
|
|
);
|
|
|
|
// If configured id is wrong/unresolvable, but issue belongs to exactly one project,
|
|
// use that project item to keep automation working.
|
|
const selectedItem = exactMatch ?? (issueProjectItems.length === 1 ? issueProjectItems[0] : null);
|
|
const itemId = selectedItem?.id;
|
|
const projectId = selectedItem?.project?.id;
|
|
|
|
if (!itemId || !projectId) {
|
|
const availableProjects = issueProjectItems
|
|
.map((node) => `${node.project?.title ?? "(untitled)"} [${node.project?.id ?? "no-id"}]`)
|
|
.join(", ");
|
|
console.log(`Issue not in configured project ${configuredProjectId}. Available: ${availableProjects || "none"}`);
|
|
return;
|
|
}
|
|
|
|
// update status field
|
|
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: itemId,
|
|
fieldId: fieldId,
|
|
optionId: optionId
|
|
});
|