Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add config for running in a date window #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,29 @@ jobs:
| {{ id }} | The numeric id of the issue/pr |
| {{ payload.* }} | The payload of the [issue/pr](https://docs.github.com/cn/rest/pulls/pulls#get-a-pull-request) |

### Running within a specific date window

You can configure the action to only run after a specific date, before a specific date, or between a start and end date.

```yml
name: Auto Comment
on: [issues, pull_request]
jobs:
run:
runs-on: ubuntu-latest
steps:
- uses: wow-actions/auto-comment@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
startDate: 2022-12-24
endDate: 2023-01-02
issuesOpenedComment: |
👋 @{{ author }}
Thank you for raising an issue.
We are on a company-wide holiday, and will only be investigating SEV-1 issues between Christmas and New Years.
If you have a SEV-1 issue, you can raise it by filing a "Production Outage" issue.
```

## 🔖 License

The scripts and documentation in this project are released under the [MIT License](LICENSE)
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,12 @@ inputs:
pullRequestReviewRequestRemovedReactions:
required: false

startDate:
required: false

endDate:
required: false

runs:
using: node16
main: dist/index.js
Expand Down
16 changes: 16 additions & 0 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ export namespace Action {
core.info(`action: ${action}`)
core.info(`event: ${Util.getEventName()}`)

const startDate = Util.getStartDate()
const endDate = Util.getEndDate()
if (startDate || endDate) {
core.info(`StartDate: ${startDate} - EndDate ${endDate}`)
const now = new Date()
core.info(`Today: ${now}`)

if (!(startDate && startDate < now)) {
throw new Error('Running before StartDate - not executing')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if throwing an error here (and below) is desired behavior (do people monitor workflow executions)?

Happy to refactor this to something better if that's the preferred approach.

}
if (!(endDate && endDate > now)) {
throw new Error('Running after EndDate - not executing')
}
core.info('Running inside of configured time - executing')
}

const comment = Util.getComment()
const payload = context.payload.issue || context.payload.pull_request
if (comment && payload) {
Expand Down
8 changes: 8 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,12 @@ export namespace Util {

return null
}

export function getStartDate() {
return new Date(Date.parse(core.getInput('startDate')))
}

export function getEndDate() {
return new Date(Date.parse(core.getInput('endDate')))
}
Comment on lines +102 to +108
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not doing any validation on the input, as Date.parse will return NaN if the format isn't a date.

}