@@ -141,6 +141,7 @@ def __init__(self, url, actor):
141
141
self ._commits = None
142
142
self ._commit_date = None
143
143
self ._bot_login = None
144
+ self ._gh_version = None
144
145
145
146
s = url .split ('/' )
146
147
self ._owner = s [3 ]
@@ -235,13 +236,30 @@ def bot_login(self):
235
236
"""
236
237
if self ._bot_login :
237
238
return self ._bot_login
238
- cmd = 'gh auth status'
239
239
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'
240
245
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
245
263
if self ._bot_login .endswith ('[bot]' ):
246
264
self ._bot_login = self ._bot_login .split ('[bot]' )[0 ]
247
265
info ('Bot is %s' % self ._bot_login )
0 commit comments