MNT add GitHub Action to add and remove no-contribution warning#33521
MNT add GitHub Action to add and remove no-contribution warning#33521AnneBeyer wants to merge 10 commits intoscikit-learn:mainfrom
Conversation
lesteve
left a comment
There was a problem hiding this comment.
Thanks this seems super useful and not too complicated 🎉!
What is the behaviour when testing on your fork when the issue is created? Does it add the warning message or do you need to set a "Needs label"?
I would like that the warning when the issue is created. I am not 100% sure this is the case right now.
The wording may need a bit of tweaking, let's see what other people think before I jump in 😉.
| steps: | ||
| - name: Remove no-contribution warning | ||
| run: | | ||
| has_needs_label="$(gh issue view "$ISSUE_NUMBER" --json labels --jq '.labels[].name | select(startswith("Needs"))' | head -n 1)" |
There was a problem hiding this comment.
With the startsWith(github.event.label.name, 'Needs') if conditional, do we need to check again with has_needs_label?
There was a problem hiding this comment.
I think startsWith(github.event.label.name, 'Needs') only checks the label that was just removed but there may be more "Needs" labels left, so you need to check all the labels? For example you have "Needs Triage" and "Needs Reproducer" and you remove "Needs Triage", you still want the warning to be there and not remove it.
Side-comment: I think you can use github.event.issue.labels for all the labels, but I am not sure it would simplify things much compared to using the current logic with gh + jq.
There was a problem hiding this comment.
Exactly, the if condition checks that the step is only executed when a "Needs ..." label is removed, and has_needs_label checks whether there are any other "Needs ..." labels left.
There was a problem hiding this comment.
For reference, we currently have 9 labels staring with "Needs"
It is dependent on a "Needs ..." label, but since all our issues are automatically labelled "Needs Triage" when they are created, the message will be added a few seconds after they are created. Adding a condition for issue creation on top should be straight forward, though, if you think that makes more sense. |
Can you test the behaviour in your separate repo by adding a workflow that adds the label on issue creation 🙏. I seem to remember some kind of limitation that if the label is set by a workflow it will not trigger another one to prevent some kind of infinite loop e.g. See https://docs.github.com/en/actions/how-tos/write-workflows/choose-when-workflows-run/trigger-a-workflow#triggering-a-workflow-from-a-workflow or https://github.com/orgs/community/discussions/25565 for example. |
Indeed, thanks for pointing that out! I added the |
|
About the wording, I am completely fine with "not open for contribution (yet)" but in case others find it a bit harsh, here are a few alternatives I can think of:
|
|
I agree that the wording is a bit too harsh. (I just copied it from another issue and focussed on the workflow first.) I would vote for something like "not ready for a PR". It is more concise than the second point, but does not exclude contributions to the issue itself (like adding a reproducer, or whatever else might be needed.) |
|
We could also add an explicit link to the "Needs triage" section in the docs? |
You mean in the warning message, right? That seems reasonable. At the same time we should try to keep it short because otherwise are more like to skip over it. Also I would use Important this is some important things that you have to read Hmmm actually it's violet for me not red, I guess orange is better 🤷 |
|
Actually "CAUTION" is red see doc Caution now this is red and you should really pay attention Slightly prefer read for it to stand out a bit more, but not a super strong opinion on this |
|
I like the "not ready for a PR" wording suggestion. I would prefer using The other thing to carefully look at is things like |
It's a good point to keep in mind indeed that we are using user input so we need to be careful about this, plus the workflow has elevated permissions ( I also think we are fine because we quote the |
|
Between important and warning, I vote for warning. There is precedent and I feel orange may stand out a bit more than violet (super subjective opinion based on nothing much 😉). |
|
I played around with the formatting a bit and found that, when In general, I'm leaning towards checking out PyGitHub though, also after looking into all the things that could potentially go wrong 😅 but I will only manage to get to that next week. |
|
Here is the version using PyGithub. It took me a while to figure out all the details, but I learned a lot, so feel free to ping me on all future things related to GitHub Actions. 🤓 |
|
The only potential problem I see is if the author edits the issue body right after the issue was created (to fix typos or the like). Then, on saving, an error is shown that the issue could not be updated, and the changes are not saved (but they will still be present in the edit window if the issue is edited again after the warning is added). Would we be willing to risk that? We're talking about a window of 10-20 seconds here. |
|
One thing I wasn't sure is where the python script should live. Others are in:
I went for the last one, let me know if anywhere else would be preferred. |
betatim
left a comment
There was a problem hiding this comment.
LGTM
I have no strong opinion on where the put the script. From your enumeration of locations it sounds like one day we could consolidate?
Don't tell too many people about your new found GitHub Action knowledge. It is in high demand :D
| has_needs_labels = any(label.name.startswith("Needs") for label in issue.labels) | ||
| if not has_needs_labels: | ||
| if body_text.startswith(message): | ||
| new_body = body_text.removeprefix(f"{message}\n\n") |
There was a problem hiding this comment.
Whoop removeprefix being useful!
| python-version: '3.13' | ||
| - name: Install PyGithub | ||
| run: pip install -Uq PyGithub | ||
| - name: Checkout repository |
There was a problem hiding this comment.
Which commit does this checkout? My guess is that it is main because there is no commit to prefer for issues. I think this is what we want.
There was a problem hiding this comment.
From the docs:
# The branch, tag or SHA to checkout. When checking out the repository that
# triggered a workflow, this defaults to the reference or SHA for that event.
# Otherwise, uses the default branch.
So I guess it's main either way in our case.
Co-authored-by: Tim Head <betatim@gmail.com>
Reference Issues/PRs
This implements an idea from the last Monthly Developer Meeting.
What does this implement/fix? Explain your changes.
Whenever a lable starting with "Needs" is added to an issue, a warning is added on top of the issue description like this:

Once all labels starting with "Needs" are removed, the warning is also removed.
I had some help from Codex on the bash part, but refined and refactored it (a lot) and played around with this in a separate repo to make sure the warning is
@lesteve @betatim
AI usage disclosure
I used AI assistance for:
Any other comments?