Skip to content

temporary scripts for branch maintenance#15488

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

temporary scripts for branch maintenance#15488
borinquenkid wants to merge 21 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.

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 +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.
@jdaugherty
Copy link
Contributor

It's my understanding that the protection logic can't be updated by us. We have to use .asf.yaml to set the protection. The issue is the asf.yaml process hasn't historically supported regex based protection rules - only specific branches. The reason for this is because the rest api does not support setting up this type of protections. Only the graphql library supports this. Have you researched this? Does asf.yaml still have this limitation? Maybe we could contribute to the ASF implementation to get this support so we can then define these in .asf.yaml.

@borinquenkid borinquenkid requested a review from Copilot March 11, 2026 13:43
@testlens-app
Copy link

testlens-app bot commented Mar 11, 2026

The TestLens GitHub App is installed in this repository but TestLens is currently in private beta.

Please contact us to finish onboarding this repository.

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.

Comment on lines +133 to +147
if (body) {
conn.doOutput = true
conn.setRequestProperty("Content-Type", "application/json")
conn.outputStream.withWriter { it << body }
}

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}")
}
} finally {
conn?.disconnect()
}
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

The response/error streams are never explicitly closed. With HttpURLConnection, leaving streams unclosed can leak resources and (in some JVMs) prevent clean connection teardown. Ensure input/error streams are read/closed (e.g., withCloseable) on both success and failure paths.

Copilot uses AI. Check for mistakes.
Comment on lines +201 to +215
if (body) {
conn.doOutput = true
conn.setRequestProperty("Content-Type", "application/json")
conn.outputStream.withWriter { it << body }
}

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}")
}
} finally {
conn?.disconnect()
}
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

Same as ProtectBranches.groovy: response/error streams aren’t explicitly closed. Close streams deterministically to avoid resource leaks and make failure modes more reliable.

Copilot uses AI. Check for mistakes.
Comment on lines +26 to +30
if (!githubToken || githubToken == "YOUR_PERSONAL_ACCESS_TOKEN") {
throw new IllegalStateException(
"GitHub token is required. Set the GITHUB_TOKEN environment variable or the -Dgithub.token system property."
)
}
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

The sentinel check against \"YOUR_PERSONAL_ACCESS_TOKEN\" looks like leftover scaffolding and is inconsistent with DeleteBranches.groovy (which only checks for presence). Either document the expected placeholder usage or remove this special-case to keep behavior consistent and predictable.

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.

3 participants