-
Notifications
You must be signed in to change notification settings - Fork 374
Add push trigger on repository default branch for .github/workflows/*.md to agentic maintenance workflow generator
#28295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e57ed59
251618b
40b5c2b
90227ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,7 @@ import ( | |||||||||||||||||||
| "fmt" | ||||||||||||||||||||
| "os" | ||||||||||||||||||||
| "path/filepath" | ||||||||||||||||||||
| "strings" | ||||||||||||||||||||
|
|
||||||||||||||||||||
| "github.com/github/gh-aw/pkg/console" | ||||||||||||||||||||
| "github.com/github/gh-aw/pkg/logger" | ||||||||||||||||||||
|
|
@@ -83,11 +84,37 @@ func getCLICmdPrefix(actionMode ActionMode) string { | |||||||||||||||||||
| return "gh aw" | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // FetchDefaultBranch queries the GitHub API to determine the default branch of the | ||||||||||||||||||||
| // given repository slug (owner/repo). Returns "main" as a fallback when the slug is | ||||||||||||||||||||
| // empty, not in owner/repo format, or when the API call fails. | ||||||||||||||||||||
| func FetchDefaultBranch(slug string) string { | ||||||||||||||||||||
| const fallback = "main" | ||||||||||||||||||||
| if slug == "" || strings.Count(slug, "/") != 1 { | ||||||||||||||||||||
| maintenanceLog.Printf("No valid repository slug, using default branch fallback: %s", fallback) | ||||||||||||||||||||
| return fallback | ||||||||||||||||||||
| } | ||||||||||||||||||||
| maintenanceLog.Printf("Fetching default branch for repository: %s", slug) | ||||||||||||||||||||
| output, err := RunGH("Fetching default branch...", "api", "/repos/"+slug, "--jq", ".default_branch") | ||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||
| maintenanceLog.Printf("Failed to fetch default branch for %s: %v, falling back to %s", slug, err, fallback) | ||||||||||||||||||||
| return fallback | ||||||||||||||||||||
| } | ||||||||||||||||||||
| branch := strings.TrimSpace(string(output)) | ||||||||||||||||||||
| if branch == "" { | ||||||||||||||||||||
| maintenanceLog.Printf("Empty default branch response for %s, falling back to %s", slug, fallback) | ||||||||||||||||||||
| return fallback | ||||||||||||||||||||
| } | ||||||||||||||||||||
| maintenanceLog.Printf("Default branch for %s: %s", slug, branch) | ||||||||||||||||||||
| return branch | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // GenerateMaintenanceWorkflow generates the agentics-maintenance.yml workflow | ||||||||||||||||||||
| // if any workflows use the expires field for discussions or issues. | ||||||||||||||||||||
| // When repoConfig is non-nil and repoConfig.MaintenanceDisabled is true the | ||||||||||||||||||||
| // maintenance workflow is deleted and the function returns immediately. | ||||||||||||||||||||
| func GenerateMaintenanceWorkflow(workflowDataList []*WorkflowData, workflowDir string, version string, actionMode ActionMode, actionTag string, verbose bool, repoConfig *RepoConfig) error { | ||||||||||||||||||||
| // repoSlug is the owner/repo slug used to determine the default branch for the push | ||||||||||||||||||||
| // trigger; pass an empty string to fall back to "main". | ||||||||||||||||||||
| func GenerateMaintenanceWorkflow(workflowDataList []*WorkflowData, workflowDir string, version string, actionMode ActionMode, actionTag string, verbose bool, repoConfig *RepoConfig, repoSlug string) error { | ||||||||||||||||||||
| maintenanceLog.Print("Checking if maintenance workflow is needed") | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // Respect explicit opt-out from aw.json: maintenance: false | ||||||||||||||||||||
|
|
@@ -144,8 +171,12 @@ func GenerateMaintenanceWorkflow(workflowDataList []*WorkflowData, workflowDir s | |||||||||||||||||||
| cronSchedule, scheduleDesc := generateMaintenanceCron(minExpiresDays) | ||||||||||||||||||||
| maintenanceLog.Printf("Maintenance schedule: %s (%s)", cronSchedule, scheduleDesc) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // Fetch the default branch for the push trigger (dev mode only) | ||||||||||||||||||||
| // Resolved here to avoid passing it through multiple layers; empty slug falls back to "main" | ||||||||||||||||||||
| defaultBranch := FetchDefaultBranch(repoSlug) | ||||||||||||||||||||
|
Comment on lines
+174
to
+176
|
||||||||||||||||||||
| // Fetch the default branch for the push trigger (dev mode only) | |
| // Resolved here to avoid passing it through multiple layers; empty slug falls back to "main" | |
| defaultBranch := FetchDefaultBranch(repoSlug) | |
| // Fetch the default branch only when the dev-mode push trigger will be included. | |
| // Outside dev mode, leave it empty so generation does not depend on gh/api auth or network access. | |
| defaultBranch := "" | |
| if actionMode == ActionModeDev { | |
| defaultBranch = FetchDefaultBranch(repoSlug) | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition comment uses a typographic closing quote (
”) rather than an ASCII quote, which makes the example hard to read/copy and is inconsistent with the rest of the file. Consider changing it tooperation == ''(oroperation == "") to match the actual expression being built.