codelytv / pr-size-labeler Goto Github PK
View Code? Open in Web Editor NEW๐ท Visualize and optionally limit the size of your Pull Requests
Home Page: https://github.com/marketplace/actions/pull-request-size-labeler
License: MIT License
๐ท Visualize and optionally limit the size of your Pull Requests
Home Page: https://github.com/marketplace/actions/pull-request-size-labeler
License: MIT License
The PR isn't labeled and I can see the next message in logs:
{
"message": "Validation Failed",
"errors": [
{
"resource": "Label",
"field": "name",
"code": "missing_field"
}
],
"documentation_url": "https://developer.github.com/v3/issues/#edit-an-issue"
}
Hi, I'm looking for an app or action to label pull requests with a size based on LOC. This action looks perfect, but another similar action I tried did not work on PRs created from forks (which is the majority of PRs in our project). Can you confirm if this action will work on PRs from forks?
So I'm not sure if this is a bug or this is me just not understanding how to work the yaml file but...
I have a codebase I just pushed a small PR to and it got flagged as being over 1000 lines by the pr-size-labeler
Code changes: 5 files, 235 lines
Snapshot changes: 3 files, 2358 lines
The labeler should be ignoring the snapshot files but doesn't appear to be.
I've tried both styles of config:
files_to_ignore: "*.snap *.lock"
and
files_to_ignore: |
"*.snap"
"*.lock"
Is it something I'm doing incorrectly? Would it have an issue with deeply nested filenames? EG:
/components/Footer/__snapshots__/index.test.tsx.snap
Sorry for the noise if I'm doing something wrong!
I removed the default size/xs
level, and my config rule starts from S
. But it still gives the size/xs
to PR
workflow: https://github.com/GreptimeTeam/greptimedb/actions/runs/6584684983/job/17889694460?pr=2631
action output:
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Total modifications (additions + deletions): 7
Ignoring files (if present): Cargo.lock
Labeling pull request with size/xs
Final labels: "size/xs"
config file:
name: size-labeler
on: [pull_request]
jobs:
labeler:
runs-on: ubuntu-latest
name: Label the PR size
steps:
- uses: codelytv/pr-size-labeler@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
s_label: 'Size: S'
s_max_size: '100'
m_label: 'Size: M'
m_max_size: '500'
l_label: 'Size: L'
l_max_size: '1000'
xl_label: 'Size: XL'
fail_if_xl: 'false'
message_if_xl: >
This PR exceeds the recommended size of 1000 lines.
Please make sure you are NOT addressing multiple issues with one PR.
Note this PR might be rejected due to its size.
github_api_url: 'api.github.com'
files_to_ignore: 'Cargo.lock'
Is it possible to ignore files and folders by patterns?
For example, ignoring snapshots directories, ignoring JSON fixtures directories, ignoring some test folders.
Sometimes a change may be a few lines of code, however, the test itself could generate more than the limits defined.
The idea is simple:
Apart from the message for a PR that is too big, it should also be able to supply some messages according to the actual size of the PR.
For example, to help developers more accurately, it could post as a comment the current guidelines to the size; i.e. small changes only require 1 reviewer, bigger ones up to 3.
so deletions do not count for total size?
Hi!
First of all, thank you for this action!
So here is our issue, it seems like the label isn't applied anymore. Here you can find the logs:
2022-05-17T13:12:19.8359002Z /src/github.sh: line 15: null: unbound variable
2022-05-17T13:12:19.8361467Z Total modifications (additions + deletions):
2022-05-17T13:12:19.8362674Z Ignoring files (if present):
2022-05-17T13:12:19.8372382Z /src/labeler.sh: line 49: [: : integer expression expected
2022-05-17T13:12:19.8372724Z /src/labeler.sh: line 51: [: : integer expression expected
2022-05-17T13:12:19.8373037Z /src/labeler.sh: line 53: [: : integer expression expected
2022-05-17T13:12:19.8373339Z /src/labeler.sh: line 55: [: : integer expression expected
2022-05-17T13:12:19.8375026Z Labeling pull request with size/xl
2022-05-17T13:12:20.1232720Z jq: error (at <stdin>:1): Cannot iterate over null (null)
2022-05-17T13:12:20.1255564Z Final labels: "size/xl"
2022-05-17T13:12:20.6126579Z {
2022-05-17T13:12:20.6127218Z "message": "Not Found",
2022-05-17T13:12:20.6128176Z "documentation_url": "https://docs.github.com/rest/reference/issues#create-an-issue-comment"
2022-05-17T13:12:20.6128657Z }
2022-05-17T13:12:20.7627548Z Cleaning up orphan processes
This is the dev workflow we have enabled:
name: Size Labeler
on: [pull_request]
jobs:
labeler:
runs-on: ubuntu-latest
name: Label the PR size
steps:
- uses: codelytv/pr-size-labeler@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
xs_max_size: '10'
s_max_size: '100'
m_max_size: '500'
l_max_size: '1000'
fail_if_xl: 'false'
message_if_xl: >
'This PR exceeds the recommended size of 1000 lines.
Please make sure you are NOT addressing multiple issues with one PR.
Note this PR might be rejected due to its size.โ
github_api_url: 'api.github.com'
Can someone have a look at this?
This my pr action link, sukkiCat/test#1, no error logs, but labels are not added.
Asking this because I basically want the PR size label on my PRs but what I don't want is to see the message as the team knows there's gonna be big PRs every now and then.
Not sure if returning an empty string would just not display it but would love to know a workaround for this ๐
Hi!
First of all, thank you for this action!
So here is our issue, it seems like the label isn't applied anymore. Here you can find the logs:
2022-04-26T20:28:48.7798250Z Total modifications (additions + deletions): 1973
2022-04-26T20:28:48.7799291Z Ignoring files (if present):
2022-04-26T20:28:48.7809902Z Labeling pull request with size: XL
2022-04-26T20:28:49.1872778Z Final labels: "size: XL"
2022-04-26T20:28:49.8593456Z {
2022-04-26T20:28:49.8594306Z "message": "Invalid request.\n\nFor 'links/0/schema', nil is not an object.",
2022-04-26T20:28:49.8595189Z "documentation_url": "https://docs.github.com/rest/reference/issues#create-an-issue-comment"
2022-04-26T20:28:49.8595980Z }
Here is our call to the action:
name: Dev tools workflow
on:
pull_request:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
determine_pr_size:
name: Determine the size of the PR
runs-on: ubuntu-latest
steps:
- uses: codelytv/pr-size-labeler@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
xs_label: 'size: XS'
xs_max_size: '30'
s_label: 'size: S'
s_max_size: '100'
m_label: 'size: M'
m_max_size: '500'
l_label: 'size: L'
l_max_size: '1000'
xl_label: 'size: XL'
fail_if_xl: 'false'
message_if_xl: >
'This PR exceeds the recommended size of 1000 lines.
Please make sure you are NOT addressing multiple issues with one PR.
Note this PR might be rejected due to its size.โ
github_api_url: 'api.github.com'
Thank you in advance and don't hesitate if you need anything else.
I used this labeler in another company of mine years ago. It's a nice GH action which encourages smaller PRs, which leads to faster PR reviews, which leads to faster product velocity IMHO.
However, it seems like this project is not maintained anymore and there are a number of open, yet very fixable issues, including:
Additionally, during my recent attempts to set up the labeler on a project, I encountered several operational quirks, such as unreported errors leading to unlabelled PRs, which suggests issues are silently failing.
While I want to fork and maintain a new version of this repository, I will only do so if there are people that would consider it worth while for their teams and their projects.
For a bit of background, I've contributed to open source and have one other project I'm maintaining right now, Robin AI, which is another lightweight github action (58 stars). It also got some press: https://www.globenewswire.com/en/news-release/2023/06/22/2693172/0/en/New-Open-Source-Project-Uses-Artificial-Intelligence-to-Improve-Software-Code.html
That's it. React if you want to see this project pushed forward ๐๐ป
Currently the size of a PR is determined by the amount of changes (Deletion+ Modification)
In my perception, I take on on a PR which has 120 changes in a single file much easier, as on a PR which has 120 changes across 30 files. In other words, the complexity is more interesting as the size only.
By taking a file weight into account (1 file = x changes) the labels would effectively show the complexity of the pr.
Lines 15 to 33 in 48a746c
From my biased perspective, as the author, NGS is better fit for this tool. Please consider. Sample, untested, translation of the referenced code follows:
F add_label_to_pr(pr_number, label_to_add) {
info = ``curl -sSL -H "Authorization: token $GITHUB_TOKEN" -H $GITHUB_API_HEADER "$GITHUB_API_URI/repos/$GITHUB_REPOSITORY/pulls/$pr_number"``
# info is now data structure, the JSON is parsed by ``...`` expression
labels = info.labels.name.flatten().reject(Pfx('size/')) + [label_to_add]
labels_arg = {'labels': labels}.encode_json() # proper handling of all escaping etc
log("Final labels: ${labels}") # log() is language built in
$(curl -sSL -H "Authorization: token $GITHUB_TOKEN" -H $GITHUB_API_HEADER -X PATCH -H "Content-Type: application/json" -d $labels_arg "$GITHUB_API_URI/repos/$GITHUB_REPOSITORY/issues/$pr_number")
}
$GITHUB_API_HEADER
is intentionally not inside double quotes, it is passed as exactly one argument, as is.
When a PR is updated with a commit and the number of modified lines changes, the GHAction applies the label to the PR, however it does not remove the old label and adds the new label of the corresponding size.
Actually the action is quite simple:
on:
pull_request:
jobs:
tag_pr_size:
runs-on: ubuntu-latest
name: Label the PR size
steps:
- uses: codelytv/pr-size-labeler@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
xs_max_size: '10'
s_max_size: '30'
m_max_size: '100'
l_max_size: '500'
message_if_xl: >
'This PR exceeds the recommended size of 500 lines.
Please make sure you are NOT addressing multiple issues with one PR.โ
Examples:
Thanks for the work!
Line 3 in 417e60a
Are you around and would accept a PR?
It took me a bit of time to figure out which permissions this actions needs.
In my case, adding the following worked. Maybe that should be added to the README.
jobs:
labeler:
...
permissions:
issues: write
pull-requests: write
steps:
...
By default, GitHub and its variants include an GITHUB_API_URL
environment variable, so the addition of github_api_url
just increased code complexity, reduced maintainability, and actually reduced flexibility since it assumes https://
. The latter meant I was not able to simply pass in $GITHUB_API_URL
, because it became an invalid url (e.g., https://https://my-enterprise.url.com/api/v3
).
I get several failures and the label is not assigned:
Usage: basename FILE [SUFFIX]
Strip directory path and .SUFFIX from FILE
parse error: Invalid numeric literal at line 1, column 4
/src/github.sh: line 29: ((: changes += : syntax error: operand expected (error token is "+= ")
parse error: Invalid numeric literal at line 1, column 6
BusyBox v1.34.1 (2022-07-19 20:11:24 UTC) multi-call binary.
Usage: basename FILE [SUFFIX]
Strip directory path and .SUFFIX from FILE
parse error: Invalid numeric literal at line 1, column 6
/src/github.sh: line 29: ((: changes += : syntax error: operand expected (error token is "+= ")
Total modifications (additions + deletions): 0
Ignoring files (if present): "pkg/generated/*""docs/*""database/mock/store.go""go.mod""go.sum"
Labeling pull request with size/xs
jq: error (at <stdin>:1): Cannot iterate over null (null)
Final labels: "size/xs"
It would be great if user's could include a regular expression for the files_to_ignore
parameter. For example if you wanted to exlclude test classes from the size counting you could add something like this...
files_to_ignore: '*Test*'
Title says all, indent changes have usually very little relevance to complexity.
Dear @rgomezcasas
thanks for testing, refactoring and merging my feature pr #33 (based on issue #9) ๐
But I do think that one of your changes might have added a very subtle bug.
See this code in main:
Lines 19 to 27 in 88ab4d8
compared to my original version:
local changes=0
for file in $(echo "$body" | jq -r '.[] | @base64'); do
_jq() {
echo "$file" | base64 -d | jq -r "$1"
}
local ignore_file=0 # False
for file_to_ignore in $files_to_ignore; do
if [ "$file_to_ignore" = "$(basename $(_jq '.filename'))" ]; then
ignore_file=1 # True
fi
done
if [ $ignore_file -eq 0 ]; then
((changes += $(_jq '.changes')))
fi
done
The difference I want to point at is on line 22:
Line 22 in 88ab4d8
Does this work for files_to_ignore
lists with more than one filename?
Let's say that files_to_ignore
= 'Pipfile.lock package-lock.json'
and you change your package-lock.json
.
Pipfile.lock
!= package-lock.json
?That's why you will have to loop over all filenames all the time.
Note ๐ I haven't tested this, just compared your code to mine and this seemed like a real logical difference.
If you can confirm this, let's do a v1.8.1
asap ๐
whenever i push it repeats it. really annoying as i keep getting notifications for nothing.
I've noticed that the label it's not being added for every pull request. The latest pull request where the label was not added had two labels with spaces in it. May not be related though. Any idea what could be the problem?
Thanks in advance
Hi there! ๐ We would love the ability to customize the size labels that get applied. In our use case, it is to match previously existing capitalized labels (e.g. size/XS
) and associated workflows with those.
Add new configuration options with defaults matching the existing label names:
inputs:
# ...
xs_label:
description: 'Label for xs PR'
required: false
default: 'size/xs'
s_label:
description: 'Label for s PR'
required: false
default: 'size/s'
m_label:
description: 'Label for m PR'
required: false
default: 'size/m'
l_label:
description: 'Label for l PR'
required: false
default: 'size/l'
# ...
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.GITHUB_TOKEN }}
- ${{ inputs.xs_label }}
- ${{ inputs.xs_max_size }}
- ${{ inputs.s_label }}
- ${{ inputs.s_max_size }}
- ${{ inputs.m_label }}
- ${{ inputs.m_max_size }}
- ${{ inputs.l_label }}
- ${{ inputs.l_max_size }}
- ${{ inputs.fail_if_xl }}
- ${{ inputs.message_if_xl }}
- ${{ inputs.github_api_url }}
And adjusting hardcoded size/
references in the code.
Howdy,
I would be nice to have an ability to set a custom label color.
Could be either for all labels as one option or per each.
All the best
I'm using the labeler to my company's code, and it is very useful.
By the way, when PR is made, the user who added this github action to workflow is working as labeler.
I wonder if it is possible to add github bot and assign it as a labeler, so that the other user may not be involved in the PR.
Line 19 in 48a746c
$1
is used instead of pr_number
Is it the message optional? Should be great it can be optional and avoid add a comment on every push to the PR branch, I think one comment is enough.
Please, release a new version v1.8.2 that includes d269449310fe33526c56b2dfe6244e3a9f489b15 available in main
.
Thank you for the such an useful tool!
We have implemented it in mdn/content
. In this PR only files were deleted, we use a custom command to deletions so there was almost no effort reviewing the PR.
But the PR got the biggest size label size/xl
. Is is possible to ignore lines from deleted files?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.