Skip to content

Instantly share code, notes, and snippets.

@skwashd
Created August 27, 2019 03:50
Show Gist options
  • Save skwashd/3ffc1ab9230224001455151813b41648 to your computer and use it in GitHub Desktop.
Save skwashd/3ffc1ab9230224001455151813b41648 to your computer and use it in GitHub Desktop.
Batch create dependabot config.yml file in github repos
#!/usr/bin/env python3
import base64
import os
import requests
token = os.environ.get("GITHUB_TOKEN")
org = os.environ.get("GITHUB_ORG")
config_file = os.environ.get("DEPENDABOT_CONFIG_FILE", "dependabot-config.yml")
commit_message = "I didn't configure the script properly"
name = "Dave's Dependabot Script"
email = "skwashd@gmail.com"
repos = [
# Add list of repos here.
]
with open(config_file, "rb") as f:
config = f.read()
config_b64 = base64.b64encode(config).decode("utf-8")
headers = {"Authorization": f"token {token}"}
for repo in repos:
url = f"https://api.github.com/repos/{org}/{repo}/contents/.dependabot/config.yml"
payload = {
"author": {"name": name, "email": email},
"content": config_b64,
"message": commit_message,
}
r = requests.put(url, headers=headers, json=payload)
r.raise_for_status()
# Full config file configuration available at https://dependabot.com/docs/config-file/
version: 1
update_configs:
- package_manager: "python"
directory: "/"
update_schedule: "live"
automerged_updates:
- match:
dependency_type: "all"
update_type: "semver:minor"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment