Skip to content

Commit

Permalink
Merge pull request #5 from fpicalausa/ignore-unknown-authors
Browse files Browse the repository at this point in the history
Ignore unknown authors
  • Loading branch information
fpicalausa authored Jan 7, 2024
2 parents 6dba543 + d961595 commit bfaf2b7
Show file tree
Hide file tree
Showing 14 changed files with 4,843 additions and 4,600 deletions.
37 changes: 23 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@ Without setting `dry_run: true`, this action will remove branches. Consider sett

## Inputs

| Input | Defaults | Description |
|-----------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `github-token` | `${{ secrets.GITHUB_TOKEN }}` | PAT for GitHub API authentication. |
| `dry-run` | `false` | Flag that prevents this action from doing any modification to the repository. |
| `exempt-organization` | (not set) | Name of a Github organization. Branches for which the latest commiter belongs to this organization will be exempt from cleanup. |
| `exempt-branches-regex` | `^(main\|master)$` | Regular expression defining branches name that are exempt from cleanup. |
| `exempt-authors-regex` | (not set) | Regular expression defining authors who are exempt from cleanup. |
| `exempt-protected-branches` | true | Whether protected branches are exempted |
| `stale-branch-message` | `@{author} Your branch [{branchName}]({branchUrl}) hasn't been updated in the last 60 days and is marked as stale. It will be removed in a week.\r\nIf you want to keep this branch around, delete this comment or add new commits to this branch.` | Template for commit comments notifying the author that their branch will be removed. |
| `days-before-branch-stale` | 90 | Number of days since the last commit before a branch is considered stale. Once stale, this action will leave a comment on the last commit, marking the branch as stale. |
| `days-before-branch-delete` | 7 | Number of days before a stale branch is removed. Set to 0 to remove immediately. |
| `operations-per-run` | 10 | Maximum number of stale branches to look at in any run of this action. |
| Input | Defaults | Description |
|-----------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `github-token` | `${{ secrets.GITHUB_TOKEN }}` | PAT for GitHub API authentication. |
| `dry-run` | `false` | Flag that prevents this action from doing any modification to the repository. |
| `exempt-organization` | (not set) | Name of a Github organization. Branches for which the latest commiter belongs to this organization will be exempt from cleanup. |
| `exempt-branches-regex` | `^(main\|master)$` | Regular expression defining branches name that are exempt from cleanup. |
| `exempt-authors-regex` | (not set) | Regular expression defining authors who are exempt from cleanup. |
| `exempt-protected-branches` | `true` | Whether protected branches are exempted |
| `stale-branch-message` | `@{author} Your branch [{branchName}]({branchUrl}) hasn't been updated in the last 60 days and is marked as stale. It will be removed in a week.\r\nIf you want to keep this branch around, delete this comment or add new commits to this branch.` | Template for commit comments notifying the author that their branch will be removed. |
| `days-before-branch-stale` | `90` | Number of days since the last commit before a branch is considered stale. Once stale, this action will leave a comment on the last commit, marking the branch as stale. |
| `days-before-branch-delete` | `7` | Number of days before a stale branch is removed. Set to 0 to remove immediately. |
| `operations-per-run` | `10` | Maximum number of stale branches to look at in any run of this action. |
| `ignore-unknown-authors` | `false` | Whether to abort early when a commit author cannot be identified. By default, stop early since this may indicate that the token used to run the action doesn't have the right privileges. Set to true and define a default recipient instead if not a concern. |
| `default-recipient` | (not set) | When `ignore-unknown-authors` is `true`, use this login as the author to notify when the branch becomes stale. |

## Example usage

Expand Down Expand Up @@ -86,6 +88,13 @@ This action notifies users through a commit comment. There are pros and cons to
To start, install dependencies with `npm install`. The source files live under `src`.

You can run the tool locally with `ts-node src/cli.ts` 🖥️
You can run the tool locally by:
1. Set `GITHUB_TOKEN` in a .env file with a PAT with correct access
2. Edit `src/cli.ts` as needed to poin to the correct repo
3. Run `src/cli.ts` under `ts-node` as follows:

To deploy you changes, start a PR. Don't forget to run `npm build` and include changes to the `dist` dir in your commit.
```shell
source .env && npx ts-node src/cli.ts
```

To deploy you changes, start a PR. Don't forget to run `npm run build` and include changes to the `dist` dir in your commit.
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,11 @@ inputs:
description: "Maximum number of stale branches to look at in any run of this action."
default: "10"
required: false
ignore-unknown-authors:
description: "Whether to abort early when a commit author cannot be identified. By default, stop early since this may indicate that the token used to run the action doesn't have the right privileges. Set to true and define a default recipient instead if not a concern."
default: "false"
required: false
default-recipient:
description: "A string corresponding to the username to be tagged on stale branches from unknown authors"
default: ""
required: false
2 changes: 1 addition & 1 deletion dist/commitComments.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export declare class TaggedCommitComments {
private readonly octokit;
private readonly headers;
constructor(repo: Repo, octokit: Octokit, headers: any);
static formatCommentMessage(messageTemplate: string, branch: Branch, config: Pick<Params, "daysBeforeBranchStale" | "daysBeforeBranchDelete">, repo: Repo): string;
static formatCommentMessage(messageTemplate: string, branch: Branch, config: Pick<Params, "daysBeforeBranchStale" | "daysBeforeBranchDelete" | "defaultRecipient">, repo: Repo): string;
getCommitCommentsWithTag({ commentTag, commitSHA, }: Commit & CommentTag): Promise<{
html_url: string;
url: string;
Expand Down
Loading

0 comments on commit bfaf2b7

Please sign in to comment.