Skip to content

Commit

Permalink
feat: do not set milestones on issues (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
nipsufn authored Oct 16, 2024
1 parent c4b880a commit 92c8d07
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 32 deletions.
76 changes: 44 additions & 32 deletions action.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ module.exports = async (
};

// leave drafts alone
if (isDraftPr){
if (isDraftPr) {
coreGlob.info("detected PR draft, skipping project assignment");
return
}
Expand Down Expand Up @@ -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");
}
}

Expand Down
19 changes: 19 additions & 0 deletions graphql/projectIssueItemAssignFields.gql
Original file line number Diff line number Diff line change
@@ -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
}
}
}

0 comments on commit 92c8d07

Please sign in to comment.