Skip to content

Commit 79c3879

Browse files
committed
Check permission script supports user's repositories
When user forks a repository under its own namespace the Github API raises exception since the organization doesn't exists and instead user namespace is used. This commits add a support of such a repository to allow running pipelines from forks. Signed-off-by: Ales Raszka <[email protected]>
1 parent 804f4f0 commit 79c3879

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

operator-pipeline-images/operatorcert/entrypoints/check_permissions.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import urllib
88
from typing import Any
99

10-
from github import Auth, Github
10+
from github import Auth, Github, UnknownObjectException
1111
from operator_repo import Operator
1212
from operator_repo import Repo as OperatorRepo
1313
from operatorcert import pyxis
@@ -194,7 +194,11 @@ def is_org_member(self) -> bool:
194194
)
195195
github_auth = Auth.Token(os.environ.get("GITHUB_TOKEN") or "")
196196
github = Github(auth=github_auth)
197-
members = github.get_organization(self.github_repo_org).get_members()
197+
try:
198+
members = github.get_organization(self.github_repo_org).get_members()
199+
except UnknownObjectException:
200+
LOGGER.info("Organization %s does not exist", self.github_repo_org)
201+
return False
198202

199203
for member in members:
200204
if self.pr_owner in member.login:

operator-pipeline-images/tests/entrypoints/test_check_permissions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import operatorcert.entrypoints.check_permissions as check_permissions
77
import pytest
8+
from github import UnknownObjectException
89
from operator_repo import Repo as OperatorRepo
910
from tests.utils import bundle_files, create_files
1011

@@ -180,6 +181,13 @@ def test_OperatorReview_is_org_member(
180181
mock_organization.get_members.return_value = members
181182
assert review_community.is_org_member() == False
182183

184+
# Organization does not exist
185+
members = [MagicMock(login="user123")]
186+
mock_github.return_value.get_organization.side_effect = UnknownObjectException(
187+
404, "", {}
188+
)
189+
assert review_community.is_org_member() == False
190+
183191

184192
@patch("operatorcert.entrypoints.check_permissions.pyxis.get_project")
185193
def test_OperatorReview_check_permission_for_partner(

0 commit comments

Comments
 (0)