Skip to content
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

Adjust the sync label bot to reflect recent GitHub CLI changes #36894

Merged
merged 2 commits into from
Dec 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions .github/sync_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def __init__(self, url, actor):
self._commits = None
self._commit_date = None
self._bot_login = None
self._gh_version = None

s = url.split('/')
self._owner = s[3]
Expand Down Expand Up @@ -235,13 +236,30 @@ def bot_login(self):
"""
if self._bot_login:
return self._bot_login
cmd = 'gh auth status'
from subprocess import run
cmd = 'gh version'
capt = run(cmd, shell=True, capture_output=True)
self._gh_version = str(capt.stdout).split('\\n')[0]
info('version: %s' % self._gh_version)
cmd = 'gh auth status'
capt = run(cmd, shell=True, capture_output=True)
l = str(capt.stderr).split()
if not 'as' in l:
l = str(capt.stdout).split()
self._bot_login = l[l.index('as')+1]
errtxt = str(capt.stderr)
outtxt = str(capt.stdout)
debug('auth status err: %s' % errtxt)
debug('auth status out: %s' % outtxt)
def read_login(txt, position_mark):
for t in txt:
for p in position_mark:
# the output text has changed from as to account
# around version 2.40.0
l = t.split()
if p in l:
return l[l.index(p)+1]
self._bot_login = read_login([errtxt, outtxt], ['account', 'as'])
if not self._bot_login:
self._bot_login = default_bot
warning('Bot is unknown')
return self._bot_login
if self._bot_login.endswith('[bot]'):
self._bot_login = self._bot_login.split('[bot]')[0]
info('Bot is %s' % self._bot_login)
Expand Down
Loading