From 64b7607b983a26ce9046ae2581b7896a886d40ed Mon Sep 17 00:00:00 2001 From: Sebastian Date: Wed, 17 Sep 2025 08:01:17 +0200 Subject: [PATCH 1/4] sync_labels_merge_commit initial --- .github/sync_labels.py | 52 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/.github/sync_labels.py b/.github/sync_labels.py index 128d3437e3c..dad2c43305a 100755 --- a/.github/sync_labels.py +++ b/.github/sync_labels.py @@ -408,7 +408,17 @@ def get_commits(self): return self._commits self._commits = self.view('commits') - self._commit_date = max( com['committedDate'] for com in self._commits ) + + # 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(): + for com in date_commits: + message = com['messageHeadline'] + if message.startswith('Merge') and message.find('develop') > 0: + debug('Ignore merge commit %s for commit_date' % com['oid']) + date_commits.remove(com) + + self._commit_date = max(com['committedDate'] for com in date_commits) info('Commits until %s for %s: %s' % (self._commit_date, self._issue, self._commits)) return self._commits @@ -1034,6 +1044,35 @@ def run_tests(self): elif self.is_pull_request(): self.run(action) + def test_method(self, method, *args, **kwds): + r""" + Run the given method for testing. + + EXAMPLES:: + + sage$ python .github/sync_labels.py https://github.com/sagemath/sage/pull/40634 soehms is_auth_team_member "{'login': 'soehms'}" -t + INFO:root:cmdline_args (4) ['https://github.com/sagemath/sage/pull/40634', 'soehms', 'is_auth_team_member', "{'login': 'soehms'}"] + ... + DEBUG:root:call is_auth_team_member with args () and kwds {'login': 'soehms'} + DEBUG:root:================================================================================ + DEBUG:root:Execute command: gh api -X GET -H "Accept: application/vnd.github+json" /orgs/sagemath/teams/triage/memberships/soehms + INFO:root:User soehms is a member of triage + INFO:root:result of is_auth_team_member with args () and kwds {'login': 'soehms'} is True + INFO:root:================================================================================ + ... + """ + if hasattr(self, method): + meth = self.__getattribute__(method) + if callable(meth): + debug('call %s with args %s and kwds %s' % (method, args, kwds)) + debug('='*80) + res = meth(*args, **kwds) + info('result of %s with args %s and kwds %s is %s' % (method, args, kwds, res)) + info('='*80) + debug('state of self: %s' % self.__dict__) + return + raise ValueError('%s is not a method of %s' % (method, self)) + ############################################################################### # Main @@ -1068,8 +1107,10 @@ def run_tests(self): num_args = len(cmdline_args) info('cmdline_args (%s) %s' % (num_args, cmdline_args)) -if run_tests and num_args in (1,2): - if num_args == 2: +if run_tests: + if num_args == 4: + url, actor, method, args = cmdline_args + elif num_args == 2: url, actor = cmdline_args else: url, = cmdline_args @@ -1079,7 +1120,10 @@ def run_tests(self): info('actor: %s' % actor) gh = GhLabelSynchronizer(url, actor) - gh.run_tests() + if num_args == 4: + gh.test_method(method, **eval(args)) + else: + gh.run_tests() elif num_args == 5: action, url, actor, label, rev_state = cmdline_args From 111257bf10dac04575f3f3a35efde0a5bcc4aea7 Mon Sep 17 00:00:00 2001 From: Sebastian Oehms <47305845+soehms@users.noreply.github.com> Date: Fri, 19 Sep 2025 09:10:58 +0200 Subject: [PATCH 2/4] 40839: review changes Co-authored-by: Vincent Macri --- .github/sync_labels.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/sync_labels.py b/.github/sync_labels.py index dad2c43305a..9e4b7979d90 100755 --- a/.github/sync_labels.py +++ b/.github/sync_labels.py @@ -414,7 +414,7 @@ def get_commits(self): 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: + if message.startswith('Merge') and 'develop' in message: debug('Ignore merge commit %s for commit_date' % com['oid']) date_commits.remove(com) From d0bbf380a0f5fbd3d9307c1be377d21f5af33220 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 22 Sep 2025 08:15:42 +0200 Subject: [PATCH 3/4] 40839: ignore merge commits if there is no positive review --- .github/sync_labels.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/sync_labels.py b/.github/sync_labels.py index 9e4b7979d90..bc4b545b93b 100755 --- a/.github/sync_labels.py +++ b/.github/sync_labels.py @@ -409,9 +409,9 @@ def get_commits(self): self._commits = self.view('commits') - # ignore merge commits with the develop branch for commit_date if needs_work is set + # ignore merge commits with the develop branch for _commit_date except positive review is set date_commits = list(self._commits) - if Status.needs_work.value in self.get_labels(): + if Status.positive_review.value not in self.get_labels(): for com in date_commits: message = com['messageHeadline'] if message.startswith('Merge') and 'develop' in message: From 0a3cfe2af14b49a78e7544f6f7c898c792c23a76 Mon Sep 17 00:00:00 2001 From: Sebastian Oehms <47305845+soehms@users.noreply.github.com> Date: Mon, 22 Sep 2025 22:18:48 +0200 Subject: [PATCH 4/4] 40839: Apply suggestions from code review Co-authored-by: Vincent Macri --- .github/sync_labels.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/sync_labels.py b/.github/sync_labels.py index bc4b545b93b..2dbdc671faf 100755 --- a/.github/sync_labels.py +++ b/.github/sync_labels.py @@ -409,10 +409,10 @@ def get_commits(self): self._commits = self.view('commits') - # ignore merge commits with the develop branch for _commit_date except positive review is set + # ignore merge commits with the develop branch for _commit_date unless positive review is set date_commits = list(self._commits) if Status.positive_review.value not in self.get_labels(): - for com in date_commits: + for com in self._commits: message = com['messageHeadline'] if message.startswith('Merge') and 'develop' in message: debug('Ignore merge commit %s for commit_date' % com['oid'])