Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion checkov/common/goget/github/get_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
except ImportError as e:
git_import_error = e

COMMIT_ID_PATTERN = re.compile(r"\?(ref=)(?P<commit_id>([0-9a-f]{40}))")
COMMIT_ID_PATTERN = re.compile(r"\?(ref=)(?P<commit_id>([0-9a-f]{5,40}))")
TAG_PATTERN = re.compile(r'\?(ref=)(?P<tag>(.*))') # technically should be with ?ref=tags/ but this catches both
BRANCH_PATTERN = re.compile(r'\?(ref=heads/)(?P<branch>(.*))')

Expand Down
11 changes: 11 additions & 0 deletions tests/common/goget/test_goget_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,17 @@ def test_parse_commit_id(self):
self.assertEqual("aa218f56b14c9653891f9e74264a383fa43fefbd", getter.commit_id,
"Parsed source commit_id is wrong")

def test_parse_shortened_commit_id(self):
"""Test parsing of shortened git commit IDs (5-39 characters)."""
url = "https://my-git.com/owner/repository-name?ref=aa218"
getter = GitGetter(url)
git_url = getter.extract_git_ref(url)

self.assertEqual(
"https://my-git.com/owner/repository-name", git_url, "Parsed source url is wrong for 5-char commit"
)
self.assertEqual("aa218", getter.commit_id, "Parsed source commit_id is wrong for 5-char commit")

@patch('checkov.common.goget.github.get_git.Repo')
@patch('shutil.copytree')
@patch('os.makedirs')
Expand Down