Skip to content

Commit bd9679b

Browse files
authored
feat(IDX): add approved contributors (#174)
* feat(IDX): add approved contributors * fix * fix test * test on branch Added a reference to the 'add-contribution-override' branch in the checkout step. * change trigger * Remove test reference from checkout step Removed the test reference from the checkout step.
1 parent 138c114 commit bd9679b

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

.github/workflows/check_cla_ruleset.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,20 @@ jobs:
3535
- name: Python Setup
3636
uses: ./.github/workflows/python-setup
3737

38-
- name: Check if accepting external contributions
39-
id: accepts_external_contrib
38+
- name: Check if can contribute
39+
id: can_contribute
4040
run: |
4141
export PYTHONPATH="$PWD/reusable_workflows/"
42-
python reusable_workflows/check_cla/check_repos.py
42+
python reusable_workflows/check_cla/check_can_contribute.py
4343
shell: bash
4444
env:
4545
GH_TOKEN: ${{ steps.app-token.outputs.token }}
4646
REPO: ${{ github.event.repository.name }}
47+
USER: ${{ github.event.pull_request.user.login }}
4748

4849
- name: Close Pull Request
4950
id: close_pr
50-
if: ${{ steps.accepts_external_contrib.outputs.accepts_contrib != 'true' }}
51+
if: ${{ steps.can_contribute.outputs.can_contribute != 'true' }}
5152
uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 #v3
5253
with:
5354
comment: |
@@ -77,7 +78,7 @@ jobs:
7778
export PYTHONPATH="$PWD/reusable_workflows/"
7879
python reusable_workflows/check_cla/check_cla_pr.py
7980
shell: bash
80-
if: ${{ steps.accepts_external_contrib.outputs.accepts_contrib != 'false' }}
81+
if: ${{ steps.can_contribute.outputs.can_contribute == 'true' }}
8182
env:
8283
GH_ORG: ${{ github.repository_owner }}
8384
GH_TOKEN: ${{ steps.app-token.outputs.token }}

reusable_workflows/check_cla/check_repos.py renamed to reusable_workflows/check_cla/check_can_contribute.py

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

66
from shared.utils import download_gh_file
77

8+
APPROVED_CONTRIBUTOR_LIST = ["droid-uexternal"]
9+
810

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

2325
def main() -> None:
2426
repo = os.environ["REPO"]
27+
user = os.environ["USER"]
2528
gh_token = os.environ["GH_TOKEN"]
2629

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

3235
repo_list = get_repos_open_to_contributions(gh)
33-
accepts_contrib = repo in repo_list
36+
repo_accepts_contributions = repo in repo_list
37+
user_is_approved_contributor = user in APPROVED_CONTRIBUTOR_LIST
38+
39+
can_contribute = repo_accepts_contributions or user_is_approved_contributor
3440

35-
os.system(f"""echo 'accepts_contrib={accepts_contrib}' >> $GITHUB_OUTPUT""")
41+
os.system(f"""echo 'can_contribute={can_contribute}' >> $GITHUB_OUTPUT""")
3642

3743

3844
if __name__ == "__main__":

reusable_workflows/tests/test_check_repos.py renamed to reusable_workflows/tests/test_check_can_contribute.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import github3
55
import pytest
66

7-
from check_cla.check_repos import (
7+
from check_cla.check_can_contribute import (
88
get_repos_open_to_contributions,
99
main,
1010
) # noqa
@@ -43,7 +43,7 @@ def test_end_to_end(os_system, github_login_mock):
4343

4444
main()
4545

46-
os_system.assert_called_with("echo 'accepts_contrib=True' >> $GITHUB_OUTPUT")
46+
os_system.assert_called_with("echo 'can_contribute=True' >> $GITHUB_OUTPUT")
4747

4848

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

0 commit comments

Comments
 (0)