Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Page committed Jun 26, 2021
2 parents 75411c4 + 541882c commit 80978ac
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 9 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
automate-project-columns:
runs-on: ubuntu-latest
steps:
- uses: alex-page/github-project-automation-plus@v0.7.1
- uses: alex-page/github-project-automation-plus@v0.8.0
with:
project: Backlog
column: Triage
Expand All @@ -51,7 +51,7 @@ jobs:
automate-project-columns:
runs-on: ubuntu-latest
steps:
- uses: alex-page/github-project-automation-plus@v0.7.1
- uses: alex-page/github-project-automation-plus@v0.8.0
with:
project: Backlog
column: To do
Expand All @@ -69,7 +69,7 @@ Change these options in the workflow `.yml` file to meet your GitHub project nee
| `project` | The name of the project | `Backlog` |
| `column` | The column to create or move the card to | `Triage` |
| `repo-token` | The personal access token | `${{ secrets.GITHUB_TOKEN }}` |
| `action` | This determines the type of the action to be performed on the card, Default: `update` | `update`, `delete`, `archive` |
| `action` | This determines the type of the action to be performed on the card, Default: `update` | `update`, `delete`, `archive`, `add` |

## Personal access token

Expand Down Expand Up @@ -112,6 +112,7 @@ You may need to enable policy settings to allow running workflows from forks. Pl

## Release History

- v0.8.0 - Add new action type 'add'
- v0.7.1 - Move Node.js version back to v12
- v0.7.0 - Update documentation and dependencies
- v0.6.0 - Add support for `pull_request_target` and `pull_request_review`
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ inputs:
required: true
action:
description: |
Can be `update`, `delete` or `archive`. This determines the type of the action
Can be `update`, `delete` or `archive` or `add`. This determines the type of the action
to be performed on the card
required: false
default: "update"
Expand Down
4 changes: 2 additions & 2 deletions dist/index.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "github-project-automation-plus",
"version": "0.6.0",
"version": "0.8.0",
"description": "🤖 Automate GitHub Project cards with any webhook event",
"private": true,
"main": "dist/index.js",
Expand Down Expand Up @@ -39,4 +39,4 @@
"files": [
"dist/index.js"
]
}
}
9 changes: 9 additions & 0 deletions src/generate-mutation-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ const generateMutationQuery = (data, projectName, columnName, contentId, action)
}) { clientMutationId } }`;
}

if (action === 'add' && !cardLocations[mutation].cardId) {
// Add issue if the card does not exist in the project
return `mutation {
addProjectCard( input: {
contentId: "${contentId}",
projectColumnId: "${cardLocations[mutation].columnId}"
}) { clientMutationId } }`;
}

return undefined;
});

Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const generateMutationQuery = require('./generate-mutation-query');

// A list of columns that line up with the user entered project and column
const mutationQueries = generateMutationQuery(resource, project, column, nodeId, action);
if ((action === 'delete' || action === 'archive') && mutationQueries.length === 0) {
if ((action === 'delete' || action === 'archive' || action === 'add') && mutationQueries.length === 0) {
console.log('✅ There is nothing to do with card');
return;
}
Expand Down
4 changes: 4 additions & 0 deletions tests/generate-mutation-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ test('generateMutationQuery delete the card when it is in the project already',
]);
});

test('generateMutationQuery skip issue addition when the card already exists in the project', t => {
t.deepEqual(generateMutationQuery(moveData, project, column, nodeId, 'add'), []);
});

const addData = {
projectCards: {
nodes: []
Expand Down

0 comments on commit 80978ac

Please sign in to comment.