diff --git a/README.md b/README.md index 3608c60..2bd41b5 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/action.yml b/action.yml index 5b9cccd..b4792fa 100644 --- a/action.yml +++ b/action.yml @@ -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" diff --git a/dist/index.js b/dist/index.js index aaf33b1..94bac39 100644 --- a/dist/index.js +++ b/dist/index.js @@ -28925,6 +28925,7 @@ async function run() { } const farthest = (0, core_1.getBooleanInput)("farthest"); const overwrite = (0, core_1.getBooleanInput)("overwrite"); + const single = (0, core_1.getBooleanInput)("single"); const token = (0, core_1.getInput)("repo-token"); const octokit = (0, github_1.getOctokit)(token); if (!overwrite && (issue?.milestone || pull_request?.milestone)) { @@ -28942,6 +28943,16 @@ async function run() { (0, core_1.warning)("Exit: there are no open milestones in this repo."); process.exit(0); } + if (single && milestones.length === 1) { + await octokit.rest.issues.update({ + ...repo, + issue_number, + milestone: milestones[0].number, + }); + (0, core_1.notice)(`Success: the issue or pull request was added to the "${milestones[0]?.title}" milestone.`); + (0, core_1.setOutput)("milestone", milestones[0]); + process.exit(0); + } const currentDate = new Date(Date.now()); currentDate.setUTCHours(0, 0, 0, 0); for (const milestone of milestones) { diff --git a/src/main.ts b/src/main.ts index 2420448..011ada6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -24,6 +24,7 @@ export async function run(): Promise { const farthest = getBooleanInput("farthest"); const overwrite = getBooleanInput("overwrite"); + const single = getBooleanInput("single"); const token = getInput("repo-token"); const octokit = getOctokit(token); @@ -48,6 +49,21 @@ export async function run(): Promise { 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);