Update diff_url logic in GitHubClient.py to simplify commit comparison handling. Adjusted the URL for single commit cases and removed unnecessary comparisons against an empty tree.

Signed-off-by: Shakar Bakr <5h4k4r.b4kr@gmail.com>
This commit is contained in:
Shakar Bakr 2025-06-15 13:57:00 +03:00
parent 5cdfff250b
commit 61dcc147f4
No known key found for this signature in database
GPG Key ID: DA55A26823AE3C28

View File

@ -89,15 +89,14 @@ class GitHubClient(Client):
# There is a valid before SHA to compare with, or this is a release being created.
diff_url = f'{self.repos_url}{self.repo}/compare/{self.before}...{self.sha}'
elif len(self.commits) == 1:
# There is only one commit - compare against empty tree to get all files
diff_url = f'{self.repos_url}{self.repo}/compare/4b825dc642cb6eb9a060e54bf8d69288fbee4904...{self.sha}'
# There is only one commit.
diff_url = f'{self.repos_url}{self.repo}/commits/{self.sha}'
elif len(self.commits) > 1:
# There are several commits: compare with the oldest one.
oldest = sorted(self.commits, key=self._get_timestamp)[0]['id']
diff_url = f'{self.repos_url}{self.repo}/compare/{oldest}...{self.sha}'
else:
# No commits info available, compare against empty tree to get all files
diff_url = f'{self.repos_url}{self.repo}/compare/4b825dc642cb6eb9a060e54bf8d69288fbee4904...{self.sha}'
return None
diff_headers = {
'Accept': 'application/vnd.github.v3.diff',