Skip to content

Commit a0df948

Browse files
committed
adapt_sync_labels_to_gh_changes initial
1 parent e2e0f8d commit a0df948

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+
info('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)