Skip to content
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
11 changes: 6 additions & 5 deletions .github/workflows/check_cla_ruleset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,20 @@ jobs:
- name: Python Setup
uses: ./.github/workflows/python-setup

- name: Check if accepting external contributions
id: accepts_external_contrib
- name: Check if can contribute
id: can_contribute
run: |
export PYTHONPATH="$PWD/reusable_workflows/"
python reusable_workflows/check_cla/check_repos.py
python reusable_workflows/check_cla/check_can_contribute.py
shell: bash
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
REPO: ${{ github.event.repository.name }}
USER: ${{ github.event.pull_request.user.login }}

- name: Close Pull Request
id: close_pr
if: ${{ steps.accepts_external_contrib.outputs.accepts_contrib != 'true' }}
if: ${{ steps.can_contribute.outputs.can_contribute != 'true' }}
uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 #v3
with:
comment: |
Expand Down Expand Up @@ -77,7 +78,7 @@ jobs:
export PYTHONPATH="$PWD/reusable_workflows/"
python reusable_workflows/check_cla/check_cla_pr.py
shell: bash
if: ${{ steps.accepts_external_contrib.outputs.accepts_contrib != 'false' }}
if: ${{ steps.can_contribute.outputs.can_contribute == 'true' }}
env:
GH_ORG: ${{ github.repository_owner }}
GH_TOKEN: ${{ steps.app-token.outputs.token }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from shared.utils import download_gh_file

APPROVED_CONTRIBUTOR_LIST = ["droid-uexternal"]


def get_repos_open_to_contributions(gh: github3.login) -> List[str]:
org = "dfinity"
Expand All @@ -22,6 +24,7 @@ def get_repos_open_to_contributions(gh: github3.login) -> List[str]:

def main() -> None:
repo = os.environ["REPO"]
user = os.environ["USER"]
gh_token = os.environ["GH_TOKEN"]

gh = github3.login(token=gh_token)
Expand All @@ -30,9 +33,12 @@ def main() -> None:
raise Exception("github login failed - maybe GH_TOKEN was not correctly set")

repo_list = get_repos_open_to_contributions(gh)
accepts_contrib = repo in repo_list
repo_accepts_contributions = repo in repo_list
user_is_approved_contributor = user in APPROVED_CONTRIBUTOR_LIST

can_contribute = repo_accepts_contributions or user_is_approved_contributor

os.system(f"""echo 'accepts_contrib={accepts_contrib}' >> $GITHUB_OUTPUT""")
os.system(f"""echo 'can_contribute={can_contribute}' >> $GITHUB_OUTPUT""")


if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import github3
import pytest

from check_cla.check_repos import (
from check_cla.check_can_contribute import (
get_repos_open_to_contributions,
main,
) # noqa
Expand Down Expand Up @@ -43,7 +43,7 @@ def test_end_to_end(os_system, github_login_mock):

main()

os_system.assert_called_with("echo 'accepts_contrib=True' >> $GITHUB_OUTPUT")
os_system.assert_called_with("echo 'can_contribute=True' >> $GITHUB_OUTPUT")


@mock.patch.dict(os.environ, {"REPO": "my_org", "GH_TOKEN": ""})
Expand Down