diff --git a/README.md b/README.md index b3a54ab..12780fc 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/action.yml b/action.yml index d8b16b6..3c10d6d 100644 --- a/action.yml +++ b/action.yml @@ -280,6 +280,12 @@ inputs: pullRequestReviewRequestRemovedReactions: required: false + startDate: + required: false + + endDate: + required: false + runs: using: node16 main: dist/index.js diff --git a/src/action.ts b/src/action.ts index bebe42c..dc0cc1d 100644 --- a/src/action.ts +++ b/src/action.ts @@ -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') + } + 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) { diff --git a/src/util.ts b/src/util.ts index 0aeb9e1..074268d 100644 --- a/src/util.ts +++ b/src/util.ts @@ -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'))) + } }