delete-github-branches
Delete GitHub Branches that match patterns.
Features
- Can define
includesBranchPatterns
- Can define
excludesBranchPatterns
- If the branch has associated Pull Requests, Does not delete the branch
- Have
dryRun
mode
Install
Install with npm:
npm install delete-github-branches
Usage: CLI
Usage
$ delete-github-branches
Options
--owner Owner name for repository: **owner**/repo
--repo Repo name for repository: owner/**repo**
--token GitHub Token. you can use als GITHUB_TOKEN env
--includesBranchPatterns includes branch patterns split by comma. Default: "/^.*$/" (all)
--excludesBranchPatterns excludes branch patterns split by comma. Default: "master,develop,dev,gh-pages"
--stalledDays Deletable days after the branch is stalled. Default: 30
--format Output formatter. Available: "markdown", "json". Default: "markdown"
--baseUrl GitHub API base Url.
--dryRun if this flag is on, run dry-run mode
--config path to config file
Examples
$ delete-github-branches --owner azu --repo delete-github-branches-test --token <TOKEN>
$ delete-github-branches --owner azu --repo delete-github-branches-test --token <TOKEN> --includesBranchPatterns "/feature\/.*/" --dryRun
Also this package includes helper cli tool.
delete-github-branches-check-branch-name
just detect if the branch name is matched patterns.
Usage
$ delete-github-branches-check-branch-name [branchName]
Options
--includesBranchPatterns includes branch patterns split by comma. Default: "/^.*$/" (all)
--excludesBranchPatterns excludes branch patterns split by comma. Default: "master,develop,dev,gh-pages"
--config path to config file
Examples
$ delete-github-branches-check-branch-name "feature/009"
$ echo $? # 0
# It will be alive and exit code: 0
$ delete-github-branches-check-branch-name "patch-101"
$ echo $? # 1
# It will be deleted and exit code: 1
Config File
Config file is following JSON format.
All property is optional and its can be combined with command line flags.
{
owner?: string;
repo?: string;
includesBranchPatterns?: string[];
excludesBranchPatterns?: string[];
stalledDays?: number;
baseUrl?: string;
token?: string;
dryRun?: boolean;
}
For example, delete-github-branches.json
is following config.
delete-github-branches.json
:
{
"includesBranchPatterns": ["/^.*$/"],
"excludesBranchPatterns": ["master", "develop", "dev", "gh-pages", "/^feature\/.*$/"]
}
And you can pass other options as command line flags
$ GITHUB_TOKEN=$GH_TOKEN delete-github-branches --owner azu --repo delete-github-branches-test --config ./delete-github-branches.json
Usage: Library
(async () => {
const results = await deleteGitHubBranches({
owner: "azu",
repo: "delete-github-branches-test",
excludesBranchPatterns: ["master", "develop", "/feature/.*/"],
token: process.env.token!,
dryRun: true
});
assert.deepStrictEqual(results, [
{ branchName: "develop", deleted: false, reason: "It is ignored by includes/excludes patterns" },
{ branchName: "feature/a", deleted: false, reason: "It is ignored by includes/excludes patterns" },
{ branchName: "feature/b", deleted: false, reason: "It is ignored by includes/excludes patterns" },
{ branchName: "master", deleted: false, reason: "It is ignored by includes/excludes patterns" },
{ branchName: "will-be-deleted", deleted: true }
]);
})()
Changelog
See Releases page.
Running tests
Add .env
with token
GITHUB_TOKEN=XXXX
Run tests
npm test
Contributing
Pull requests and stars are always welcome.
For bugs and feature requests, please create an issue.
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
Author
License
MIT © azu