Skip to content

Commit

Permalink
🔀 Merge pull request #6 from ChromaticHQ/master
Browse files Browse the repository at this point in the history
GH-5 Add support for optional excluded-statuses option
  • Loading branch information
blombard authored Jan 9, 2024
2 parents 1eedfb0 + db380bd commit e70c0d0
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 6 deletions.
36 changes: 33 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Automatically move issues and pull requests to the next iteration of your [GitHu

## Example

```yml
```yaml
on:
schedule:
# Runs "at 05:00, only on Monday" (see https://crontab.guru)
Expand All @@ -24,7 +24,32 @@ jobs:
iteration-field: Iteration
iteration: last
new-iteration: current
statuses: Todo,In Progress,In Review
statuses: 'Todo,In Progress,In Review'
```
Alternatively, you may specify `excluded-statuses`. In this case, all items that _don’t_ have these statuses will be moved to the new iteration. (Note that if `excluded-statuses` is used, `statuses` will be ignored.)

```yaml
on:
schedule:
# Runs "at 05:00, only on Monday" (see https://crontab.guru)
- cron: '0 5 * * 1'
jobs:
move-to-next-iteration:
name: Move to next iteration
runs-on: ubuntu-latest
steps:
- uses: blombard/move-to-next-iteration@master
with:
owner: OrgName
number: 1
token: ${{ secrets.PROJECT_PAT }}
iteration-field: Iteration
iteration: last
new-iteration: current
excluded-statuses: "Done,Won't Fix"
```

## Inputs
Expand All @@ -49,7 +74,12 @@ Should be `current` or `next`.
#### statuses
Statuses of the issues to move to the next iteration.

⚠️ _Don't put an empty string after a comma unless the status starts with an empty string._ ⚠️
⚠️ _This setting is ignored if `excluded-statuses` is provided. See below._ ⚠️

#### excluded-statuses
Statuses of the issues that should _not_ be moved.

⚠️ _This setting takes precedence over `statuses`._ ⚠️

## Sources

Expand Down
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ inputs:
required: true
statuses:
description: Statuses of the issues to move to the next iteration.
required: true
required: false
excluded-statuses:
description: Statuses of the issues that should not be moved. This setting takes precedence over statuses.
required: false
runs:
using: 'node16'
main: 'dist/index.js'
14 changes: 13 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9824,6 +9824,7 @@ const run = async () => {
const iterationType = core.getInput('iteration'); // last or current
const newiterationType = core.getInput('new-iteration'); // current or next
const statuses = core.getInput('statuses').split(',');
const excludedStatuses = core.getInput('excluded-statuses').split(',');

const project = new GitHubProject({ owner, number, token, fields: { iteration: iterationField } });

Expand All @@ -9838,7 +9839,18 @@ const run = async () => {

const items = await project.items.list();

const filteredItems = items.filter(item => statuses.includes(item.fields.status) && item.fields.iteration === iteration.title);
const filteredItems = items.filter(item => {
// If item is not in the old iteration, return false.
if (item.fields.iteration !== iteration.title) return false;
// If excludedStatuses are supplied, use that. Otherwise, use statuses.
if (excludedStatuses?.length) {
// Move item only if its status _is not_ in the excluded statuses list.
return !excludedStatuses.includes(item.fields.status);
} else {
// Move item only if its status _is_ in the statuses list.
return statuses.includes(item.fields.status);
}
});

await Promise.all(filteredItems.map(item => project.items.update(item.id, { iteration: newIteration.title })));
} catch (error) {
Expand Down
14 changes: 13 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const run = async () => {
const iterationType = core.getInput('iteration'); // last or current
const newiterationType = core.getInput('new-iteration'); // current or next
const statuses = core.getInput('statuses').split(',');
const excludedStatuses = core.getInput('excluded-statuses').split(',');

const project = new GitHubProject({ owner, number, token, fields: { iteration: iterationField } });

Expand All @@ -24,7 +25,18 @@ const run = async () => {

const items = await project.items.list();

const filteredItems = items.filter(item => statuses.includes(item.fields.status) && item.fields.iteration === iteration.title);
const filteredItems = items.filter(item => {
// If item is not in the old iteration, return false.
if (item.fields.iteration !== iteration.title) return false;
// If excludedStatuses are supplied, use that. Otherwise, use statuses.
if (excludedStatuses?.length) {
// Move item only if its status _is not_ in the excluded statuses list.
return !excludedStatuses.includes(item.fields.status);
} else {
// Move item only if its status _is_ in the statuses list.
return statuses.includes(item.fields.status);
}
});

await Promise.all(filteredItems.map(item => project.items.update(item.id, { iteration: newIteration.title })));
} catch (error) {
Expand Down

0 comments on commit e70c0d0

Please sign in to comment.