Giter VIP home page Giter VIP logo

Comments (15)

dowrow avatar dowrow commented on July 29, 2024 4

I'm really interested in this. What would be the best way to implement it?
I've been checking the github::calculate_total_modifications() method and the Github API docs and the only approach I found would be:

  • Allow a 8th argument to be passed to the action (ignore_files), which would be a string with the comma-separated files to ignore.
  • Inside calculate_total_modifications() define a variable totalLines = deteledLines + addedLines (current returned value)
  • Loop over every file in the PR (using this endpoint GET /repos/:owner/:repo/pulls/:pull_number/files) and check if the filename matches one of the ignored_files. If it does, substract its (deletedLines + addedLines) from the totalLines.

Does this make sense? Am I missing anything?

from pr-size-labeler.

ddalpange avatar ddalpange commented on July 29, 2024 4

Thanks this project.

is there anything working on this issue?

If nobody solving it, I will contribute to solve this issue .

@JavierCane @rgomezcasas

from pr-size-labeler.

favmd avatar favmd commented on July 29, 2024 3

@szamanr I opened PR #33 👍

from pr-size-labeler.

favmd avatar favmd commented on July 29, 2024 1

Dear @kevindice @dowrow @JavierCane et al.

I've been using the pr-size-labeler workflow for quite a while now (it's simple yet super helpful!), so I gave this issue a try: Have a look at this one commit from my forked repo: favmd@992a73a

The code basically does what has been described above:

  • Allow a whitespace(!)-separated list of files to be ignored (files_to_ignore)
  • If files_to_ignore is empty, the old code will be used (see below for the rationale behind this!)
  • If files_to_ignore is given, it will loop through the list of files and count the changes

Plus: Minor modifications:

  • Add missing message_if_xl parameter description to README.md
  • Fix issue #29

Note however that my code does have its LIMITATIONS and should be tested by someone else too:

  • Filenames with whitespaces are not supported (never saw that in auto-generated filenames anyway...)
  • files_to_ignore is global (as described above), i.e., filenames will be ignored in every part of the repo
  • Only the first 100 files are taken into account ❗ (note that the Pulls API endpoint GET /repos/{owner}/{repo}/pulls/{pull_number}/files is paginated and limited to 3000 files max (100 files max per page))

I can live with that limitation due to the fact that we don't open PRs with hundreds of changed files, but this is the reason why my code will fall back to the old code if files_to_ignore is empty: to ensure that someone not using the new parameter does not have this limitation at all and falls back to the API endpoint without /files at the end.

P.S. Dear @magnattic: Your approach did not work for me, but maybe I just missed some little detail.

from pr-size-labeler.

JavierCane avatar JavierCane commented on July 29, 2024

It would be awesome to support this 🙌

@dowrow, your approach seems to completely make sense 🙂

The only thing I would suggest would be using a YAML sequence instead of a comma separated string for specifying the different files to ignore. That is, being able to specify it as files_to_ignore: ['package-lock.json', 'composer.lock'] instead of files_to_ignore: 'package-lock.json, composer.lock'.

Example of how the README.md complete example would look like:

name: 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 is so big! Please, split it 😊'
          files_to_ignore: ['package-lock.json', 'composer.lock']

What do you think?

from pr-size-labeler.

dowrow avatar dowrow commented on July 29, 2024

Hey @ddalpange, that would be great! I can't really move forward with this issue at the moment.

from pr-size-labeler.

mrchief avatar mrchief commented on July 29, 2024

@rgomezcasas @dowrow what about this commit? Seems like it does what is being described here: martincleto@7fc2823

from pr-size-labeler.

mharris717 avatar mharris717 commented on July 29, 2024

@mrchief does it? It looks like it adds the argument, but doesn't actually use it

from pr-size-labeler.

mrchief avatar mrchief commented on July 29, 2024

@mharris717 you're right - seems like it goes all the way except ignoring actual changes.

from pr-size-labeler.

magnattic avatar magnattic commented on July 29, 2024

Wouldn't the correct solution be to mark those files in the .gitattributes file so they count towards the lines changed in Github?

I haven't tested this yet myself but that seems to be exactly what the linguist-generated flag is for:
https://github.com/github/linguist/blob/master/docs/overrides.md#generated-code

So for the example given just add a .gitattributes file with

package-lock.json linguist-generated=true

to your repo and hopefully those line changes are then ignored in the labeller as well?

from pr-size-labeler.

magnattic avatar magnattic commented on July 29, 2024

@favmd You are right, after testing this myself I think the approach does not work as expected, unfortunately. The lines are still counted by github even if the file is marked as linguist-generated=true.

Maybe that's also an issue we could raise with github, I feel like those should be excluded from the diff altogether.

EDIT:
ℹī¸ I opened an issue with Github, please support it by upvoting! community/community#12343

from pr-size-labeler.

magnattic avatar magnattic commented on July 29, 2024

Regarding this feature request: It would be awesome if files_to_ignore would support glob patterns, so the syntax would be in line with e.g. .gitignore.

from pr-size-labeler.

favmd avatar favmd commented on July 29, 2024

Dear @magnattic Upvoted your discussion! Let's see where this leads.

You are right: From the docs I would have expected your approach to work just fine.

Regarding this feature request: It would be awesome if files_to_ignore would support glob patterns, so the syntax would be in line with e.g. .gitignore.

That's way more than I need, but a wonderful idea (maybe for another Issue/PR if this one gets approved?).

Feel free to fork and improve my approach :)

from pr-size-labeler.

szamanr avatar szamanr commented on July 29, 2024

@favmd nice, thanks for working on that. this seems ready for review, could you open a pull request? not sure if the repo maintainers will see it otherwise.

from pr-size-labeler.

rgomezcasas avatar rgomezcasas commented on July 29, 2024

Feature implemented thanks to @favmd 🎉

You can see how to use it in the documentation.

Thanks!

from pr-size-labeler.

Related Issues (20)

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.