Skip to content

Commit

Permalink
feat: add option for single milestone with no due date
Browse files Browse the repository at this point in the history
  • Loading branch information
benelan committed Feb 10, 2024
1 parent e5effd6 commit 47e7b58
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 12 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,21 @@ jobs:
steps:
- uses: benelan/milestone-action@v3
with:
farthest: true # remove this line to add the current milestone
overwrite: true # remove this line to keep an existing milestone
farthest: false # if true, add the milestone with the farthest due date.
overwrite: true # if true, allow overwriting an existing milestone.
single: false # if true, add a milestone if it's the only one open,
# even if it doesn't have a due date.
```

## Changelog

### [3.1.0](https://github.com/benelan/milestone-action/compare/v3.0.0...v3.1.0) (2024-02-10)

#### Features

- Add `single` option for workflows the consist of a single open milestone with
no due date.

### [3.0.0](https://github.com/benelan/milestone-action/compare/v2.0.0...v3.0.0) (2024-01-24)

#### Breaking Changes
Expand Down
24 changes: 14 additions & 10 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
name: 'Add Milestone By Due Date'
description: 'Add the milestone with the current or farthest due date to pull requests and issues'
author: 'Ben Elan'
name: "Add Milestone By Due Date"
description: "Add the milestone with the current or farthest due date to pull requests and issues"
author: "Ben Elan"
branding:
icon: calendar
color: green
inputs:
repo-token:
description: 'Token for the repository. Defaults to `{{ github.token }}`'
description: "Token for the repository. Defaults to `{{ github.token }}`"
default: ${{ github.token }}
required: false
farthest:
description: 'Set this boolean to `true` if you want to add the milestone with the farthest due date. Defaults to `false`, which adds the current milestone.'
description: "Set this boolean to `true` if you want to add the milestone with the farthest due date. Defaults to `false`, which adds the current milestone."
required: false
default: 'false'
default: "false"
overwrite:
description: 'Set this boolean to `true` if you want the action to overwrite existing milestones on issues. Defaults to `false`, which ends the run if the issue already has a milestone.'
description: "Set this boolean to `true` if you want the action to overwrite existing milestones on issues. Defaults to `false`, which ends the run if the issue already has a milestone."
required: false
default: 'false'
default: "false"
single:
description: "Set this boolean to `true` if you only have a single milestone open at a time but don't set the due date. Defaults to `false`, which will not select a milestone if it doesn't have a due date, even if there is only one milestone open."
required: false
default: "false"
runs:
using: 'node20'
main: 'dist/index.js'
using: "node20"
main: "dist/index.js"
11 changes: 11 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export async function run(): Promise<void> {

const farthest = getBooleanInput("farthest");
const overwrite = getBooleanInput("overwrite");
const single = getBooleanInput("single");

const token = getInput("repo-token");
const octokit = getOctokit(token);
Expand All @@ -48,6 +49,21 @@ export async function run(): Promise<void> {
process.exit(0);
}

if (single && milestones.length === 1) {
await octokit.rest.issues.update({
...repo,
issue_number,
milestone: milestones[0].number,
});

notice(
`Success: the issue or pull request was added to the "${milestones[0]?.title}" milestone.`,
);

setOutput("milestone", milestones[0]);
process.exit(0);
}

const currentDate = new Date(Date.now());
currentDate.setUTCHours(0, 0, 0, 0);

Expand Down

0 comments on commit 47e7b58

Please sign in to comment.