Skip to content

Commit eca3b11

Browse files
committed
Fixing logic for Github changed files
1 parent f5da0a9 commit eca3b11

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
66

77
[project]
88
name = "socketsecurity"
9-
version = "2.1.29"
9+
version = "2.1.30"
1010
requires-python = ">= 3.10"
1111
license = {"file" = "LICENSE"}
1212
dependencies = [

socketsecurity/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
__author__ = 'socket.dev'
2-
__version__ = '2.1.29'
2+
__version__ = '2.1.30'

socketsecurity/core/git_interface.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,25 @@ def __init__(self, path: str):
134134
# GitHub Actions PR context
135135
github_base_ref = os.getenv('GITHUB_BASE_REF')
136136
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:
138139
try:
139140
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}"
141142
diff_files = self.repo.git.diff('--name-only', diff_range)
142143
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}")
144145
detected = True
145146
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}")
147156
# GitLab CI Merge Request context
148157
if not detected:
149158
gitlab_target = os.getenv('CI_MERGE_REQUEST_TARGET_BRANCH_NAME')

0 commit comments

Comments
 (0)