Skip to content

Commit

Permalink
attempt workaround github api issue: after converting issue to PR, ca…
Browse files Browse the repository at this point in the history
…n no longer move its status on project board

error message: Prioritization The priority you are attempting to set for this record is not unique
see: actions/add-to-project#89 (comment)
  • Loading branch information
flexponsive committed Oct 18, 2022
1 parent 66f2ca3 commit 44c723e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ inputs:
description: Moves the card for this issue to the top of this column
required: true
default: "false"
replace:
description: Try to delete any existing card for the issue/PR before updating
required: false
default: "false"
outputs:
card-node-id: # id of output
description: Node ID of the card created or updated
Expand Down
27 changes: 26 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const inputs = {
issueNodeId: (
github.context.payload.issue ?? github.context.payload.pull_request
).node_id,
replace: ["true", "1", "yes"].includes(core.getInput("replace")),
};

core.debug(`INPUTS ${JSON.stringify(inputs)}`);
Expand Down Expand Up @@ -44,7 +45,30 @@ async function main() {
);
}

// STEP 2: Add our Issue/PR to that project board.
// STEP 2A: If required, delete any existing card from the project (before re-adding it, see https://github.com/actions/add-to-project/issues/89#issuecomment-1233952145)
if (inputs.replace) {
try {
const issueCard = getIssueCardOnProject(octokitGraphql, projectDetails.projectNodeId, inputs.issueNodeId);
console.log('ISSUE CARD', issueCard);
const deleteOldCard = await octokitGraphql(
`mutation {
deleteProjectV2Item(
input: {
projectId: "${projectDetails.projectNodeId}"
itemId: "${issueCard.id}"
}
) {
deletedItemId
}
}`
);
console.log('DELETE OLD CARD', deleteOldCard);
} catch (e) {
console.log('could not delete old project card', e);
}
}

// STEP 2B: Add our Issue/PR to that project board.
const addIssueToProject = await octokitGraphql(
`mutation addIssueToProject($input: AddProjectV2ItemByIdInput!) {
addProjectV2ItemById(input: $input) {
Expand Down Expand Up @@ -182,3 +206,4 @@ async function getProjectDetails(octokitGraphql, projectBoardLink) {
core.debug(`GETPROJECTDETAILS ${JSON.stringify(projectInfo)}`);
return projectInfo;
}

0 comments on commit 44c723e

Please sign in to comment.