Skip to content

Instantly share code, notes, and snippets.

@mstoykov
Created April 18, 2026 08:17
Show Gist options
  • Select an option

  • Save mstoykov/c00406f9d3e0894de991a0b17737ef9b to your computer and use it in GitHub Desktop.

Select an option

Save mstoykov/c00406f9d3e0894de991a0b17737ef9b to your computer and use it in GitHub Desktop.
add renovate config to repos
#!/usr/bin/env bash
set -euo pipefail
if [[ $# -lt 1 ]]; then
echo "Usage: $0 <owner/repo> [owner/repo ...]"
exit 1
fi
RENOVATE_CONTENT='{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"github>grafana/grafana-renovate-config//presets/k6/k6-engine-base.json"
]
}
'
BRANCH_NAME="add-renovate-config"
COMMIT_MESSAGE="chore: add renovate config"
PR_TITLE="chore: add renovate config"
PR_BODY="Adds \`renovate.json\` extending the [k6-engine-base preset](https://github.com/grafana/grafana-renovate-config/blob/main/presets/k6/k6-engine-base.json)."
for REPO in "$@"; do
echo "==> Processing $REPO"
# Get default branch
DEFAULT_BRANCH=$(gh api "repos/$REPO" --jq '.default_branch')
echo " Default branch: $DEFAULT_BRANCH"
# Check if renovate.json already exists on default branch
if gh api "repos/$REPO/contents/renovate.json" --silent 2>/dev/null; then
echo " renovate.json already exists, skipping."
continue
fi
echo " renovate.json not found, creating branch '$BRANCH_NAME'..."
# Bail out if the branch already exists rather than touching it
if gh api "repos/$REPO/git/ref/heads/$BRANCH_NAME" --silent 2>/dev/null; then
echo " Branch '$BRANCH_NAME' already exists — skipping to avoid overwriting existing work."
continue
fi
# Get SHA of default branch tip
BASE_SHA=$(gh api "repos/$REPO/git/ref/heads/$DEFAULT_BRANCH" --jq '.object.sha')
# Create branch
gh api --method POST "repos/$REPO/git/refs" \
--field "ref=refs/heads/$BRANCH_NAME" \
--field "sha=$BASE_SHA" \
--silent
# Encode content as base64
ENCODED=$(printf '%s' "$RENOVATE_CONTENT" | base64 -w 0)
# Create the file on the new branch
gh api --method PUT "repos/$REPO/contents/renovate.json" \
--field "message=$COMMIT_MESSAGE" \
--field "content=$ENCODED" \
--field "branch=$BRANCH_NAME" \
--silent
echo " File committed. Opening PR..."
PR_URL=$(gh pr create \
--repo "$REPO" \
--base "$DEFAULT_BRANCH" \
--head "$BRANCH_NAME" \
--title "$PR_TITLE" \
--body "$PR_BODY")
echo " PR created: $PR_URL"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment