Skip to content

Commit a8f38e8

Browse files
author
Release Manager
committed
gh-36894: Adjust the sync label bot to reflect recent GitHub CLI changes <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes #1234" use "Introduce new method to calculate 1+1" --> <!-- Describe your changes here in detail --> At least since version 2.40.0 of `gh` the output of `gh auth status` has changed. This broke the method `bot_login` where the bot's login name is obtained. The first failure appeared on 13.12 in [this scheduled run](ht tps://github.com/sagemath/sage/actions/runs/7199213174/job/19610401946). More specifically, the word before the login name used for positioning has changed from `as` to `account`. In a logfile it looks like this: ``` Run chmod a+x .github/sync_labels.py INFO:root:cmdline_args (1) ['https://github.com/sagemath/sage'] INFO:root:url: https://github.com/sagemath/sage INFO:root:Create label handler for pull request #sage and actor sagetrac-github-bot Traceback (most recent call last): File "/home/runner/work/sage/sage/.github/sync_labels.py", line 1081, in <module> gh = GhLabelSynchronizer(url, default_actor) File "/home/runner/work/sage/sage/.github/sync_labels.py", line 157, in __init__ self.bot_login() File "/home/runner/work/sage/sage/.github/sync_labels.py", line 244, in bot_login self._bot_login = l[l.index('as')+1] ValueError: 'as' is not in list Error: Process completed with exit code 1. ``` This PR does the following: * implements an adjustment to this change * avoids raising an error if the bot name cannot be discovered (to better behave with similar changes in the future) * adds more log messages to make it easier to identify similar issues <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes #12345". --> <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> <!-- Feel free to remove irrelevant items. --> - [x] The title is concise, informative, and self-explanatory. - [x] 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 accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - #12345: short description why this is a dependency - #34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: #36894 Reported by: Sebastian Oehms Reviewer(s): Kwankyu Lee
2 parents 74f82be + a032c79 commit a8f38e8

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

.github/sync_labels.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ def __init__(self, url, actor):
141141
self._commits = None
142142
self._commit_date = None
143143
self._bot_login = None
144+
self._gh_version = None
144145

145146
s = url.split('/')
146147
self._owner = s[3]
@@ -235,13 +236,30 @@ def bot_login(self):
235236
"""
236237
if self._bot_login:
237238
return self._bot_login
238-
cmd = 'gh auth status'
239239
from subprocess import run
240+
cmd = 'gh version'
241+
capt = run(cmd, shell=True, capture_output=True)
242+
self._gh_version = str(capt.stdout).split('\\n')[0]
243+
info('version: %s' % self._gh_version)
244+
cmd = 'gh auth status'
240245
capt = run(cmd, shell=True, capture_output=True)
241-
l = str(capt.stderr).split()
242-
if not 'as' in l:
243-
l = str(capt.stdout).split()
244-
self._bot_login = l[l.index('as')+1]
246+
errtxt = str(capt.stderr)
247+
outtxt = str(capt.stdout)
248+
debug('auth status err: %s' % errtxt)
249+
debug('auth status out: %s' % outtxt)
250+
def read_login(txt, position_mark):
251+
for t in txt:
252+
for p in position_mark:
253+
# the output text has changed from as to account
254+
# around version 2.40.0
255+
l = t.split()
256+
if p in l:
257+
return l[l.index(p)+1]
258+
self._bot_login = read_login([errtxt, outtxt], ['account', 'as'])
259+
if not self._bot_login:
260+
self._bot_login = default_bot
261+
warning('Bot is unknown')
262+
return self._bot_login
245263
if self._bot_login.endswith('[bot]'):
246264
self._bot_login = self._bot_login.split('[bot]')[0]
247265
info('Bot is %s' % self._bot_login)

0 commit comments

Comments
 (0)