Skip to content

Conversation

soehms
Copy link
Member

@soehms soehms commented Sep 17, 2025

This PR fixes #40758.

The action https://github.com/sagemath/sage/blob/develop/.github/sync_labels.py should not change "needs work" (maybe "needs info" too, but we don't use that as much so I'm not sure if it has different behaviour currently) to "needs review" when the commit message matches the default message for a merge commit.
Alternatives Considered

This is achieved by ignoring merge commits when the latest commit date is determined in case a s: needs_work label exists. Since s: needs_work persists if there is a more recent review requesting changes this should solve the problem.

Merging develop should still trigger a new CI run. I don't imagine that this change would effect that though.

This remains unchanged.

Check whether merging from the command line with git and merging from the GitHub web interface generate the same default merge commit messages.

In both cases, the predefined message begins with Merge and contains the word develop. I just check that this is valid. However, note that the user (at least in the in the command line) has the option of changing the messages. Therefore, we generally cannot detect merge commits exactly.

This PR also implements a new method test_method just for test purposes. This allows to run arbitrary methods of the class from the command line.

📝 Checklist

  • The title is concise and informative.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation and checked the documentation preview.

⌛ Dependencies

@soehms soehms added the github_actions Pull requests that update GitHub Actions code label Sep 17, 2025
@soehms
Copy link
Member Author

soehms commented Sep 17, 2025

Testcase

As a first testcase I use #39881, since this has two merge commits and s: needs_work label set.

pr39881-labels

Since one of the merge commits (1d726b686c97eea0b4ad3bffe3e365ed9c7926f7) is the last commit ({'authoredDate': '2025-04-05T08:03:07Z') the self._commit_date should be set to an earlier date with the fix.

pr39881-commits

Using the new test_method one gets:

sage$ python .github/sync_labels.py https://github.com/sagemath/sage/pull/39881 soehms get_commits {} -t
INFO:root:cmdline_args (4) ['https://github.com/sagemath/sage/pull/39881', 'soehms', 'get_commits', '{}']
...
DEBUG:root:call get_commits with args () and kwds {}
DEBUG:root:================================================================================
DEBUG:root:Execute command: gh pr view https://github.com/sagemath/sage/pull/39881 --json commits
DEBUG:root:Execute command: gh pr view https://github.com/sagemath/sage/pull/39881 --json labels
INFO:root:List of labels for pull request #39881: ['s: needs work', 'c: finite rings']

DEBUG:root:Ignore merge commit 0c56dbebf51d6603b00b4a064944c26ae930462c for commit_date
DEBUG:root:Ignore merge commit 1d726b686c97eea0b4ad3bffe3e365ed9c7926f7 for commit_date

INFO:root:Commits until 2025-04-05T07:59:06Z for pull request #39881: [{'authoredDate': '2025-03-27T22:39:59Z', 'authors': [{'email': '[email protected]', 'id': '', 'login': '', 'name': 'Release Manager'}], 'committedDate': '2025-03-27T22:39:59Z', 'messageBody': '', 'messageHeadline': 'Updated SageMath version to 10.6.rc1', 'oid': '8a8453f35f3850c74d151a9f1c41778aac1f9e88'}, {'authoredDate': '2025-04-01T07:30:34Z', 'authors': [{'email': '[email protected]', 'id': '', 'login': '', 'name': 'Xavier Caruso'}], 'committedDate': '2025-04-01T07:30:34Z', 'messageBody': '', 'messageHeadline': "Merge branch 'develop' of https://github.com/sagemath/sage into develop", 'oid': '0c56dbebf51d6603b00b4a064944c26ae930462c'}, {'authoredDate': '2025-04-04T18:16:08Z', 'authors': [{'email': '[email protected]', 'id': '', 'login': '', 'name': 'Xavier Caruso'}], 'committedDate': '2025-04-04T18:16:46Z', 'messageBody': '', 'messageHeadline': 'improve Frobenius endomorphisms over extensions of finite fields', 'oid': '52b8e19639f7dc03bed605b7528239a9433c540c'}, {'authoredDate': '2025-04-05T06:31:33Z', 'authors': [{'email': '[email protected]', 'id': '', 'login': '', 'name': 'Xavier Caruso'}], 'committedDate': '2025-04-05T07:33:28Z', 'messageBody': '', 'messageHeadline': 'check finite field in the category', 'oid': '26ff7f192c4905747002aec87f2600abb59015ed'}, {'authoredDate': '2025-04-05T07:59:06Z', 'authors': [{'email': '[email protected]', 'id': '', 'login': '', 'name': 'Xavier Caruso'}], 'committedDate': '2025-04-05T07:59:06Z', 'messageBody': '', 'messageHeadline': 'add a doctest', 'oid': 'd31a1decaceec003140293c37ad16763454347a8'}, {'authoredDate': '2025-04-05T08:03:07Z', 'authors': [{'email': '[email protected]', 'id': 'MDQ6VXNlcjY1MTYwOTg=', 'login': 'xcaruso', 'name': 'Xavier Caruso'}], 'committedDate': '2025-04-05T08:03:07Z', 'messageBody': '', 'messageHeadline': "Merge branch 'develop' into ore_over_extension", 'oid': '1d726b686c97eea0b4ad3bffe3e365ed9c7926f7'}]

INFO:root:result of get_commits with args () and kwds {} is [{'authoredDate': '2025-03-27T22:39:59Z', 'authors': [{'email': '[email protected]', 'id': '', 'login': '', 'name': 'Release Manager'}], 'committedDate': '2025-03-27T22:39:59Z', 'messageBody': '', 'messageHeadline': 'Updated SageMath version to 10.6.rc1', 'oid': '8a8453f35f3850c74d151a9f1c41778aac1f9e88'}, {'authoredDate': '2025-04-01T07:30:34Z', 'authors': [{'email': '[email protected]', 'id': '', 'login': '', 'name': 'Xavier Caruso'}], 'committedDate': '2025-04-01T07:30:34Z', 'messageBody': '', 'messageHeadline': "Merge branch 'develop' of https://github.com/sagemath/sage into develop", 'oid': '0c56dbebf51d6603b00b4a064944c26ae930462c'}, {'authoredDate': '2025-04-04T18:16:08Z', 'authors': [{'email': '[email protected]', 'id': '', 'login': '', 'name': 'Xavier Caruso'}], 'committedDate': '2025-04-04T18:16:46Z', 'messageBody': '', 'messageHeadline': 'improve Frobenius endomorphisms over extensions of finite fields', 'oid': '52b8e19639f7dc03bed605b7528239a9433c540c'}, {'authoredDate': '2025-04-05T06:31:33Z', 'authors': [{'email': '[email protected]', 'id': '', 'login': '', 'name': 'Xavier Caruso'}], 'committedDate': '2025-04-05T07:33:28Z', 'messageBody': '', 'messageHeadline': 'check finite field in the category', 'oid': '26ff7f192c4905747002aec87f2600abb59015ed'}, {'authoredDate': '2025-04-05T07:59:06Z', 'authors': [{'email': '[email protected]', 'id': '', 'login': '', 'name': 'Xavier Caruso'}], 'committedDate': '2025-04-05T07:59:06Z', 'messageBody': '', 'messageHeadline': 'add a doctest', 'oid': 'd31a1decaceec003140293c37ad16763454347a8'}, {'authoredDate': '2025-04-05T08:03:07Z', 'authors': [{'email': '[email protected]', 'id': 'MDQ6VXNlcjY1MTYwOTg=', 'login': 'xcaruso', 'name': 'Xavier Caruso'}], 'committedDate': '2025-04-05T08:03:07Z', 'messageBody': '', 'messageHeadline': "Merge branch 'develop' into ore_over_extension", 'oid': '1d726b686c97eea0b4ad3bffe3e365ed9c7926f7'}]

INFO:root:================================================================================

DEBUG:root:state of self: {'_url': 'https://github.com/sagemath/sage/pull/39881', '_actor': 'soehms', '_warning_prefix': 'Label Sync Warning:', '_hint_prefix': 'Label Sync Hint:', '_labels': ['s: needs work', 'c: finite rings'], '_author': None, '_draft': None, '_open': None, '_review_decision': None, '_reviews': None, '_reviews_from_rest_api': None, '_review_requests': None, '_commits': [{'authoredDate': '2025-03-27T22:39:59Z', 'authors': [{'email': '[email protected]', 'id': '', 'login': '', 'name': 'Release Manager'}], 'committedDate': '2025-03-27T22:39:59Z', 'messageBody': '', 'messageHeadline': 'Updated SageMath version to 10.6.rc1', 'oid': '8a8453f35f3850c74d151a9f1c41778aac1f9e88'}, {'authoredDate': '2025-04-01T07:30:34Z', 'authors': [{'email': '[email protected]', 'id': '', 'login': '', 'name': 'Xavier Caruso'}], 'committedDate': '2025-04-01T07:30:34Z', 'messageBody': '', 'messageHeadline': "Merge branch 'develop' of https://github.com/sagemath/sage into develop", 'oid': '0c56dbebf51d6603b00b4a064944c26ae930462c'}, {'authoredDate': '2025-04-04T18:16:08Z', 'authors': [{'email': '[email protected]', 'id': '', 'login': '', 'name': 'Xavier Caruso'}], 'committedDate': '2025-04-04T18:16:46Z', 'messageBody': '', 'messageHeadline': 'improve Frobenius endomorphisms over extensions of finite fields', 'oid': '52b8e19639f7dc03bed605b7528239a9433c540c'}, {'authoredDate': '2025-04-05T06:31:33Z', 'authors': [{'email': '[email protected]', 'id': '', 'login': '', 'name': 'Xavier Caruso'}], 'committedDate': '2025-04-05T07:33:28Z', 'messageBody': '', 'messageHeadline': 'check finite field in the category', 'oid': '26ff7f192c4905747002aec87f2600abb59015ed'}, {'authoredDate': '2025-04-05T07:59:06Z', 'authors': [{'email': '[email protected]', 'id': '', 'login': '', 'name': 'Xavier Caruso'}], 'committedDate': '2025-04-05T07:59:06Z', 'messageBody': '', 'messageHeadline': 'add a doctest', 'oid': 'd31a1decaceec003140293c37ad16763454347a8'}, {'authoredDate': '2025-04-05T08:03:07Z', 'authors': [{'email': '[email protected]', 'id': 'MDQ6VXNlcjY1MTYwOTg=', 'login': 'xcaruso', 'name': 'Xavier Caruso'}], 'committedDate': '2025-04-05T08:03:07Z', 'messageBody': '', 'messageHeadline': "Merge branch 'develop' into ore_over_extension", 'oid': '1d726b686c97eea0b4ad3bffe3e365ed9c7926f7'}], '_commit_date': '2025-04-05T07:59:06Z', '_bot_login': 'soehms', '_gh_version': "b'gh version 2.74.0-19-gea8fc856e (2025-06-09)", '_owner': 'sagemath', '_repo': 'sage', '_number': '39881', '_pr': True, '_issue': 'pull request #39881'}

The assertion is confirmed in the last line: '_commit_date': '2025-04-05T07:59:06Z'! Also note that self._commits still contains the full list of commits, ensuring that the change shouldn't cause a regression with this.

Copy link

github-actions bot commented Sep 17, 2025

Documentation preview for this PR (built with commit 111257b; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@soehms soehms marked this pull request as ready for review September 17, 2025 17:48
@soehms soehms requested a review from vincentmacri September 17, 2025 17:49
Copy link
Member

@vincentmacri vincentmacri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A question and a suggestion.

Also, how can we test this before I approve it?

if Status.needs_work.value in self.get_labels():
for com in date_commits:
message = com['messageHeadline']
if message.startswith('Merge') and message.find('develop') > 0:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if message.startswith('Merge') and message.find('develop') > 0:
if message.startswith("Merge branch 'develop' into "):

Would this work? Since it's more specific it's less likely to have a false positive.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, I see you already mentioned this. You can ignore this suggestion if you think people changing the merge commit message could be an issue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are also default messages that wouldn't match, for example in #40448: Merge remote-tracking branch 'upstream/develop' into remove-incremental


# ignore merge commits with the develop branch for commit_date if needs_work is set
date_commits = list(self._commits)
if Status.needs_work.value in self.get_labels():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason not to include the needs info tag as well here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No! I will include it in the next commit.

@soehms
Copy link
Member Author

soehms commented Sep 18, 2025

Also, how can we test this before I approve it?

This is a bit complicated. I've created a dummy PR (soehms#16) in my fork relative to the branch of this PR. I've declared the latter as the default branch so that GH-Action uses the changes in get_commits.

You should request changes on this PR. Afterwards I will merge the change concerning s: needs info into this PR.

Copy link
Member

@vincentmacri vincentmacri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or is the PR you wanted me to request changes on?

I think that the behaviour being changed here should be agnostic to if changes were requested through the "review changes" interface or someone manually setting the "needs work" label.

@soehms
Copy link
Member Author

soehms commented Sep 19, 2025

Or is the PR you wanted me to request changes on?

We cannot test the new changes with this PR because GH-Actions inherits the code from the base branch of the PR, which is develop.

I think that the behaviour being changed here should be agnostic to if changes were requested through the "review changes" interface or someone manually setting the "needs work" label.

That's right! This is the case when all of the bot's triggers are activated, meaning synchronization is bidirectional, meaning a change in the GH states translates into a change in the labels and vice versa. Currently, the direction from states to labels isn't even fully activated (changes in the review state are missing). For the return path, the activation of label changes is missing. You can see the current activation status in the header of #35927:

image

If all triggers are enabled, your scenario works like this:

  1. A reviewer sets the label s: needs review. The bot adds a review requesting changes. Since this feature is not currently enabled, the reviewer must do this manually.
  2. The author merges the branch into develop. The bot does not change the label because there is no significant commit after the requested changes.
  3. The author pushes a commit with significant changes. The bot changes the label to s: needs review.

Co-authored-by: Vincent Macri <[email protected]>
@soehms
Copy link
Member Author

soehms commented Sep 19, 2025

Sorry, time is over for the moment. I'll do the s: needs info change later on!

@tobiasdiez
Copy link
Contributor

tobiasdiez commented Sep 19, 2025

I'm wondering (loud) if it makes sense to never change needs work to needs review. Take for example this PR: Vincent had a few remarks, some but not all of them were addressed in a new commit - and the bot put it now onto needs review, although it is still in needs work.

This would also align it a bit better with the github interface: Vincent's review still shows as "requested changes" although there was a commit afterwards.

But I'm probably missing something essential here, in that case, sorry for the noise.


Btw, what's blocking the activation of

submitting a review to a PR, bot reaction: #35172 (comment), #36292

This would be quite convenient to have, and looks very similar to the already active "marking a draft PR as ready for review"

@vincentmacri
Copy link
Member

I'm wondering (loud) if it makes sense to never change needs work to needs review. Take for example this PR: Vincent had a few remarks, some but not all of them were addressed in a new commit - and the bot put it now onto needs review, although it is still in needs work.

I think this came up on sage-devel.

The problem is that changing labels requires certain GitHub permissions that not all contributors (particularly new contributors) have. So if a reviewer requests changes, the changes are made, and the reviewer doesn't look at the changes then the PR will be stuck marked as "needs work" and will probably get ignored. If that happened to one of my PRs I could change the label. If it happens to a new contributor they wouldn't have any way of bringing attention to their PR (besides tagging people, and they probably wouldn't know who to tag and might not be comfortable tagging random people they've never interacted with).

I think the main issue with the bot changing the labels to needs review when it doesn't need a review is that it makes it harder to find PRs that actually need a review. This PR should cut down on that noise a lot, even if there may still be some situations where the bot changes the label too early.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
github_actions Pull requests that update GitHub Actions code s: needs work t: bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Do not change PR from "needs work" to "needs review" after merge commit
3 participants