Skip to content

temporary scripts for branch maintenance#15488

Open
borinquenkid wants to merge 20 commits into7.0.xfrom
7.0.x-prune-branches
Open

temporary scripts for branch maintenance#15488
borinquenkid wants to merge 20 commits into7.0.xfrom
7.0.x-prune-branches

Conversation

@borinquenkid
Copy link
Member

Two tasks one to protect the release branches and another to delete stale branches

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Gradle-invokable maintenance automation for GitHub branch hygiene in apache/grails-core (protect release branches, delete stale branches) via two Groovy scripts executed from the root build.gradle.

Changes:

  • Registers two new Gradle maintenance tasks: deleteBranches and protectBranches.
  • Introduces ProtectBranches.groovy to apply GitHub branch protection to a curated list of release branches.
  • Introduces DeleteBranches.groovy to delete a curated list of merged/closed branches via the GitHub API.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 8 comments.

File Description
build.gradle Adds Gradle tasks that execute the maintenance Groovy scripts via GroovyShell.
ProtectBranches.groovy New script that calls GitHub’s branch protection API for listed branches.
DeleteBranches.groovy New script that calls GitHub’s refs API to delete listed branches.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

borinquenkid and others added 7 commits March 8, 2026 20:51
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

borinquenkid and others added 3 commits March 8, 2026 21:03
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 3 changed files in this pull request and generated 7 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

borinquenkid and others added 7 commits March 9, 2026 07:38
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@borinquenkid borinquenkid requested a review from Copilot March 9, 2026 12:44
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

*/
import groovy.json.JsonBuilder

// --- Configuration ---
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codebase style guidance discourages section-separator/grouping comments like // --- ... ---. Please remove this header comment to align with the repository conventions (see AGENTS.md guidance).

Copilot uses AI. Check for mistakes.
Comment on lines +24 to +27
if (!githubToken) {
throw new IllegalStateException(
"GitHub token is required. Set the GITHUB_TOKEN environment variable."
)
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exception text says only GITHUB_TOKEN is supported, but the script also reads System.getProperty('github.token') above. Update the message to mention -Dgithub.token as an alternative so users aren't misled when running locally/CI.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 3 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +139 to +144
if (conn.responseCode in [200, 201, 204]) {
println "SUCCESS: ${conn.responseCode}"
} else {
def errorText = conn.errorStream?.text ?: "No error stream available"
throw new RuntimeException("HTTP ${conn.responseCode} - ${errorText}")
}
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sendRequest currently treats a 404 as a hard failure. For branch protection maintenance, it’s common for some branches in the list to no longer exist; consider treating 404 as a skip (log and continue) so one missing branch doesn’t make the whole run fail.

Copilot uses AI. Check for mistakes.
Comment on lines +19 to +22
def githubToken = System.getenv('GITHUB_TOKEN') ?: System.getProperty('github.token')
def repoOwner = "apache"
def repoName = "grails-core"
def baseApiUrl = "https://api.github.com/repos/${repoOwner}/${repoName}"
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The target repository is hardcoded to apache/grails-core. That makes it easy to accidentally run this from a fork/clone and still delete branches on the upstream repo if the token has access. Make repoOwner/repoName configurable (env/Gradle properties) and/or require an explicit confirmation that prints the resolved target before proceeding.

Copilot uses AI. Check for mistakes.
Comment on lines +207 to +212
if (conn.responseCode in [200, 201, 204]) {
println "SUCCESS: ${conn.responseCode}"
} else {
def errorText = conn.errorStream?.text ?: "No error stream available"
throw new RuntimeException("HTTP ${conn.responseCode} - ${errorText}")
}
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sendRequest currently treats a 404 as a hard failure. For a branch-cleanup script, DELETE is typically intended to be idempotent (branch may already be gone), so consider treating 404 as a success/skip and continuing; otherwise the script can fail at the end due to already-deleted branches.

Copilot uses AI. Check for mistakes.
Comment on lines +21 to +24
def githubToken = System.getenv('GITHUB_TOKEN') ?: System.getProperty('github.token')
def repoOwner = "apache"
def repoName = "grails-core"
def baseApiUrl = "https://api.github.com/repos/${repoOwner}/${repoName}"
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The target repository is hardcoded to apache/grails-core. That makes it easy to accidentally run this from a fork/clone and still change branch protection on the upstream repo if the token has access. Make repoOwner/repoName configurable (env/Gradle properties) and/or require an explicit confirmation that prints the resolved target before proceeding.

Copilot uses AI. Check for mistakes.
Comment on lines +131 to +133
conn.setRequestProperty("Authorization", "token ${token}")
conn.setRequestProperty("Accept", "application/vnd.github.v3+json")
if (body) {
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitHub’s REST API requires a User-Agent header on requests; DeleteBranches.groovy sets one but this script doesn’t. Add a User-Agent request header here to avoid 403/400 responses from the API.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants