-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from hypothesis/copy-code-from-dependabot-batch…
…-review Copy code from `dependabot-batch-review`
- Loading branch information
Showing
16 changed files
with
306 additions
and
61 deletions.
There are no files selected for viewing
This file contains 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 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,10 @@ | ||
`dependabot-alerts` lists Dependabot security alerts for all repos of a GitHub | ||
user or organization. You can run it from the command line: | ||
|
||
```terminal | ||
$ dependabot-alerts <your_github_user_or_organization> | ||
``` | ||
|
||
There's also a [GitHub Actions workflow](.github/workflows/alert.yml) that runs | ||
automatically on a schedule and notifies us in Slack of any Dependabot alerts | ||
in the `hypothesis` GitHub organization. |
This file contains 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 @@ | ||
requests |
This file contains 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 @@ | ||
dev: GITHUB_TOKEN |
This file contains 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,44 @@ | ||
name: Alert | ||
on: | ||
schedule: | ||
- cron: '30 10 * * 1' | ||
workflow_dispatch: | ||
jobs: | ||
Alert: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Install Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: 3.12 | ||
- name: Install pipx | ||
run: python -m pip install pipx | ||
- name: Install gha-token | ||
run: python -m pipx install "git+https://github.com/hypothesis/gha-token.git" | ||
- name: Checkout dependabot-alerts | ||
- uses: actions/checkout@v4 | ||
- name: Install dependabot-alerts | ||
run: python -m pipx install . | ||
- name: Get GitHub token | ||
id: github_token | ||
run: echo GITHUB_TOKEN=$(gha-token --app-id 274948 --installation-id 32440510 --private-key "$PRIVATE_KEY") >> $GITHUB_OUTPUT | ||
env: | ||
PRIVATE_KEY: ${{ secrets.HYPOTHESIS_GITHUB_APP_PRIVATE_KEY }} | ||
- name: Check for alerts | ||
id: slack_message | ||
run: | | ||
{ | ||
echo 'SLACK_MESSAGE<<EOF' | ||
dependabot-alerts hypothesis | ||
echo EOF | ||
} >> "$GITHUB_OUTPUT" | ||
env: | ||
GITHUB_TOKEN: ${{ steps.github_token.outputs.GITHUB_TOKEN }} | ||
- name: Post to Slack | ||
uses: slackapi/[email protected] | ||
with: | ||
channel-id: ${{ vars.SLACK_CHANNEL }} | ||
slack-message: ${{ env.SLACK_MESSAGE }} | ||
env: | ||
SLACK_MESSAGE: ${{ steps.slack_message.outputs.SLACK_MESSAGE }} | ||
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} |
This file contains 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 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 |
---|---|---|
@@ -1,5 +1,2 @@ | ||
3.12.0 | ||
3.11.6 | ||
3.10.13 | ||
3.9.18 | ||
3.8.18 |
This file contains 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 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 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 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 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 |
---|---|---|
@@ -1,13 +1,49 @@ | ||
from argparse import ArgumentParser | ||
from importlib.metadata import version | ||
|
||
from dependabot_alerts.core import GitHubClient, Vulnerability, fetch_alerts | ||
|
||
def cli(_argv=None): # pylint:disable=inconsistent-return-statements | ||
|
||
def cli(_argv=None): # pragma: no cover | ||
parser = ArgumentParser() | ||
parser.add_argument("-v", "--version", action="store_true") | ||
parser.add_argument( | ||
"-v", "--version", action="version", version=version("dependabot-alerts") | ||
) | ||
parser.add_argument("organization", help="GitHub user or organization") | ||
|
||
args = parser.parse_args(_argv) | ||
|
||
if args.version: | ||
print(version("dependabot-alerts")) | ||
return 0 | ||
gh_client = GitHubClient.init() | ||
vulns = fetch_alerts(gh_client, args.organization) | ||
print(format_slack_message(args.organization, vulns)) | ||
|
||
return 0 | ||
|
||
|
||
def format_slack_message( | ||
organization: str, vulns: list[Vulnerability] | ||
) -> str: # pragma: no cover | ||
""" | ||
Format a Slack status report from a list of vulnerabilities. | ||
Returns a message using Slack's "mrkdwn" format. See | ||
https://api.slack.com/reference/surfaces/formatting. | ||
""" | ||
if not vulns: | ||
return "Found no open vulnerabilities." | ||
|
||
n_repos = len(set(vuln.repo for vuln in vulns)) | ||
|
||
msg_parts = [] | ||
msg_parts.append(f"*Found {len(vulns)} vulnerabilities in {n_repos} repositories.*") | ||
|
||
for vuln in vulns: | ||
vuln_msg = [] | ||
vuln_msg.append( | ||
f"{organization}/{vuln.repo}: <{vuln.url}|{vuln.package_name} {vuln.severity} - {vuln.title}>" | ||
) | ||
if vuln.pr: | ||
vuln_msg.append(f" Resolved by {vuln.pr}") | ||
msg_parts.append("\n".join(vuln_msg)) | ||
|
||
return "\n\n".join(msg_parts) |
Oops, something went wrong.