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

Revert "dont raise exception" #27

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
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
7 changes: 2 additions & 5 deletions reusable_workflows/check_membership/check_membership.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@ def main() -> None:
gh = github3.login(token=gh_token)

if not gh:
# Todo: change to Exception once GH_TOKEN can be passed in from forked repositories
print("github login failed - maybe GH_TOKEN was not correctly set")
is_member = False
raise Exception("github login failed - maybe GH_TOKEN was not correctly set")

else:
is_member = is_member_of_org(gh, org, user)
is_member = is_member_of_org(gh, org, user)

if is_member:
print(f"{user} is member of {org} and can contribute.")
Expand Down
21 changes: 7 additions & 14 deletions reusable_workflows/tests/test_membership.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,16 @@ def test_end_to_end_api_fails(os_system, github_login_mock):
os_system.assert_not_called()


@mock.patch.dict(os.environ, {"GH_ORG": "my_org", "GH_TOKEN": "", "USER": "username"})
@mock.patch.dict(
os.environ, {"GH_ORG": "my_org", "GH_TOKEN": "", "USER": "username"}
)
@mock.patch("github3.login")
def test_github_token_not_passed_in(github_login_mock, capfd):
def test_github_token_not_passed_in(github_login_mock):
github_login_mock.return_value = None

main()
out, err = capfd.readouterr()
with pytest.raises(Exception) as exc:
main()

assert (
out
== "github login failed - maybe GH_TOKEN was not correctly set\nusername is an external contributor.\n"
str(exc.value) == "github login failed - maybe GH_TOKEN was not correctly set"
)

# Todo: switch back once exception is added back
# with pytest.raises(Exception) as exc:
# main()

# assert (
# str(exc.value) == "github login failed - maybe GH_TOKEN was not correctly set"
# )
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ ignore_missing_imports = True
ignore_missing_imports = True

[flake8]
ignore = E501, W503
ignore = E501