Dane Balia
creative · wiltw

Github Dependabot API & Dumpify

Using Dumpify for Neovim debugging in C#

This is a great aid if you looking to get insight into debug information via console, while not using a debugger. DAP sucks.

Dumpify

Retrieving dependadot alerts from Github API

import csv
                import requests
                
                OWNER = 'your_owner_name'  # GitHub Owner name
                REPOSITORIES = ['repo1', 'repo2']  # List of repositories
                PAT = 'your_personal_access_token'  # GitHub Personal Access Token
                CSV_FILE = 'dependabot_alerts.csv'  # Output CSV file name
                
                session = requests.Session()
                session.headers.update({
                    "Accept": "application/vnd.github+json",
                    "Authorization": f"Bearer {PAT}",
                    "X-GitHub-Api-Version": "2022-11-28"
                })
                
                def fetch_dependabot_alerts(owner, repo):
                    """Fetch Dependabot alerts for a specific repository using the session."""
                    url = f"https://api.github.com/repos/{owner}/{repo}/dependabot/alerts?state=open&severity=critical&per_page=100"
                    response = session.get(url)
                    if response.status_code == 200:
                        return response.json()
                    else:
                        print(f"Failed to fetch alerts for {repo}: {response.status_code}")
                        return []
                
                def process_alerts(alerts, repo):
                    """Process each alert to extract relevant fields, including the repository name."""
                    processed_alerts = []
                    for alert in alerts:
                        processed_alert = {
                            "repository": repo,
                            "number": alert.get("number"),
                            "state": alert.get("state"),
                            "dependency_ecosystem": alert.get("dependency", {}).get("package", {}).get("ecosystem", ""),
                            "dependency_name": alert.get("dependency", {}).get("package", {}).get("name", ""),
                            "security_advisory_description": alert.get("security_advisory", {}).get("description", "")
                        }
                        processed_alerts.append(processed_alert)
                    return processed_alerts
                
                def write_to_csv(data):
                    """Write the processed alert data to a CSV file."""
                    with open(CSV_FILE, mode='w', newline='') as file:
                        writer = csv.DictWriter(file, fieldnames=data[0].keys())
                        writer.writeheader()
                        for row in data:
                            writer.writerow(row)
                
                def main():
                    """Main function to orchestrate the fetching, processing, and writing of Dependabot alert data."""
                    all_alerts = []
                    for repo in REPOSITORIES:
                        alerts = fetch_dependabot_alerts(OWNER, repo)
                        if alerts:
                            processed_alerts = process_alerts(alerts, repo)
                            all_alerts.extend(processed_alerts)
                    if all_alerts:
                        write_to_csv(all_alerts)
                        print(f"Data written to {CSV_FILE}")
                    else:
                        print("No data to write.")
                
                if __name__ == "__main__":
                    main()
                
                
                
Dane Balia
Dane Balia

Engineer and writer. Notes on software, faith, and the craft of building.