Skip to content

Commit 2c1f889

Browse files
committed
fix: avoid exception when checking for logged in user in case app is used
1 parent a08706e commit 2c1f889

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

gh_org_mgr/_gh_org.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,16 @@ def _check_configured_org_owners(self) -> bool:
201201
return True
202202

203203
def _is_user_authenticated_user(self, user: NamedUser) -> bool:
204-
"""Check if a given NamedUser is the authenticated user"""
205-
if user.login == self.gh.get_user().login:
206-
return True
204+
"""Check if a given NamedUser is the authenticated user. If logging in via App, this will
205+
always return False, as the authenticated user is the App itself"""
206+
try:
207+
if user.login == self.gh.get_user().login:
208+
return True
209+
except GithubException as e:
210+
if e.status == 403 and "Resource not accessible by integration" in str(e):
211+
logging.debug("Cannot check if user is authenticated, as this is an App login")
212+
return False
213+
raise
207214
return False
208215

209216
def sync_org_owners(self, dry: bool = False, force: bool = False) -> None:

0 commit comments

Comments
 (0)