File tree Expand file tree Collapse file tree 6 files changed +21
-25
lines changed
Expand file tree Collapse file tree 6 files changed +21
-25
lines changed Original file line number Diff line number Diff line change 44from mergify_cli .ci import detector
55from mergify_cli .ci .junit_processing import cli as junit_processing_cli
66from mergify_cli .ci .scopes import cli as scopes_cli
7+ from mergify_cli .ci .scopes import exceptions as scopes_exc
78
89
910class JUnitFile (click .Path ):
@@ -240,7 +241,7 @@ async def scopes(
240241) -> None :
241242 try :
242243 scopes = scopes_cli .detect (config_path = config_path )
243- except scopes_cli .ScopesError as e :
244+ except scopes_exc .ScopesError as e :
244245 raise click .ClickException (str (e )) from e
245246
246247 running_in_ci = utils .get_boolean_env ("CI" )
Original file line number Diff line number Diff line change 44import os
55import typing
66
7- import click
87import yaml
98
109from mergify_cli import utils
10+ from mergify_cli .ci .scopes import exceptions
11+
12+
13+ class BaseNotFoundError (exceptions .ScopesError ):
14+ pass
1115
1216
1317class MergeQueuePullRequest (typing .TypedDict ):
@@ -92,10 +96,5 @@ def detect() -> Base:
9296 if base_ref :
9397 return Base (base_ref , is_merge_queue = False )
9498
95- msg = (
96- "Could not detect base SHA. Ensure checkout has sufficient history "
97- "(e.g., actions/checkout with fetch-depth: 0) or provide GITHUB_EVENT_PATH / GITHUB_BASE_REF."
98- )
99- raise click .ClickException (
100- msg ,
101- )
99+ msg = "Could not detect base SHA. Provide GITHUB_EVENT_PATH / GITHUB_BASE_REF."
100+ raise BaseNotFoundError (msg )
Original file line number Diff line number Diff line change 33import subprocess
44import sys
55
6+ from mergify_cli .ci .scopes import exceptions
7+
68
79COMMITS_BATCH_SIZE = 100
810
911
10- class ChangedFilesError (Exception ):
12+ class ChangedFilesError (exceptions . ScopesError ):
1113 pass
1214
1315
Original file line number Diff line number Diff line change 1212from mergify_cli import utils
1313from mergify_cli .ci .scopes import base_detector
1414from mergify_cli .ci .scopes import changed_files
15+ from mergify_cli .ci .scopes import exceptions
1516
1617
1718if typing .TYPE_CHECKING :
2223SCOPE_NAME_RE = r"^[A-Za-z0-9_-]+$"
2324
2425
25- class ScopesError (Exception ):
26- pass
27-
28-
29- class ConfigInvalidError (ScopesError ):
30- pass
31-
32-
33- class ChangedFilesError (ScopesError ):
26+ class ConfigInvalidError (exceptions .ScopesError ):
3427 pass
3528
3629
@@ -121,10 +114,7 @@ class DetectedScope:
121114def detect (config_path : str ) -> DetectedScope :
122115 cfg = Config .from_yaml (config_path )
123116 base = base_detector .detect ()
124- try :
125- changed = changed_files .git_changed_files (base .ref )
126- except changed_files .ChangedFilesError as e :
127- raise ChangedFilesError (str (e ))
117+ changed = changed_files .git_changed_files (base .ref )
128118 scopes_hit , per_scope = match_scopes (cfg , changed )
129119
130120 all_scopes = set (cfg .scopes .keys ())
Original file line number Diff line number Diff line change 1+ class ScopesError (Exception ):
2+ pass
Original file line number Diff line number Diff line change 11import json
22import pathlib
33
4- import click
54import pytest
65
76from mergify_cli .ci .scopes import base_detector
@@ -63,7 +62,10 @@ def test_detect_base_no_info(monkeypatch: pytest.MonkeyPatch) -> None:
6362 monkeypatch .delenv ("GITHUB_EVENT_PATH" , raising = False )
6463 monkeypatch .delenv ("GITHUB_BASE_REF" , raising = False )
6564
66- with pytest .raises (click .ClickException , match = "Could not detect base SHA" ):
65+ with pytest .raises (
66+ base_detector .BaseNotFoundError ,
67+ match = "Could not detect base SHA" ,
68+ ):
6769 base_detector .detect ()
6870
6971
You can’t perform that action at this time.
0 commit comments