Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pascalgn/size-label-action
GitHub action to assign labels based on pull request change sizes
https://github.com/pascalgn/size-label-action
github github-action github-api hacktoberfest
Last synced: 4 days ago
JSON representation
GitHub action to assign labels based on pull request change sizes
- Host: GitHub
- URL: https://github.com/pascalgn/size-label-action
- Owner: pascalgn
- License: mit
- Created: 2019-01-27T20:17:11.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2024-12-17T06:45:05.000Z (26 days ago)
- Last Synced: 2025-01-06T23:38:22.199Z (5 days ago)
- Topics: github, github-action, github-api, hacktoberfest
- Language: JavaScript
- Homepage:
- Size: 439 KB
- Stars: 91
- Watchers: 5
- Forks: 50
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-actions - Add Labels to a PR based on Total Size of the Diff
- fucking-awesome-actions - Add Labels to a PR based on Total Size of the Diff
- awesome-workflows - Add Labels to a PR based on Total Size of the Diff
README
# size-label-action
GitHub action to assign labels based on pull request change sizes.
Labels are taken from https://github.com/kubernetes/kubernetes/labels?q=size
## Usage
Create a `.github/workflows/size-label.yml` file:
```yaml
name: size-label
on: pull_request_target
jobs:
size-label:
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: size-label
uses: "pascalgn/[email protected]"
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
```## Create the needed labels
Export both `GITHUB_TOKEN` and `REPO` (e.g. `my-username/my-repository`) and run the script below:
```bash
for size in XL XXL XS S M L; do
curl -sf -H "Authorization: Bearer $GITHUB_TOKEN" "https://api.github.com/repos/kubernetes/kubernetes/labels/size/$size" |
jq '. | { "name": .name, "color": .color, "description": .description }' |
curl -sfXPOST -d @- -H "Authorization: Bearer $GITHUB_TOKEN" https://api.github.com/repos/$REPO/labels
done
```## Configuration
The following optional environment variables are supported:
- `IGNORED`: A list of [glob expressions](http://man7.org/linux/man-pages/man7/glob.7.html)
separated by newlines. Files matching these expressions will not count when
calculating the change size of the pull request. Lines starting with `#` are
ignored and files matching lines starting with `!` are always included.
- `HTTPS_PROXY`: A proxy URL to pass to [https-proxy-agent](https://www.npmjs.com/package/https-proxy-agent)
which will be used to proxy requests to the GitHub API.You can configure the environment variables in the workflow file like this:
```yaml
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
IGNORED: ".*\n!.gitignore\nyarn.lock\ngenerated/**"
```## Custom sizes
The default sizes are:
```js
{
"0": "XS",
"10": "S",
"30": "M",
"100": "L",
"500": "XL",
"1000": "XXL"
}
```You can pass your own configuration by passing `sizes`
```yaml
name: size-label
on: pull_request_target
jobs:
size-label:
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: size-label
uses: "pascalgn/[email protected]"
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
with:
sizes: >
{
"0": "XS",
"20": "S",
"50": "M",
"200": "L",
"800": "XL",
"2000": "XXL"
}
```## Using with other actions
If creating workflow with multiple jobs, they can react on the label set by this action:
```yaml
name: size-label
on: pull_request_target
jobs:
label:
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
outputs:
label: ${{ steps.label.outputs.sizeLabel }}
steps:
- name: size-label
id: label
uses: "pascalgn/[email protected]"
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
comment:
runs-on: ubuntu-latest
needs: label
if: ${{ contains(needs.label.outputs.label, 'XL') }}
steps:
- run: echo "Too big PR"
```## License
[MIT](LICENSE)