feat(project): set assigned issues in progress
This commit is contained in:
1 parent
6f15fa303c
commit
66237d7160
2 files changed
+71
-2
No files matched your search
@@ -32,6 +32,7 @@ const repo = args.repo || process.env.GITHUB_REPOSITORY || DEFAULT_REPO;
|
|||||||
const [repoOwner, repoName] = repo.split("/");
|
const [repoOwner, repoName] = repo.split("/");
|
||||||
const issueNumber = args["issue-number"] ? Number(args["issue-number"]) : null;
|
const issueNumber = args["issue-number"] ? Number(args["issue-number"]) : null;
|
||||||
const mode = args.backfill === "true" ? "backfill" : "issue";
|
const mode = args.backfill === "true" ? "backfill" : "issue";
|
||||||
|
const eventAction = args["event-action"] || process.env.ISSUE_EVENT_ACTION || "";
|
||||||
|
|
||||||
if (!projectToken) {
|
if (!projectToken) {
|
||||||
throw new Error("PROJECT_TOKEN, GH_TOKEN, or GITHUB_TOKEN is required");
|
throw new Error("PROJECT_TOKEN, GH_TOKEN, or GITHUB_TOKEN is required");
|
||||||
@@ -89,6 +90,18 @@ function triageName(issue) {
|
|||||||
return "Inbox";
|
return "Inbox";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function singleSelectOptionsByName(field) {
|
||||||
|
return Object.fromEntries((field?.options || []).map((option) => [option.name, option.id]));
|
||||||
|
}
|
||||||
|
|
||||||
|
function singleSelectOptionId(options, name) {
|
||||||
|
const exact = options[name];
|
||||||
|
if (exact) return exact;
|
||||||
|
const target = name.toLowerCase();
|
||||||
|
const entry = Object.entries(options).find(([optionName]) => optionName.toLowerCase() === target);
|
||||||
|
return entry?.[1];
|
||||||
|
}
|
||||||
|
|
||||||
async function getProjectConfig() {
|
async function getProjectConfig() {
|
||||||
const query = `
|
const query = `
|
||||||
query {
|
query {
|
||||||
@@ -128,12 +141,15 @@ async function getProjectConfig() {
|
|||||||
if (!triageField) {
|
if (!triageField) {
|
||||||
throw new Error(`Project ${project.title} is missing a Triage field`);
|
throw new Error(`Project ${project.title} is missing a Triage field`);
|
||||||
}
|
}
|
||||||
|
const statusField = project.fields.nodes.find((field) => field.name === "Status");
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: project.id,
|
id: project.id,
|
||||||
title: project.title,
|
title: project.title,
|
||||||
triageFieldId: triageField.id,
|
triageFieldId: triageField.id,
|
||||||
triageOptions: Object.fromEntries(triageField.options.map((option) => [option.name, option.id])),
|
triageOptions: singleSelectOptionsByName(triageField),
|
||||||
|
statusFieldId: statusField?.id || "",
|
||||||
|
statusOptions: singleSelectOptionsByName(statusField),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,6 +196,12 @@ async function fetchIssue(number) {
|
|||||||
optionId
|
optionId
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
statusValue: fieldValueByName(name: "Status") {
|
||||||
|
... on ProjectV2ItemFieldSingleSelectValue {
|
||||||
|
name
|
||||||
|
optionId
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -232,6 +254,27 @@ async function updateTriage({ projectId, itemId, fieldId, optionId }) {
|
|||||||
await graphql(mutation, projectToken);
|
await graphql(mutation, projectToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function updateSingleSelectField({ projectId, itemId, fieldId, optionId }) {
|
||||||
|
const mutation = `
|
||||||
|
mutation {
|
||||||
|
updateProjectV2ItemFieldValue(
|
||||||
|
input: {
|
||||||
|
projectId: ${gqlString(projectId)}
|
||||||
|
itemId: ${gqlString(itemId)}
|
||||||
|
fieldId: ${gqlString(fieldId)}
|
||||||
|
value: { singleSelectOptionId: ${gqlString(optionId)} }
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
projectV2Item {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
await graphql(mutation, projectToken);
|
||||||
|
}
|
||||||
|
|
||||||
async function syncIssue(projectConfig, number) {
|
async function syncIssue(projectConfig, number) {
|
||||||
const issue = await fetchIssue(number);
|
const issue = await fetchIssue(number);
|
||||||
const targetTriage = triageName(issue);
|
const targetTriage = triageName(issue);
|
||||||
@@ -251,6 +294,7 @@ async function syncIssue(projectConfig, number) {
|
|||||||
projectItem = {
|
projectItem = {
|
||||||
id: itemId,
|
id: itemId,
|
||||||
fieldValueByName: null,
|
fieldValueByName: null,
|
||||||
|
statusValue: null,
|
||||||
};
|
};
|
||||||
console.log(`Added issue #${issue.number} to ${projectConfig.title}`);
|
console.log(`Added issue #${issue.number} to ${projectConfig.title}`);
|
||||||
}
|
}
|
||||||
@@ -267,6 +311,30 @@ async function syncIssue(projectConfig, number) {
|
|||||||
} else {
|
} else {
|
||||||
console.log(`Issue #${issue.number} triage already ${targetTriage}`);
|
console.log(`Issue #${issue.number} triage already ${targetTriage}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (eventAction === "assigned" && issue.state === "OPEN") {
|
||||||
|
const targetStatus = "In Progress";
|
||||||
|
const statusOptionId = singleSelectOptionId(projectConfig.statusOptions, targetStatus);
|
||||||
|
if (!projectConfig.statusFieldId) {
|
||||||
|
throw new Error(`Project ${projectConfig.title} is missing a Status field`);
|
||||||
|
}
|
||||||
|
if (!statusOptionId) {
|
||||||
|
throw new Error(`Missing Status option: ${targetStatus}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentStatusOptionId = projectItem.statusValue?.optionId || "";
|
||||||
|
if (currentStatusOptionId !== statusOptionId) {
|
||||||
|
await updateSingleSelectField({
|
||||||
|
projectId: projectConfig.id,
|
||||||
|
itemId: projectItem.id,
|
||||||
|
fieldId: projectConfig.statusFieldId,
|
||||||
|
optionId: statusOptionId,
|
||||||
|
});
|
||||||
|
console.log(`Set issue #${issue.number} status to ${targetStatus}`);
|
||||||
|
} else {
|
||||||
|
console.log(`Issue #${issue.number} status already ${targetStatus}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchOpenIssueNumbers() {
|
async function fetchOpenIssueNumbers() {
|
||||||
|
|||||||
@@ -40,7 +40,8 @@ jobs:
|
|||||||
if: ${{ github.event_name == 'issues' }}
|
if: ${{ github.event_name == 'issues' }}
|
||||||
env:
|
env:
|
||||||
ISSUE_NUMBER: ${{ github.event.issue.number }}
|
ISSUE_NUMBER: ${{ github.event.issue.number }}
|
||||||
run: node .github/scripts/sync-project-triage.mjs --issue-number "$ISSUE_NUMBER"
|
ISSUE_EVENT_ACTION: ${{ github.event.action }}
|
||||||
|
run: node .github/scripts/sync-project-triage.mjs --issue-number "$ISSUE_NUMBER" --event-action "$ISSUE_EVENT_ACTION"
|
||||||
|
|
||||||
- name: Backfill open issues
|
- name: Backfill open issues
|
||||||
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.backfill == 'true' }}
|
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.backfill == 'true' }}
|
||||||
|
|||||||
Reference in new issue
Block a user