From 92c8d07746c60ba0aff150f47462d3cc78be458e Mon Sep 17 00:00:00 2001 From: Ferdynand Naczynski Date: Wed, 16 Oct 2024 13:41:59 +0200 Subject: [PATCH] feat: do not set milestones on issues (#25) --- action.js | 76 ++++++++++++++---------- graphql/projectIssueItemAssignFields.gql | 19 ++++++ 2 files changed, 63 insertions(+), 32 deletions(-) create mode 100644 graphql/projectIssueItemAssignFields.gql diff --git a/action.js b/action.js index 53f77ed..4de6e12 100644 --- a/action.js +++ b/action.js @@ -156,7 +156,7 @@ module.exports = async ( }; // leave drafts alone - if (isDraftPr){ + if (isDraftPr) { coreGlob.info("detected PR draft, skipping project assignment"); return } @@ -207,48 +207,60 @@ module.exports = async ( }; }; - // set milestones & effort if a PR and includeEffort - if (includeEffort && isPr) { - const assignProjectFieldsQuery = fs.readFileSync(`${basePath}/graphql/projectEffortItemAssignFields.gql`, 'utf8'); - const assignProjectFieldsParams = { - project: projectId, - item: projectItemId, - status_field: statusFieldId, - status_value: statusValueId, - effort_field: effortFieldId, - effort_value: effortValueId, - primary_milestone_field: monthlyMilestoneFieldId, - primary_milestone_value: monthlyMilestoneValueId, - secondary_milestone_field: quarterlyMilestoneFieldId, - secondary_milestone_value: quarterlyMilestoneValueId - }; - try { - await github.graphql(assignProjectFieldsQuery, assignProjectFieldsParams); - } catch (error) { - bail(error.message); - }; - coreGlob.info("set project fields including effort"); - }; - - // set milestones if an Issue or if a PR and not includeEffort - if (!isPr || !includeEffort) { - const assignProjectFieldsQuery = fs.readFileSync(`${basePath}/graphql/projectNoEffortItemAssignFields.gql`, 'utf8'); + if (isPr) { // set status, milestones & maybe effort if a PR + if (includeEffort) { + const assignProjectFieldsQuery = fs.readFileSync(`${basePath}/graphql/projectEffortItemAssignFields.gql`, 'utf8'); + const assignProjectFieldsParams = { + project: projectId, + item: projectItemId, + status_field: statusFieldId, + status_value: statusValueId, + effort_field: effortFieldId, + effort_value: effortValueId, + primary_milestone_field: monthlyMilestoneFieldId, + primary_milestone_value: monthlyMilestoneValueId, + secondary_milestone_field: quarterlyMilestoneFieldId, + secondary_milestone_value: quarterlyMilestoneValueId + }; + try { + await github.graphql(assignProjectFieldsQuery, assignProjectFieldsParams); + } catch (error) { + bail(error.message); + }; + coreGlob.info("set project fields including effort"); + } else { + const assignProjectFieldsQuery = fs.readFileSync(`${basePath}/graphql/projectNoEffortItemAssignFields.gql`, 'utf8'); + const assignProjectFieldsParams = { + project: projectId, + item: projectItemId, + status_field: statusFieldId, + status_value: statusValueId, + primary_milestone_field: monthlyMilestoneFieldId, + primary_milestone_value: monthlyMilestoneValueId, + secondary_milestone_field: quarterlyMilestoneFieldId, + secondary_milestone_value: quarterlyMilestoneValueId + }; + try { + await github.graphql(assignProjectFieldsQuery, assignProjectFieldsParams); + } catch (error) { + bail(error.message); + }; + coreGlob.info("set project fields omitting effort"); + } + } else { // set status if an Issue + const assignProjectFieldsQuery = fs.readFileSync(`${basePath}/graphql/projectIssueItemAssignFields.gql`, 'utf8'); const assignProjectFieldsParams = { project: projectId, item: projectItemId, status_field: statusFieldId, status_value: statusValueId, - primary_milestone_field: monthlyMilestoneFieldId, - primary_milestone_value: monthlyMilestoneValueId, - secondary_milestone_field: quarterlyMilestoneFieldId, - secondary_milestone_value: quarterlyMilestoneValueId }; try { await github.graphql(assignProjectFieldsQuery, assignProjectFieldsParams); } catch (error) { bail(error.message); }; - coreGlob.info("set project fields omitting effort"); + coreGlob.info("set project fields omitting effort & milestones"); } } diff --git a/graphql/projectIssueItemAssignFields.gql b/graphql/projectIssueItemAssignFields.gql new file mode 100644 index 0000000..d16c38f --- /dev/null +++ b/graphql/projectIssueItemAssignFields.gql @@ -0,0 +1,19 @@ +mutation ( + $project: ID! + $item: ID! + $status_field: ID! + $status_value: String! +) { + status: updateProjectV2ItemFieldValue( + input: { + projectId: $project + itemId: $item + fieldId: $status_field + value: { singleSelectOptionId: $status_value } + } + ) { + projectV2Item { + id + } + } +}