This is a Python script that interacts with the GitHub API to fetch repository details and code scanning analysis information. Make sure the repository exists and your GitHub token has the necessary permissions to access it.
- Python 3.6 or higher
requests
library
-
Clone this repository:
git clone [email protected]:austimkelly/ghas-utils.git
-
Navigate to the cloned repository:
cd ghas-utils
-
Install the required Python libraries:
pip3 install requests
or
pip3 install -r requests.txt
-
Create a Github Personal Access Token and set the value in a
GITHUB_ACCESS_TOKEN
environment variable. Your personal access token will start withgithub_pat_
- This script is tested with these permissions:
NOTE: For organizations which you are not an owner, please see Setting a Personal Access Token for your Organization. If you leverage a personal access token to read organization repositories, you will need to enable this policy, otherwise only public repositories will be readable. You will need one personal access token per organization.
- Open
ghas-scan.py
in your favorite text editor. - Replace
owner_type
variable value withuser
ororg
. - Replace
owner_name
variable value with the corresponding user or org name. - Set
skip_forks
toTrue
if you want to omit forked repos from the results. - Run the script:
python3 ghas-scan.py
Output is written to github_data.csv
at the repository root. The console output will look like this:
Getting list of repositories...
Fetching repo security configs...
CSV file 'github_data.csv' written successfully.
Total repositories: 16
Total public repositories: 16
Percent of repositories that are forked: 0.0%
Percent of repositories with Codeowners: 6.25%
Percent of repositories with Secrets Scanning Enabled: 12.5%
Percent of repositories with Secrets Push Protection Enabled: 12.5%
Total number of open critical and high code scanning alerts: 0
Total number of open critical dependabot alerts: 0
Done.
You can see an example CSV in ./example/example_output.csv. This is just a simple example to give you an idea of the schema.