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 new options to stop the processing sooner if too many queries were performed #382

Merged
merged 6 commits into from
Feb 2, 2022
Merged
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
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ To help us have a clear vision over the workflow and also for you if you are jus

- Check if the issues processing is enabled and stop the processing if this is the case (coming from the `issue-processing` input)
- Fetch all the open issues per batch of 20, sorted by update date from the oldest first
- Check if the issue can be processed
- If the issues API queries calls performed are below the limit (coming from the `issue-limit-api-queries-count`), stop the processing
- Check if the issue is locked and stop the processing if this is the case
- Check if the issue has a label (except the stale one) and stop the processing if this is the case (coming from the `issue-ignore-all-labels` input)
- Check if the issue has any of the ignored labels and stop the processing if this is the case (coming from the `issue-ignore-any-labels` input)
Expand Down Expand Up @@ -157,6 +159,8 @@ To help us have a clear vision over the workflow and also for you if you are jus

- Check if the pull requests processing is enabled and stop the processing if this is the case (coming from the `pull-request-processing` input)
- Fetch all the open pull requests per batch of 20, sorted by update date from the oldest first
- Check if the pull request can be processed
- If the pull requests API queries calls performed are below the limit (coming from the `pull-request-limit-api-queries-count`), stop the processing
- Check if the pull request is locked and stop the processing if this is the case
- Check if the pull request has a label (except the stale one) and stop the processing if this is the case (coming from the `pull-request-ignore-all-labels` input)
- Check if the pull request has any of the ignored labels and stop the processing if this is the case (coming from the `pull-request-ignore-any-labels` input)
Expand Down
94 changes: 3 additions & 91 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ All the inputs that are used both for issues and pull requests.
| [issue-add-labels-after-stale](https://sonia-corporation.github.io/stale/docs/issues/inputs/issue-add-labels-after-stale-input) | A list of labels added when the processing stale the issue (multiline). | |
| [issue-add-labels-after-close](https://sonia-corporation.github.io/stale/docs/issues/inputs/issue-add-labels-after-close-input) | A list of labels added when the processing close the issue (multiline). | |
| [issue-processing](https://sonia-corporation.github.io/stale/docs/issues/inputs/issue-processing-input) | Allow to process the issues. | `true` |
| [issue-limit-api-queries-count](https://sonia-corporation.github.io/stale/docs/issues/inputs/issue-limit-api-queries-count) | Limit the quantity of API queries calls performed during the processing of issues (-1 for unlimited). | `-1` |

## All the issues outputs

Expand Down Expand Up @@ -130,6 +131,7 @@ All the inputs that are used both for issues and pull requests.
| [pull-request-add-labels-after-close](https://sonia-corporation.github.io/stale/docs/pull-requests/inputs/pull-request-add-labels-after-close-input) | A list of labels added when the processing close the pull request (multiline). | |
| [pull-request-processing](https://sonia-corporation.github.io/stale/docs/pull-requests/inputs/pull-request-processing-input) | Allow to process the pull requests. | `true` |
| [pull-request-to-draft-instead-of-stale](https://sonia-corporation.github.io/stale/docs/pull-requests/inputs/pull-request-to-draft-instead-of-stale-input) | Convert the pull request to a draft pull request instead of handling it as a stale candidate. | `false` |
| [pull-request-limit-api-queries-count](https://sonia-corporation.github.io/stale/docs/pull-requests/inputs/pull-request-limit-api-queries-count) | Limit the quantity of API queries calls performed during the processing of pull requests (-1 for unlimited). | `-1` |

## All the pull requests outputs

Expand All @@ -152,97 +154,7 @@ All the inputs that are used both for issues and pull requests.

## Examples

### All issues inputs example

```yml
name: Stale
on:
workflow_dispatch:
schedule:
- cron: '0 12 * * *'
jobs:
Stale:
runs-on: ubuntu-latest
name: Run stale
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v2
- name: Stale
id: stale
uses: sonia-corporation/stale@1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
dry-run: false
issue-ignore-all-assignees: false
issue-ignore-any-assignees: |
marco
polo
issue-ignore-all-labels: false
issue-stale-label: stale
issue-ignore-any-labels: |
frozen :ice_cube:
help wanted :sos:
dependency-fix :wrench:
dependencies :package:
issue-days-before-stale: 30
issue-days-before-close: 10
issue-ignore-before-creation-date: 2020-04
issue-stale-comment: |
This issue is now stale!
issue-close-comment: |
This issue is now closed!
issue-ignore-all-project-cards: false
issue-add-labels-after-stale: |
wake up!
```

### All pull requests inputs example

```yml
name: Stale
on:
workflow_dispatch:
schedule:
- cron: '0 12 * * *'
jobs:
Stale:
runs-on: ubuntu-latest
name: Run stale
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v2
- name: Stale
id: stale
uses: sonia-corporation/stale@1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
dry-run: false
pull-request-ignore-all-assignees: false
pull-request-ignore-any-assignees: |
marco
polo
pull-request-ignore-all-labels: false
pull-request-stale-label: stale
pull-request-ignore-any-labels: |
frozen :ice_cube:
help wanted :sos:
dependency-fix :wrench:
dependencies :package:
pull-request-days-before-stale: 30
pull-request-days-before-close: 10
pull-request-ignore-before-creation-date: 2020-04
pull-request-stale-comment: |
This pull request is now stale!
pull-request-close-comment: |
This pull request is now closed!
pull-request-ignore-all-project-cards: false
pull-request-ignore-draft: false
pull-request-delete-branch-after-close: false
pull-request-add-labels-after-stale: |
wake up!
```
Checkout the [documentation](https://sonia-corporation.github.io/stale/docs/introduction) to have some examples.

## Debug the action

Expand Down
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ inputs:
description: 'Allow to process the issues.'
required: false
default: 'true'
issue-limit-api-queries-count:
description: 'Limit the quantity of API queries calls performed during the processing of issues (-1 for unlimited).'
required: false
default: '-1'
# Pull request inputs
pull-request-stale-label:
description: 'The label that will be added to the pull request when it is stale.'
Expand Down Expand Up @@ -137,6 +141,10 @@ inputs:
description: 'Convert the pull request to a draft pull request instead of handling it as a stale candidate.'
required: false
default: 'false'
pull-request-limit-api-queries-count:
description: 'Limit the quantity of API queries calls performed during the processing of pull requests (-1 for unlimited).'
required: false
default: '-1'
outputs:
# Issues outputs
processed-issues-count:
Expand Down
4 changes: 2 additions & 2 deletions dist/index.js

Large diffs are not rendered by default.

18 changes: 15 additions & 3 deletions documentation/docs/02-getting-started/02-workflow-testing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ tags:
At this point, you shall have a working stale action.
Before going further into the customization, you may want to try it first.

:::tip
### Test it with the dry-run mode {#test-it-with-the-dry-run-mode}

Use the [dry-run](../dry-run-input) mode to avoid altering your repository yet.

:::

```yml {5-6} title=".github/workflows/stale.yml"
# ...
name: Stale
Expand All @@ -33,6 +31,20 @@ You will have a better idea over what to expect when a real run without the [dry

:::

### Test it with a limited amount of API calls {#test-it-with-a-limited-amount-of-api-calls}

If you still wish to play it safe, you can configure a limit of API queries calls for your [issues](../issues/inputs/issue-limit-api-queries-count-input) and [pull requests](../pull-requests/inputs/pull-request-limit-api-queries-count-input) to alter your repository on a reduced scope.

```yml {5-7} title=".github/workflows/stale.yml"
# ...
name: Stale
id: stale
uses: sonia-corporation/stale@latest
with:
issue-limit-api-queries-count: 30
C0ZEN marked this conversation as resolved.
Show resolved Hide resolved
pull-request-limit-api-queries-count: 30
```

## Customize the behaviour {#customize-the-behaviour}

If the action was successful, you may wish now to configure it at your convenience.
Expand Down
2 changes: 2 additions & 0 deletions documentation/docs/03-all-inputs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ The list of all the inputs.
| [issue-add-labels-after-stale](issues/inputs/issue-add-labels-after-stale-input) | A list of labels added when the processing stale the issue (multiline). | |
| [issue-add-labels-after-close](issues/inputs/issue-add-labels-after-close-input) | A list of labels added when the processing close the issue (multiline). | |
| [issue-processing](issues/inputs/issue-processing-input) | Allow to process the issues. | `true` |
| [issue-limit-api-queries-count](issues/inputs/issue-limit-api-queries-count-input) | Limit the quantity of API queries calls performed during the processing of issues (-1 for unlimited). | `-1` |
| [pull-request-stale-label](pull-requests/inputs/pull-request-stale-label-input) | The label that will be added to the pull request when it is stale. | `stale` |
| [pull-request-ignore-all-labels](pull-requests/inputs/pull-request-ignore-all-labels-input) | Allow to ignore the processing of pull requests that contains any labels. | `false` |
| [pull-request-ignore-any-labels](pull-requests/inputs/pull-request-ignore-any-labels-input) | Allow to ignore the processing of pull requests that contains one of those labels (multiline). | |
Expand All @@ -45,3 +46,4 @@ The list of all the inputs.
| [pull-request-add-labels-after-close](pull-requests/inputs/pull-request-add-labels-after-close-input) | A list of labels added when the processing close the pull request (multiline). | |
| [pull-request-processing](pull-requests/inputs/pull-request-processing-input) | Allow to process the pull requests. | `true` |
| [pull-request-to-draft-instead-of-stale](pull-requests/inputs/pull-request-to-draft-instead-of-stale-input) | Convert the pull request to a draft pull request instead of handling it as a stale candidate. | `false` |
| [pull-request-limit-api-queries-count](pull-requests/inputs/pull-request-limit-api-queries-count-input) | Limit the quantity of API queries calls performed during the processing of pull requests (-1 for unlimited). | `-1` |
1 change: 1 addition & 0 deletions documentation/docs/06-issues/01-inputs/01-all-inputs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ The list of all issues the inputs.
| [issue-add-labels-after-stale](issue-add-labels-after-stale-input) | A list of labels added when the processing stale the issue (multiline). | |
| [issue-add-labels-after-close](issue-add-labels-after-close-input) | A list of labels added when the processing close the issue (multiline). | |
| [issue-processing](issue-processing-input) | Allow to process the issues. | `true` |
| [issue-limit-api-queries-count](issue-limit-api-queries-count-input) | Limit the quantity of API queries calls performed during the processing of issues (-1 for unlimited). | `-1` |
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
id: issue-limit-api-queries-count-input
title: Issue limit api queries count input
tags:
- Issues
- Inputs
---

### Input {#input}

Name: `issue-limit-api-queries-count`
Type: `number`
Default value: `-1`

### Description {#description}

This input will let you define a limit count of issues API queries calls performed during the processing.
If the limit is reached, the ongoing processed issue will finish it's processing then all other issues will be ignored.
This can be useful when you want to play it safe with this action.
This can be also very useful if you have a lot of issues to process, and you want to limit the quotas of your associated [GitHub token](../../github-token-input).

### Example {#example}

```yml {6}
# ...
name: Stale
id: stale
uses: sonia-corporation/stale@latest
with:
issue-limit-api-queries-count: false
```
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ The list of all the pull requests inputs.
| [pull-request-add-labels-after-close](pull-request-add-labels-after-close-input) | A list of labels added when the processing close the pull request (multiline). | |
| [pull-request-processing](pull-request-processing-input) | Allow to process the pull requests. | `true` |
| [pull-request-to-draft-instead-of-stale](pull-request-to-draft-instead-of-stale-input) | Convert the pull request to a draft pull request instead of handling it as a stale candidate. | `false` |
| [pull-request-limit-api-queries-count](pull-request-limit-api-queries-count-input) | Limit the quantity of API queries calls performed during the processing of pull requests (-1 for unlimited). | `-1` |
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
id: pull-request-limit-api-queries-count-input
title: Pull request limit api queries count input
tags:
- Pull requests
- Inputs
---

### Input {#input}

Name: `pull-request-limit-api-queries-count`
Type: `number`
Default value: `-1`

### Description {#description}

This input will let you define a limit count of pull requests API queries calls performed during the processing.
If the limit is reached, the ongoing processed pull request will finish it's processing then all other pull requests will be ignored.
This can be useful when you want to play it safe with this action.
This can be also very useful if you have a lot of pull requests to process, and you want to limit the quotas of your associated [GitHub token](../../github-token-input).

### Example {#example}

```yml {6}
# ...
name: Stale
id: stale
uses: sonia-corporation/stale@latest
with:
pull-request-limit-api-queries-count: false
```
6 changes: 6 additions & 0 deletions documentation/docs/10-statistics.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@ tags:
To have an oversight vision of your workflow, you can check out the logs.
There is, at the end, a list of statistics listing the main events that occurred during the run.

### Dry-run mode {#dry-run-mode}

This feature can be very helpful when you are not sure how the workflow will behave based on your configuration.
In such case, enable the [dry-run mode](dry-run-input) to avoid altering your repository, execute the workflow, and then analyse the statistics.

### Limited API calls {#limited-api-calls}

You can also simply limit the number of API queries calls for your [issues](issues/inputs/issue-limit-api-queries-count-input) and [pull requests](pull-requests/inputs/pull-request-limit-api-queries-count-input) to alter your repository on a reduced scope.

### Example {#example}

```
Expand Down
9 changes: 8 additions & 1 deletion documentation/documentation.iml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,12 @@
<excludeFolder url="file://$MODULE_DIR$/build" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="lodash" level="project" />
<orderEntry type="library" name="luxon" level="project" />
<orderEntry type="library" name="terminal-link" level="project" />
<orderEntry type="library" name="ts-auto-mock" level="project" />
<orderEntry type="library" name="types" level="project" />
<orderEntry type="library" name="actions" level="project" />
<orderEntry type="library" name="jest" level="project" />
</component>
</module>
</module>
2 changes: 2 additions & 0 deletions src/core/inputs/inputs.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export enum EInputs {
ISSUE_STALE_COMMENT = `issue-stale-comment`,
ISSUE_CLOSE_COMMENT = `issue-close-comment`,
ISSUE_PROCESSING = `issue-processing`,
ISSUE_LIMIT_API_QUERIES_COUNT = `issue-limit-api-queries-count`,
PULL_REQUEST_DAYS_BEFORE_CLOSE = `pull-request-days-before-close`,
PULL_REQUEST_DAYS_BEFORE_STALE = `pull-request-days-before-stale`,
PULL_REQUEST_IGNORE_ALL_ASSIGNEES = `pull-request-ignore-all-assignees`,
Expand All @@ -32,4 +33,5 @@ export enum EInputs {
PULL_REQUEST_CLOSE_COMMENT = `pull-request-close-comment`,
PULL_REQUEST_PROCESSING = `pull-request-processing`,
PULL_REQUEST_TO_DRAFT_INSTEAD_OF_STALE = `pull-request-to-draft-instead-of-stale`,
PULL_REQUEST_LIMIT_API_QUERIES_COUNT = `pull-request-limit-api-queries-count`,
}
1 change: 1 addition & 0 deletions src/core/inputs/interfaces/issues-inputs.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface IIssuesInputs extends IInputs {
readonly issueIgnoreAnyAssignees: string[];
readonly issueIgnoreAnyLabels: string[];
readonly issueIgnoreBeforeCreationDate: IIso8601Date | '';
readonly issueLimitApiQueriesCount: number;
readonly issueProcessing: boolean;
readonly issueStaleComment: IComment | '';
readonly issueStaleLabel: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface IPullRequestsInputs extends IInputs {
readonly pullRequestIgnoreAnyLabels: string[];
readonly pullRequestIgnoreBeforeCreationDate: IIso8601Date | '';
readonly pullRequestIgnoreDraft: boolean;
readonly pullRequestLimitApiQueriesCount: number;
readonly pullRequestProcessing: boolean;
readonly pullRequestStaleComment: IComment | '';
readonly pullRequestStaleLabel: string;
Expand Down
Loading