Skip to content

Commit

Permalink
pull request check (#1140)
Browse files Browse the repository at this point in the history
* Add pr-check option to validateInputs function

* Add PR check to CI workflow

* Remove assert import in get-pr.ts

* Update get-pr.ts file

* Add logSkippedBranch function for skipping branches with active pull requests

* Add new logging function and update skipped branch message

* Update logSkippedBranch function to use bold styling for branch name

* Update stale-branches action to version 4.1.0

* Remove condition for open pull requests

* Update logSkippedBranch function message

* Update getPr function documentation
  • Loading branch information
crs-k authored Mar 9, 2024
1 parent 657b23a commit 47cf5fa
Show file tree
Hide file tree
Showing 14 changed files with 4,471 additions and 4,257 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ jobs:
stale-branch-label: 'stale branch 🗑️'
compare-branches: 'info'
branches-filter-regex: '^((?!dependabot))'
pr-check: true


Build:
Expand Down
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@

# Stale Branches

Creates issues for branches that have become stale. By default it aligns with [this](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-branches-in-your-repository/viewing-branches-in-your-repository) definition, but can be configured for other use cases.
Finds and deletes stale branches. By default it aligns with [this](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-branches-in-your-repository/viewing-branches-in-your-repository) definition, but can be configured for other use cases.

When a branch has been inactive for more than the `days-before-stale` input, an issue is opened with the title `[branch-name] is STALE`. The branch will be deleted once it has been inactive longer than `days-before-delete`.
When a branch has been inactive for more than the `days-before-stale` input, it is considered stale. The branch will be deleted once it has been inactive longer than `days-before-delete`.

* By default, a stale branch is defined as a branch that:
* has had no commits in the last 120 days.
* has no protection rules.
* has no open pull requests.
* is not the default branch of the repository.
* See [inputs](https://github.com/crs-k/stale-branches#inputs) for more info.
* See [example workflow](https://github.com/crs-k/stale-branches#example-workflow).
Expand All @@ -28,7 +27,7 @@ Inputs are defined in [`action.yml`](action.yml). None are required.:
| Name | Description | Default |
| --------------- | ---- | --- |
| `repo-token` | Token used to authenticate with GitHub's API. Can be passed in using [`${{ secrets.GITHUB_TOKEN }}`](https://docs.github.com/en/actions/security-guides/automatic-token-authentication#about-the-github_token-secret). | [`${{ github.token }}`](https://docs.github.com/en/actions/learn-github-actions/contexts#github-context) |
| `days-before-stale` | Number of days a branch has been inactive before it is stale. | 120 days |
| `days-before-stale` | Number of days a branch has been inactive before it is considered stale. | 120 days |
| `days-before-delete` | Number of days a branch has been inactive before it is deleted. | 180 days |
| `comment-updates` | A comment with updated information will be added to existing issues each workflow run. | false |
| `max-issues` | This dictates the number of `stale branch 🗑️` issues that can exist. Also, the max number of branches that can be deleted per run. | 20 |
Expand All @@ -37,6 +36,7 @@ Inputs are defined in [`action.yml`](action.yml). None are required.:
| `compare-branches` | This compares each branch to the repo's default branch. <ul><li>When set to `info`, additional output describes if the current branch is ahead, behind, diverged, or identical to the default branch.<br>![image](https://user-images.githubusercontent.com/26232872/157590411-7c97806c-a509-4002-b7a5-a1e4a5da08eb.png)</li> <li>When set to `save`, this prevents branches from being deleted if they are ahead of or diverged from the default branch.</li> <li>When set to `off`, no additional calls are made.</li></ul> | off |
| `branches-filter-regex` | An optional Regex that will be used to filter branches from this action. | '' |
| `rate-limit` | If this is enabled, the action will stop if it exceeds 95% of the GitHub API rate limit. | true |
| `pr-check` | If this is enabled, the action will first check for active pull requests against the branch. If a branch has an active pr, it will not be ignored. | false |

### Outputs
Outputs are defined in [`action.yml`](action.yml):
Expand All @@ -51,6 +51,7 @@ Outputs are defined in [`action.yml`](action.yml):
* Active branches are green
* Stale branches are yellow
* Dead branches are red
* Skipped branches are blue

![image](https://user-images.githubusercontent.com/26232872/155919116-50a2ded9-2839-4957-aaa2-caa9c40c91c9.png)

Expand All @@ -76,7 +77,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Stale Branches
uses: crs-k/stale-branches@v3.0.0
uses: crs-k/stale-branches@v4.1.0
```
### With Inputs
```yaml
Expand All @@ -97,7 +98,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Stale Branches
uses: crs-k/stale-branches@v3.0.0
uses: crs-k/stale-branches@v4.1.0
with:
repo-token: '${{ secrets.GITHUB_TOKEN }}'
days-before-stale: 120
Expand All @@ -109,6 +110,7 @@ jobs:
compare-branches: 'info'
branches-filter-regex: '^((?!dependabot))'
rate-limit: false
pr-check: false


```
Expand Down
3 changes: 2 additions & 1 deletion __mocks__/@actions/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export const validInputs: Inputs = {
tagLastCommitter: true,
staleBranchLabel: 'stale branch 🗑️',
compareBranches: 'save',
rateLimit: true
rateLimit: true,
prCheck: false
}

type ListIssuesResponseDataType = GetResponseTypeFromEndpointMethod<typeof githubActual.github.rest.issues.listForRepo>
Expand Down
2 changes: 1 addition & 1 deletion __tests__/functions/get-context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ describe('Get Context Function', () => {
await validateInputs()

expect(core.getInput).toHaveBeenCalledTimes(6)
expect(core.getBooleanInput).toHaveBeenCalledTimes(3)
expect(core.getBooleanInput).toHaveBeenCalledTimes(4)
})

test('Expect Failure: - TypeError', async () => {
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ inputs:
description: 'If this is enabled, the action will stop if it exceeds 95% of the GitHub API rate limit.'
required: false
default: true
pr-check:
description: 'If this is enabled, the action will first check for active pull requests against the branch. If a branch has an active pr, it will not be ignored.'
required: false
default: false
outputs:
deleted-branches:
description: 'List of all deleted branches.'
Expand Down
Loading

0 comments on commit 47cf5fa

Please sign in to comment.