Skip to content

Commit 2f0a787

Browse files
authored
Merge branch 'main' into extend-functionality-of-workflow
2 parents 9a62b0e + b40a8e5 commit 2f0a787

File tree

5 files changed

+52
-44
lines changed

5 files changed

+52
-44
lines changed

.github/workflows/check_is_bot.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Workflow to check if a user is a member of the org
2+
3+
name: Check Is Bot
4+
5+
on:
6+
workflow_call:
7+
outputs:
8+
is_bot:
9+
value: ${{ jobs.check-is-bot.outputs.is_bot }}
10+
11+
jobs:
12+
check-is-bot:
13+
name: Check Is Bot
14+
runs-on: ubuntu-latest
15+
# Dont run this workflow on merge queue
16+
if: ${{ github.event_name != 'merge_group' }}
17+
outputs:
18+
is_member: ${{ steps.check-is-bot.outputs.is_bot}}
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
with:
23+
repository: 'dfinity/public-workflows'
24+
25+
- name: Python Setup
26+
uses: ./.github/workflows/python-setup
27+
28+
- name: Check Is Bot
29+
id: check-is-bot
30+
run: |
31+
export PYTHONPATH="$PWD/reusable_workflows/"
32+
python reusable_workflows/repo_policies/check_is_bot.py
33+
shell: bash
34+
env:
35+
USER: ${{ github.event.pull_request.user.login }}

.github/workflows/repo_policies.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ on:
44
workflow_call:
55

66
jobs:
7+
check-is-bot:
8+
uses: dfinity/public-workflows/.github/workflows/check_is_bot.yml@main
9+
secrets: inherit
10+
711
check-bot-policies:
812
name: Check Bot Policies
913
runs-on: ubuntu-latest
10-
# Dont run this workflow on merge queue
11-
if: ${{ github.event_name != 'merge_group' }}
14+
needs: check-is-bot
15+
if: ${{ needs.check-is-bot.outputs.is_bot == 'true' && needs.check-is-bot.result == 'success' }}
1216
steps:
1317
# First check out code from public-workflows
1418
- name: Checkout

reusable_workflows/repo_policies/check_bot_approved_files.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import github3
66

7-
from check_membership.check_membership import is_approved_bot
87
from shared.utils import download_gh_file, load_env_vars
98

109
BOT_APPROVED_FILES_PATH = ".github/repo_policies/BOT_APPROVED_FILES"
@@ -105,13 +104,7 @@ def main() -> None:
105104
print("Skipping checks for dependabot.")
106105
return
107106

108-
is_bot = is_approved_bot(user)
109-
110-
if is_bot:
111-
check_if_pr_is_blocked(env_vars)
112-
113-
else:
114-
print(f"{user} is not a bot. Skipping bot checks.")
107+
check_if_pr_is_blocked(env_vars)
115108

116109

117110
if __name__ == "__main__":
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import os
2+
3+
from check_membership.check_membership import is_approved_bot
4+
5+
6+
def main() -> None:
7+
user = os.getenv("USER")
8+
9+
is_bot = is_approved_bot(user)
10+
os.system(f"""echo 'is_bot={is_bot}' >> $GITHUB_OUTPUT""")

reusable_workflows/tests/test_repo_policies.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
get_approved_files,
1111
get_approved_files_config,
1212
get_changed_files,
13-
main,
1413
)
1514

1615

@@ -155,36 +154,3 @@ def test_pr_is_blocked_true(gh_login, get_approved_files_config, get_changed_fil
155154

156155
get_changed_files.assert_called_once_with("base", "head", "path")
157156
get_approved_files_config.assert_called_once_with(repo)
158-
159-
160-
@mock.patch("repo_policies.check_bot_approved_files.load_env_vars")
161-
@mock.patch("repo_policies.check_bot_approved_files.is_approved_bot")
162-
@mock.patch("repo_policies.check_bot_approved_files.check_if_pr_is_blocked")
163-
def test_main_succeeds(check_if_pr_is_blocked, is_approved_bot, load_env_vars, capfd):
164-
env_vars = {"GH_TOKEN": "token", "USER": "user"}
165-
load_env_vars.return_value = env_vars
166-
is_approved_bot.return_value = True
167-
check_if_pr_is_blocked.return_value = False
168-
169-
main()
170-
171-
captured = capfd.readouterr()
172-
assert "" == captured.out
173-
174-
175-
@mock.patch("repo_policies.check_bot_approved_files.load_env_vars")
176-
@mock.patch("repo_policies.check_bot_approved_files.is_approved_bot")
177-
@mock.patch("repo_policies.check_bot_approved_files.check_if_pr_is_blocked")
178-
def test_main_not_a_bot(check_if_pr_is_blocked, is_approved_bot, load_env_vars, capfd):
179-
env_vars = {"GH_TOKEN": "token", "USER": "user"}
180-
load_env_vars.return_value = env_vars
181-
is_approved_bot.return_value = False
182-
183-
main()
184-
185-
captured = capfd.readouterr()
186-
assert (
187-
"user is not a bot. Skipping bot checks."
188-
in captured.out
189-
)
190-
check_if_pr_is_blocked.assert_not_called()

0 commit comments

Comments
 (0)