-
Notifications
You must be signed in to change notification settings - Fork 421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Limit number of labels added to 100 #497
Conversation
dist/index.js
Outdated
for (const [label, globs] of labelGlobs.entries()) { | ||
core.debug(`processing ${label}`); | ||
if (checkGlobs(changedFiles, globs)) { | ||
labels.push(label); | ||
if (labels.length >= GITHUB_MAX_LABELS) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this neglects the number of labels that are already present. Say the PR has 50 labels, and we come up with 100 that we want to apply, but only 25 of those are already present. The correct result would be to add 50 new ones, 25 remain the same, and 25 would be excess. But the current code reports 100 labels with no excess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I've moved the addLabels
to happen AFTER the removeLabels
(which happens with syncLabels
enabled only) to mitigate this issue. But maybe there's a better way still, I'll check again. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me, an easy solution seems to be first getting the labels already on the issue with listLabelsOnIssue
. Then, you have all the information needed to ensure the total count remains less than 100 while tracking accurately all additions/removals that you want to do.
#### Summary GitHub does not support more than 100 labels per PR, so the PR labeler action fails when that happens. There's ongoing work to fix it, see actions/labeler#497, but I think we can ignore the action failures for now. <!--
@macksal Alright so I ended up simply using
If that makes sense I'll add unit tests! |
@macksal I've rebased my branch to resolve conflicts. Kindly let me know if it needs any more changes (other than unit tests)! |
Hello, @markmssd ! Thanks for creating the PR - we love and endorse customer contributions! Overall, your PR looks good, it definitely deals well with the scenario of trying to add more than 100 labels and with what to do with the excess. However, we would also like you to take a look at this PR and its changes. Maybe it can help you see if anything could be added and/or refactored. Furthermore, those two together could solve this issue, as the latter deals with reducing the array by filtering duplicates, but not limiting the number of labels to 100, which former takes into account. In addition to that, there's another finding that could prove to be beneficial to the solution as well and which we strongly recommend incorporating into the final application. Namely, upon some inspection on our end, we have discovered that the Action will likely keep throwing What that means is that if there are less than 48 labels present in the array, those can be sent all at once without any problems. As soon as that number is exceeded, the array should be split. We suggest splitting it in half, as this seems to be the most efficient way. However, keep in mind that, as the number of labels keep increasing (e.g. 100 labels), splitting it in half could also give us more than 48 labels to work with. As a solution to this, you could put some kind of a loop in place that could perform the action above for as long as needed (e.g. 100 gets split into 2x50, which then split to 2x25). Example of this part of the logic:
I hope I explained this clearly :) For any further clarifications, questions and suggestions, please feel free to reach out to us again and we will try to answer them as best as we can. And, of course, feel free to also add some unit tests :) Thank you for your time and contribution to our software :) |
Hello, @markmssd ! I just wanted to give you a little ping to see if there are any new updates on your end? Maybe some thoughts about my previous suggestion? Thank you in advance :) |
Hey @dusan-trickovic , thanks for the thorough explanation! I just got back from vacation and I'll need a few days before getting back to this PR. So if I understand correctly, this HTTP Server Error happens only when using the "addLabels" method, or also when using "setLabels"? If that's the case, I could also change the PR to ONLY use setLabels, and it would fix all issues. The logic would be:
(In both cases it would dedupe labels and trim to 100 max) However if the HTTP Server Error happens with setLabels too, then I'll go with your suggestion with the golden number 48, what do you think? |
@dusan-trickovic everything is done and tested, let me know what you think and if it requires some changes! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @markmssd ! Thank you again for creating this PR! I have written a few initial review points that should be addressed before continuing on. Please let us know if you have any additional questions about them, any additional suggestions or concerns :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @markmssd! Thank you for the contribution!
Looks good to me! I left a minor comment
@markmssd could you please resolve conflicts? |
.gitignore
Outdated
lib/ | ||
.vscode/ | ||
.idea/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Till the moment the IDE settings were avoided to be added to the repo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I can remove them haha, it was just getting annoying locally
src/labeler.ts
Outdated
@@ -39,23 +43,33 @@ export async function run() { | |||
configPath | |||
); | |||
|
|||
const labels: string[] = []; | |||
const labelsToRemove: string[] = []; | |||
const labels: string[] = pullRequest.labels.map(label => label.name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be it worth to create Set object at this point and avoid !labels.includes(label)
check further
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I initially tried with a Set but the code was getting really ugly, I'll try that again 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright I pushed changes that use Sets instead, let me know what you think
Conflicts have been served ✅ I also added an additional check to only call |
Hello @markmssd ! The PR looks good, we will be merging it now. Thank you very much for your contribution! :) |
Description:
Github Issues can have at most 100 labels assigned to them. This PR limits the labels being added to 100, and logs the rest as a warning.
Closes #561
Closes #562
TODO: Unit tests, will add them if the PR makes sense!Related issue:
Add link to the related issue.
Check list: