Giter Site home page Giter Site logo

codelytv / pr-size-labeler Goto Github PK

View Code? Open in Web Editor NEW
313.0 5.0 52.0 88 KB

๐Ÿท Visualize and optionally limit the size of your Pull Requests

Home Page: https://github.com/marketplace/actions/pull-request-size-labeler

License: MIT License

Dockerfile 4.41% Shell 95.59%
github-actions github-action pull-requests action automation github pull-request-action pull-request-management pull-request codely

pr-size-labeler's People

Contributors

bflad avatar bhean avatar fty4 avatar javiercane avatar johnlk avatar khru avatar kooku0 avatar lionseal avatar mambax avatar mikybars avatar rgomezcasas avatar rjlopezdev avatar wu-cl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pr-size-labeler's Issues

Validation failed

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"
}

Error editing the issue

After to configure the action I realize some times I have this error:

Captura de pantalla 2020-05-05 a las 12 10 55

I don't know why some times this is working well and other no, I didn't find any difference between PRs

Question: Does this action work with pull requests from forks?

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?

files_to_ignore

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!

Labeling nonexist size level `size/xs`

Desc

I removed the default size/xs level, and my config rule starts from S. But it still gives the size/xs to PR

Info

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'

Ignore files and folders by pattern?

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.

Allow messages per size definition

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.

PR size labeler is not working

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?

Possible to not pass message_if_xl?

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 ๐Ÿ™

Not working anymore

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.

Proposal to Revive and Maintain Pr-Size-Labeler: Seeking Community Input

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:

  • Broken files to ignore option (Issue #67)
  • GitHub API config value not working (Issue #27)
  • Ignoring deleted line diffs option (Issue #66)

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 ๐Ÿ™๐Ÿป

Also include amount of changed files to the calculation to show complexity instead of size only

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.

Please consider NGS

github::add_label_to_pr() {
local -r pr_number=$1
local -r label_to_add=$2
local -r body=$(curl -sSL -H "Authorization: token $GITHUB_TOKEN" -H "$GITHUB_API_HEADER" "$GITHUB_API_URI/repos/$GITHUB_REPOSITORY/pulls/$1")
local labels=$(echo "$body" | jq .labels | jq -r ".[] | .name" | grep -v "size/")
labels=$(printf "%s\n%s" "$labels" "$label_to_add")
local -r comma_separated_labels=$(github::format_labels "$labels")
log::message "Final labels: $comma_separated_labels"
curl -sSL \
-H "Authorization: token $GITHUB_TOKEN" \
-H "$GITHUB_API_HEADER" \
-X PATCH \
-H "Content-Type: application/json" \
-d "{\"labels\":[$comma_separated_labels]}" \
"$GITHUB_API_URI/repos/$GITHUB_REPOSITORY/issues/$pr_number"
}

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.

Duplicated labels when PR is updated

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:

name: Label PR Size
Captura de pantalla 2021-10-19 a las 16 08 39

Captura de pantalla 2021-10-19 a las 16 09 04

Thanks for the work!

Document required permissions

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:
      ...

Github API url is not necessary

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).

Action fails: parse error: Invalid numeric literal at line 1, column 6

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"

Subtle bug ๐Ÿ”ฅ in support for ignoring files !?

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:

local changes=0
for file in $(echo "$body" | jq -r '.[] | @base64'); do
for file_to_ignore in $files_to_ignore; do
if [ "$file_to_ignore" != "$(basename $(jq::base64 '.filename'))" ]; then
total_changes=$(jq::base64 '.changes')
((changes += total_changes))
fi
done
done

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:

if [ "$file_to_ignore" != "$(basename $(jq::base64 '.filename'))" ]; then

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.

  1. Your code would check if Pipfile.lock != package-lock.json ?
  2. Yes, it is! Count the changes! ~> Err, that's not what we want ๐Ÿ”ฅ

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 ๐Ÿš€

Label is not added for all pull requests

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

Size Label Customization

Description

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.

Proposal

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.

Ability to set label color

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

Is it possible to make github bot as labeler?

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.

Optional parameters and message

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.

Is it possible to ignore line count from deleted files?

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.