Skip to content

Commit bbdfe97

Browse files
authored
[BRE-831] Updating error wording for repos with custom default branches (#144)
1 parent d20fa64 commit bbdfe97

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

src/bitwarden_workflow_linter/rules/check_pr_target.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ def fn(self, obj: Workflow) -> Tuple[bool, str]:
5858
result, check_job = self.has_check_run(obj)
5959
main_branch_only = self.targets_main_branch(obj)
6060
if not main_branch_only:
61-
Errors.append("Workflows using pull_request_target can only target the main branch")
61+
default_branch = self.settings.default_branch
62+
Errors.append(f"Workflows using pull_request_target can only target the '{default_branch}' branch")
6263
if result:
6364
missing_jobs = self.check_run_required(obj, check_job)
6465
if missing_jobs:

tests/rules/test_check_pr_target.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ def fixture_correct_workflow():
3030
check-run:
3131
name: Check PR run
3232
uses: bitwarden/gh-actions/.github/workflows/check-run.yml@main
33-
33+
3434
quality:
3535
name: Quality scan
3636
needs: check-run
3737
steps:
3838
- run: echo test
39-
39+
4040
dependent-job:
4141
name: Another Dependent Job
4242
needs:
@@ -85,7 +85,7 @@ def fixture_no_needs_workflow():
8585
runs-on: ubuntu-22.04
8686
steps:
8787
- run: echo test
88-
88+
8989
quality:
9090
name: Quality scan
9191
steps:
@@ -124,13 +124,13 @@ def dependent_missing_check_workflow():
124124
check-run:
125125
name: Check PR run
126126
uses: bitwarden/gh-actions/.github/workflows/check-run.yml@main
127-
127+
128128
quality:
129129
name: Quality scan
130130
needs: check-run
131131
steps:
132132
- run: echo test
133-
133+
134134
dependent-job:
135135
name: Another Dependent Job
136136
needs:
@@ -153,13 +153,13 @@ def fixture_no_branches_workflow():
153153
check-run:
154154
name: Check PR run
155155
uses: bitwarden/gh-actions/.github/workflows/check-run.yml@main
156-
156+
157157
quality:
158158
name: Quality scan
159159
needs: check-run
160160
steps:
161161
- run: echo test
162-
162+
163163
dependent-job:
164164
name: Another Dependent Job
165165
needs:
@@ -186,13 +186,13 @@ def fixture_bad_branches_workflow():
186186
check-run:
187187
name: Check PR run
188188
uses: bitwarden/gh-actions/.github/workflows/check-run.yml@main
189-
189+
190190
quality:
191191
name: Quality scan
192192
needs: check-run
193193
steps:
194194
- run: echo test
195-
195+
196196
dependent-job:
197197
name: Another Dependent Job
198198
needs:
@@ -216,13 +216,13 @@ def fixture_two_failures_workflow():
216216
check-run:
217217
name: Check PR run
218218
uses: bitwarden/some-other-repo/.github/workflows/check-run.yml@main
219-
219+
220220
quality:
221221
name: Quality scan
222222
needs: check-run
223223
steps:
224224
- run: echo test
225-
225+
226226
dependent-job:
227227
name: Another Dependent Job
228228
needs:
@@ -269,11 +269,11 @@ def test_targets_main_branch_no_default_branch(mock_workflow):
269269
with patch("src.bitwarden_workflow_linter.utils.Settings.factory") as mock_factory:
270270
# Simulate the default settings returned by the factory
271271
mock_factory.return_value = Settings(default_branch="main")
272-
272+
273273
# Use the mocked factory to create the Settings instance
274274
settings = Settings.factory()
275275
rule = RuleCheckPrTarget(settings=settings)
276-
276+
277277
# Assert that the workflow targets the main branch
278278
assert rule.targets_main_branch(mock_workflow) is True
279279

@@ -317,14 +317,14 @@ def test_rule_on_dependencies_without_check(rule, dependent_missing_check_workfl
317317
def test_rule_on_no_branches_workflow(rule, no_branches_workflow):
318318
result, message = rule.fn(no_branches_workflow)
319319
assert result is False
320-
assert message == "Workflows using pull_request_target can only target the main branch"
320+
assert message == "Workflows using pull_request_target can only target the 'main' branch"
321321

322322
def test_rule_on_only_target_main(rule, bad_branches_workflow):
323323
result, message = rule.fn(bad_branches_workflow)
324324
assert result is False
325-
assert message == "Workflows using pull_request_target can only target the main branch"
325+
assert message == "Workflows using pull_request_target can only target the 'main' branch"
326326

327327
def test_rule_on_two_failures(rule, two_failures_workflow):
328328
result, message = rule.fn(two_failures_workflow)
329329
assert result is False
330-
assert message == "Workflows using pull_request_target can only target the main branch\nA check-run job must be included as a direct job dependency when pull_request_target is used"
330+
assert message == "Workflows using pull_request_target can only target the 'main' branch\nA check-run job must be included as a direct job dependency when pull_request_target is used"

0 commit comments

Comments
 (0)