Skip to content

Commit 52d996f

Browse files
authored
Merge pull request #479 from lukasbestle/fix/security-advisories-private
Fixes to `--security-advisories` option
2 parents 6780d3a + 1181f81 commit 52d996f

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

README.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,17 @@ The tool automatically extracts file extensions from HTTP headers to ensure file
284284
**Fine-grained token limitation:** Due to a GitHub platform limitation, fine-grained personal access tokens (``github_pat_...``) cannot download attachments from private repositories directly. This affects both ``/assets/`` (images) and ``/files/`` (documents) URLs. The tool implements a workaround for image attachments using GitHub's Markdown API, which converts URLs to temporary JWT-signed URLs that can be downloaded. However, this workaround only works for images - document attachments (PDFs, text files, etc.) will fail with 404 errors when using fine-grained tokens on private repos. For full attachment support on private repositories, use a classic token (``-t``) instead of a fine-grained token (``-f``). See `#477 <https://github.com/josegonzalez/python-github-backup/issues/477>`_ for details.
285285

286286

287+
About security advisories
288+
-------------------------
289+
290+
GitHub security advisories are only available in public repositories. GitHub does not provide the respective API endpoint for private repositories.
291+
292+
Therefore the logic is implemented as follows:
293+
- Security advisories are included in the `--all` option.
294+
- If only the `--all` option was provided, backups of security advisories are skipped for private repositories.
295+
- If the `--security-advisories` option is provided (on its own or in addition to `--all`), a backup of security advisories is attempted for all repositories, with graceful handling if the GitHub API doesn't return any.
296+
297+
287298
Run in Docker container
288299
-----------------------
289300

github_backup/github_backup.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,7 +1814,7 @@ def backup_repositories(args, output_directory, repositories):
18141814
if args.include_milestones or args.include_everything:
18151815
backup_milestones(args, repo_cwd, repository, repos_template)
18161816

1817-
if args.include_security_advisories or args.include_everything:
1817+
if args.include_security_advisories or (args.include_everything and not repository["Private"]):
18181818
backup_security_advisories(args, repo_cwd, repository, repos_template)
18191819

18201820
if args.include_labels or args.include_everything:
@@ -2039,13 +2039,20 @@ def backup_security_advisories(args, repo_cwd, repository, repos_template):
20392039
return
20402040

20412041
logger.info("Retrieving {0} security advisories".format(repository["full_name"]))
2042-
mkdir_p(repo_cwd, advisory_cwd)
20432042

20442043
template = "{0}/{1}/security-advisories".format(
20452044
repos_template, repository["full_name"]
20462045
)
20472046

2048-
_advisories = retrieve_data(args, template)
2047+
try:
2048+
_advisories = retrieve_data(args, template)
2049+
except Exception as e:
2050+
if "404" in str(e):
2051+
logger.info("Security advisories are not available for this repository, skipping")
2052+
return
2053+
raise
2054+
2055+
mkdir_p(repo_cwd, advisory_cwd)
20492056

20502057
advisories = {}
20512058
for advisory in _advisories:

0 commit comments

Comments
 (0)