Skip to content

Commit

Permalink
add option to add the farthest due milestone
Browse files Browse the repository at this point in the history
  • Loading branch information
benelan committed Sep 3, 2021
1 parent 89879a9 commit 9ac638a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ jobs:
- uses: ./
with:
github_token: "${{ secrets.GITHUB_TOKEN }}"
farthest: true
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Add Milestone By Due Date

This action adds the current milestone to an issue or pull request. It chooses the milestone that expires soonest, excluding those that already expired, based on the datetime that the action is run. You can see a successful test run [here](https://github.com/benelan/milestone-action/issues/8).
This action adds the current or farthest due milestone to issues and pull requests. The current milestone is the one due the soonest, excluding milestones that are past due, based on the datetime that the action is run. You can see a successful test run [here](https://github.com/benelan/milestone-action/issues/8).


## Usage
Expand All @@ -21,4 +21,5 @@ jobs:
- uses: benelan/[email protected]
with:
github_token: "${{ secrets.GITHUB_TOKEN }}"
farthest: true # remove this line to add the current milestone
```
6 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'Add Milestone By Due Date'
description: 'Adds the current milestone to a pull request or issue '
description: 'Adds the current or farthest due milestone to pull requests and issues'
author: 'Ben Elan'
branding:
icon: git-branch
Expand All @@ -8,6 +8,10 @@ inputs:
github_token:
description: 'Token for the repository. Can be passed in using {{ secrets.GITHUB_TOKEN }}'
required: true
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.'
required: false
default: false
runs:
using: 'node12'
main: 'dist/index.js'
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "milestone-action",
"version": "1.0.1",
"private": true,
"description": "A GitHub Action to automatically set the current milestone on issues and pull requests.",
"description": "A GitHub Action to automatically set the current or farthest due milestone on issues and pull requests.",
"main": "lib/main.js",
"scripts": {
"build": "tsc",
Expand Down
11 changes: 7 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,19 @@ async function run(): Promise<void> {
return
}

const farthest = core.getBooleanInput('farthest')
const myToken = core.getInput('github_token')
const client = github.getOctokit(myToken)

const milestones = await client.rest.issues.listMilestones({
...repo,
state: 'open',
sort: 'due_on',
direction: 'asc'
direction: farthest ? 'desc' : 'asc'
})

if (milestones.data.length === 0) {
console.log('There are no milestones, skipping.')
console.log('There are no open milestones in this repo, skipping.')
return
}

Expand All @@ -52,8 +53,10 @@ async function run(): Promise<void> {
return
}
}
} catch (e) {
core.setFailed(e.message)
} catch (e: unknown) {
if (e instanceof Error) {
core.setFailed(e.message)
}
}
}

Expand Down

0 comments on commit 9ac638a

Please sign in to comment.