@@ -134,16 +134,25 @@ def __init__(self, path: str):
134
134
# GitHub Actions PR context
135
135
github_base_ref = os .getenv ('GITHUB_BASE_REF' )
136
136
github_head_ref = os .getenv ('GITHUB_HEAD_REF' )
137
- if github_base_ref and github_head_ref :
137
+ github_event_name = os .getenv ('GITHUB_EVENT_NAME' )
138
+ if github_event_name == 'pull_request' and github_base_ref and github_head_ref :
138
139
try :
139
140
self .repo .git .fetch ('origin' , github_base_ref , github_head_ref )
140
- diff_range = f"origin/{ github_base_ref } ...{ self . commit . hexsha } "
141
+ diff_range = f"origin/{ github_base_ref } ...origin/ { github_head_ref } "
141
142
diff_files = self .repo .git .diff ('--name-only' , diff_range )
142
143
self .show_files = diff_files .splitlines ()
143
- log .debug (f"Changed files detected via git diff (GitHub): { self .show_files } " )
144
+ log .debug (f"Changed files detected via git diff (GitHub PR ): { self .show_files } " )
144
145
detected = True
145
146
except Exception as error :
146
- log .debug (f"Failed to get changed files via git diff (GitHub): { error } " )
147
+ log .debug (f"Failed to get changed files via git diff (GitHub PR): { error } " )
148
+ # Commits to default branch (push events)
149
+ elif github_event_name == 'push' :
150
+ try :
151
+ self .show_files = self .repo .git .show (self .commit , name_only = True , format = "%n" ).splitlines ()
152
+ log .debug (f"Changed files detected via git show (GitHub push): { self .show_files } " )
153
+ detected = True
154
+ except Exception as error :
155
+ log .debug (f"Failed to get changed files via git show (GitHub push): { error } " )
147
156
# GitLab CI Merge Request context
148
157
if not detected :
149
158
gitlab_target = os .getenv ('CI_MERGE_REQUEST_TARGET_BRANCH_NAME' )
0 commit comments