-
Notifications
You must be signed in to change notification settings - Fork 2
Support for Dependabot commands #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
9f5aaa6
Initial support for Dependabot commands
jboursier-mwb 0a7af42
Fixes
jboursier-mwb 6a5ddcf
Support multiple repositories to be passed on the CLI
jboursier-mwb 15e1cff
Merge branch 'main' into dependabot_alerts
jboursier-mwb 4007fa4
Support exporting SBOM in various formats
jboursier-mwb 8f28b14
Rename Dependabot group commands
jboursier-mwb dedbc1b
Fix typo
jboursier-mwb 3188684
Remove unused import
jboursier-mwb dce8217
Merge branch 'main' into dependabot_alerts
a2cf402
Merge branch 'main' into dependabot_alerts
45f2cc4
Merge branch 'main' into dependabot_alerts
jboursier-mwb 4a0e793
Fix the license fetching logic for sbom CSV export
jboursier-mwb b8f1167
Merge branch 'dependabot_alerts' of github.com:Malwarebytes/ghas-cli …
jboursier-mwb afbc75d
Support exporting topics from repositories.
jboursier-mwb 0a2fb76
Fix passed credentials for the get_topics function
jboursier-mwb cd4d6a2
Support mass export of dependencies for an org
jboursier-mwb 185dfcb
Update dependabot.py
jboursier-mwb d08e439
Do not sleep twice when hitting the rate limit
jboursier-mwb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| # -*- coding: utf-8 -*- | ||
| #!/usr/bin/env python3 | ||
|
|
||
| from typing import List | ||
| import requests | ||
| import json | ||
| import time | ||
Check noticeCode scanning / CodeQL Unused import
Import of 'time' is not used.
|
||
| import logging | ||
|
|
||
| from . import network | ||
|
|
||
|
|
||
| def list_alerts_repo(repository: str, organization: str, token: str) -> List: | ||
| """Get Dependabot alerts for one repository""" | ||
|
|
||
| headers = network.get_github_headers(token) | ||
|
|
||
| alerts_repo = [] | ||
| page = 1 | ||
| while True: | ||
| i = 0 | ||
| while i < network.RETRIES: | ||
| params = {"state": "open", "per_page": 100, "page": page} | ||
| alerts = requests.get( | ||
| url=f"https://api.github.com/repos/{organization}/{repository}/dependabot/alerts", | ||
| params=params, | ||
| headers=headers, | ||
| ) | ||
| if network.check_rate_limit(alerts): | ||
|
jboursier-mwb marked this conversation as resolved.
|
||
| i += 1 | ||
| else: | ||
| break | ||
|
|
||
| if alerts.status_code != 200: | ||
| break | ||
| if not alerts.json(): | ||
| break | ||
| for a in alerts.json(): | ||
| if not a: | ||
| continue | ||
| alerts_repo.append(json.dumps(a)) | ||
| page += 1 | ||
|
|
||
| return alerts_repo | ||
|
|
||
|
|
||
|
|
||
| def get_dependencies(repository: str, organization: str, token: str, format:str ="sbom"): | ||
| """ | ||
| Get the list of dependencies for one repository. | ||
|
|
||
| Available formats: | ||
| - `sbom` - SPDX json | ||
| - `CSV` - CSV export | ||
| - `txt` - basic export | ||
|
|
||
| https://docs.github.com/en/rest/dependency-graph/sboms?apiVersion=2022-11-28 | ||
| """ | ||
| headers = network.get_github_headers(token) | ||
|
|
||
| dependencies = requests.get( | ||
| url=f"https://api.github.com/repos/{organization}/{repository}/dependency-graph/sbom", | ||
| headers=headers, | ||
| ) | ||
|
|
||
|
|
||
| if dependencies.status_code != 200: | ||
| logging.error(f"Unable to retrieve the dependencies for {repository} - {dependencies.status_code} - {dependencies.content}") | ||
| return False | ||
|
|
||
| if "sbom" == format: | ||
| return dependencies.json() | ||
| elif "csv" == format: | ||
| deps = "" | ||
| for dep in dependencies.json()["sbom"]["packages"]: | ||
| try: | ||
| license = dep['licenseConcluded'] | ||
| except: | ||
Check noticeCode scanning / CodeQL Except block handles 'BaseException'
Except block directly handles BaseException.
|
||
| try: | ||
| license = dep['licenseDeclared'] | ||
| except: | ||
Check noticeCode scanning / CodeQL Except block handles 'BaseException'
Except block directly handles BaseException.
|
||
| license = "Unknown" | ||
|
|
||
| deps += f"{repository}, {dep['name']},{dep['versionInfo']}, {license}\n" | ||
| return deps | ||
| elif "txt" == format: | ||
| deps = "" | ||
| for dep in dependencies.json()["sbom"]["packages"]: | ||
| deps += dep["name"] + "\n" | ||
| return deps | ||
| else: | ||
| logging.error(f"Invalid export format {format}. Must be one of `sbom`, `csv` or `txt`.") | ||
| return False | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.