Skip to content

Instantly share code, notes, and snippets.

@book000
Created January 21, 2024 13:35
Show Gist options
  • Save book000/7313ca0ede2810eb97fb3dcfa42c7cb4 to your computer and use it in GitHub Desktop.
Save book000/7313ca0ede2810eb97fb3dcfa42c7cb4 to your computer and use it in GitHub Desktop.
$REPO_NAME = (gh repo view --json name -q .name)
$REPO_WITH_OWNER = (gh repo view --json nameWithOwner -q .nameWithOwner)
Write-Host "Repository name: $REPO_WITH_OWNER"
# リポジトリがアーカイブ済みかどうかを判定
$IS_ARCHIVED = (gh repo view --json isArchived -q .isArchived)
if ($IS_ARCHIVED -eq $true) {
Write-Host "Repository is archived."
Write-Host ""
# リポジトリがアーカイブ済みの場合は、ディレクトリを削除するか確認
$ANSWER = Read-Host "Do you want to delete this directory? (y/N)"
if ($ANSWER -eq "y") {
cd ..
Remove-Item -Recurse -Force -Path $REPO_NAME
}
exit
}
# プライベートリポジトリかどうかを判定
$IS_PRIVATE = (gh repo view --json isPrivate -q .isPrivate)
# リポジトリの種類によってURLを変更
$URL_PRIVATE = "https://raw.githubusercontent.com/book000/templates/master/renovate/private.json"
$URL_PUBLIC = "https://raw.githubusercontent.com/book000/templates/master/renovate/public.json"
$OUTPUT_FILE = "renovate.json"
# ブランチを切る(upstream/master, upstream/main, origin/master, origin/main の順番で存在するか確認し、存在するブランチをもとにブランチを切る)
git fetch -a --prune
$BRANCH_NAME = "chore/update-renovate-config"
git checkout -q -b $BRANCH_NAME --no-track upstream/master || git checkout -q -b $BRANCH_NAME --no-track upstream/main || git checkout -q -b $BRANCH_NAME --no-track origin/master || git checkout -q -b $BRANCH_NAME --no-track origin/main
# リポジトリの種類によってURLを変更し、設定ファイルをダウンロード
if ($IS_PRIVATE -eq $true) {
Write-Host "Private repository detected. Using private configuration."
Invoke-WebRequest -Uri $URL_PRIVATE -OutFile $OUTPUT_FILE
} else {
Write-Host "Public repository detected. Using public configuration."
Invoke-WebRequest -Uri $URL_PUBLIC -OutFile $OUTPUT_FILE
}
git add $OUTPUT_FILE
git commit -m "chore: update renovate config"
git push origin $BRANCH_NAME
gh repo set-default
gh pr create --title "chore: update renovate config" --body "- see book000/book000#27"
gh pr merge --auto --squash --delete-branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment