-
Notifications
You must be signed in to change notification settings - Fork 61
feat: add code scanning coverage report and alert dismissal scripts #144
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
base: main
Are you sure you want to change the base?
Changes from all commits
a2d2490
018fb03
e5b80b3
ce85343
90bea81
8525270
ebcec20
bb3de7f
46ab062
b6d1a7e
e3294fd
e82e904
1274e6c
0995c3d
a2bf38f
2609134
271c4e5
eb0e3e4
462dfb5
510dbab
7442c3d
13c2502
b7c1138
d16195b
f634d56
4ab5d08
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,231 @@ | ||||||||||||||||||||||||||
| # code-scanning-coverage-report | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Generate a comprehensive code scanning coverage report for all repositories in a GitHub organization. | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ## Features | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| - Reports CodeQL enablement status, last scan date, and scanned languages | ||||||||||||||||||||||||||
| - Identifies CodeQL-supported languages that are not being scanned | ||||||||||||||||||||||||||
| - Shows open alert counts and analysis errors/warnings | ||||||||||||||||||||||||||
| - Generates actionable sub-reports for remediation | ||||||||||||||||||||||||||
| - Supports parallel API calls for faster processing | ||||||||||||||||||||||||||
| - Works with GitHub.com and GitHub Enterprise Server | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ## Prerequisites | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| - Node.js 18 or later | ||||||||||||||||||||||||||
| - A GitHub token with `repo` scope, or GitHub App credentials | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ## Installation | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ```shell | ||||||||||||||||||||||||||
| cd scripts/code-scanning-coverage-report | ||||||||||||||||||||||||||
| npm install | ||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ## Usage | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ```shell | ||||||||||||||||||||||||||
| # Set your GitHub token | ||||||||||||||||||||||||||
| export GITHUB_TOKEN=ghp_xxxxxxxxxxxx | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Note: If you are authenticated with the GitHub CLI, you can use `gh auth token` to get your token: | ||||||||||||||||||||||||||
| # export GITHUB_TOKEN=$(gh auth token) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Basic usage - output to stdout | ||||||||||||||||||||||||||
| node code-scanning-coverage-report.js my-org | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Output to file (also generates sub-reports) | ||||||||||||||||||||||||||
| node code-scanning-coverage-report.js my-org --output report.csv | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Check a single repository | ||||||||||||||||||||||||||
| node code-scanning-coverage-report.js my-org --repo my-repo | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Sample 25 random repositories | ||||||||||||||||||||||||||
| node code-scanning-coverage-report.js my-org --sample --output sample.csv | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Include workflow status column | ||||||||||||||||||||||||||
| node code-scanning-coverage-report.js my-org --check-workflow-status --output report.csv | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Check for unscanned GitHub Actions workflows | ||||||||||||||||||||||||||
| node code-scanning-coverage-report.js my-org --check-unscanned-actions --output report.csv | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Use with GitHub Enterprise Server | ||||||||||||||||||||||||||
| export GITHUB_API_URL=https://github.example.com/api/v3 | ||||||||||||||||||||||||||
| node code-scanning-coverage-report.js my-org --output report.csv | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Adjust concurrency (default: 10) | ||||||||||||||||||||||||||
| node code-scanning-coverage-report.js my-org --concurrency 5 --output report.csv | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Process multiple organizations from a file | ||||||||||||||||||||||||||
| node code-scanning-coverage-report.js --orgs-file orgs.txt --output report.csv | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Customize stale threshold (default: 90 days) | ||||||||||||||||||||||||||
| node code-scanning-coverage-report.js my-org --stale-days 60 --output report.csv | ||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ## Options | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| | Option | Description | | ||||||||||||||||||||||||||
| |--------|-------------| | ||||||||||||||||||||||||||
| | `--orgs-file <file>` | File containing list of organizations (one per line) | | ||||||||||||||||||||||||||
| | `--output <file>` | Write CSV to file (also generates sub-reports) | | ||||||||||||||||||||||||||
| | `--repo <repo>` | Check a single repository instead of all repos | | ||||||||||||||||||||||||||
| | `--sample` | Sample 25 random repositories | | ||||||||||||||||||||||||||
| | `--fetch-alerts` | Include alert counts in report (increases API usage) | | ||||||||||||||||||||||||||
| | `--check-workflow-status` | Check CodeQL workflow run status (success/failure) | | ||||||||||||||||||||||||||
| | `--check-unscanned-actions` | Check if repos have Actions workflows not being scanned | | ||||||||||||||||||||||||||
| | `--concurrency <n>` | Number of concurrent API calls (default: 10) | | ||||||||||||||||||||||||||
| | `--stale-days <n>` | Days after last scan to consider repo stale (default: 90) | | ||||||||||||||||||||||||||
| | `--help` | Show help message | | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ## API Usage | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Default options use approximately **2 API calls per repository**: | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| - With a **Personal Access Token** (5,000 requests/hour): supports up to ~2,500 repos | ||||||||||||||||||||||||||
| - With **GitHub App authentication** (15,000 requests/hour): supports up to ~7,500 repos | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Optional flags increase API usage: | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| | Flag | Additional Calls | | ||||||||||||||||||||||||||
| |------|------------------| | ||||||||||||||||||||||||||
| | `--fetch-alerts` | +1 call per repo (paginated for repos with many alerts) | | ||||||||||||||||||||||||||
| | `--check-workflow-status` | +1-2 calls per repo | | ||||||||||||||||||||||||||
| | `--check-unscanned-actions` | +1 call per repo | | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| The script displays your current rate limit at startup and total API calls used at completion. | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ## Environment Variables | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Two authentication methods are supported: | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| - **Personal Access Token (PAT)**: Simple setup, good for testing or small organizations | ||||||||||||||||||||||||||
| - **GitHub App**: Recommended for production use - provides higher rate limits (5,000 vs 15,000 requests/hour) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ### Token Authentication | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| | Variable | Description | | ||||||||||||||||||||||||||
| |----------|-------------| | ||||||||||||||||||||||||||
| | `GITHUB_TOKEN` | GitHub token with `repo` scope | | ||||||||||||||||||||||||||
| | `GITHUB_API_URL` | API endpoint (defaults to `https://api.github.com`) | | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ### GitHub App Authentication (recommended) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| | Variable | Description | | ||||||||||||||||||||||||||
| |----------|-------------| | ||||||||||||||||||||||||||
| | `GITHUB_APP_ID` | GitHub App ID | | ||||||||||||||||||||||||||
| | `GITHUB_APP_PRIVATE_KEY_PATH` | Path to GitHub App private key file (.pem) | | ||||||||||||||||||||||||||
| | `GITHUB_API_URL` | API endpoint (defaults to `https://api.github.com`) | | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| The script automatically looks up the installation ID for each organization being processed. This enables scanning multiple organizations with a single command using `--orgs-file`. | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| **Required GitHub App Permissions:** | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Repository permissions: | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| | Permission | Access | Required For | | ||||||||||||||||||||||||||
| |------------|--------|--------------| | ||||||||||||||||||||||||||
| | Code scanning alerts | Read | Code scanning status, analyses, and alert counts | | ||||||||||||||||||||||||||
| | Contents | Read | Listing repositories and checking for workflow files | | ||||||||||||||||||||||||||
| | Metadata | Read | Detecting repository languages (this is automatically added) | | ||||||||||||||||||||||||||
| | Actions | Read | Workflow run status (only if using --check-workflow-status) | | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Organization permissions: | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| | Permission | Access | Required For | | ||||||||||||||||||||||||||
| |------------|--------|--------------| | ||||||||||||||||||||||||||
| | Administration | Read | Listing all repositories in the organization | | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
Comment on lines
+130
to
+139
|
||||||||||||||||||||||||||
| | Contents | Read | Listing repositories and checking for workflow files | | |
| | Metadata | Read | Detecting repository languages (this is automatically added) | | |
| | Actions | Read | Workflow run status (only if using --check-workflow-status) | | |
| Organization permissions: | |
| | Permission | Access | Required For | | |
| |------------|--------|--------------| | |
| | Administration | Read | Listing all repositories in the organization | | |
| | Contents | Read | Checking for workflow files | | |
| | Metadata | Read | Listing repositories and detecting repository languages (this is automatically added) | | |
| | Actions | Read | Workflow run status (only if using --check-workflow-status) | |
Copilot
AI
Jan 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are duplicate lines at lines 158-160. The comment "# Run the report" and the command "node code-scanning-coverage-report.js my-org --output report.csv" appear to be accidentally duplicated from the previous section.
| # Run the report | |
| node code-scanning-coverage-report.js my-org --output report.csv | |
| ``` |
Copilot
AI
Jan 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sub-reports table mentions "-open-alerts.csv" but the code actually generates "-critical-alerts.csv" (as seen in line 849 of the main script). This documentation should be updated to match the actual implementation.
| | `*-open-alerts.csv` | Repos with open code scanning alerts | | |
| | `*-critical-alerts.csv` | Repositories with critical severity code scanning alerts | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The entry for "code-scanning-coverage-report" should come before "create-app-jwt.py" to maintain alphabetical order. Currently it's placed after "ado_workitems_to_github_issues" which breaks the alphabetical ordering pattern.