From b42255f3e7ceecdcfcf55ac91fcb90a4c39aa66b Mon Sep 17 00:00:00 2001 From: Theo Brigitte Date: Tue, 14 Apr 2026 18:48:49 +0200 Subject: [PATCH 1/3] Fix github repository setup to correctly detect and configure required checks --- cmd/repo/setup/flag.go | 2 +- pkg/githubclient/client_repository.go | 30 +++++++++++++-------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/cmd/repo/setup/flag.go b/cmd/repo/setup/flag.go index fee01df8f..c9c9f6734 100644 --- a/cmd/repo/setup/flag.go +++ b/cmd/repo/setup/flag.go @@ -67,7 +67,7 @@ func (f *flag) Init(cmd *cobra.Command) { cmd.Flags().StringVar(&f.DefaultBranch, "default-branch", "main", "Default branch name") cmd.Flags().BoolVar(&f.DisableBranchProtection, "disable-branch-protection", false, "Disable default branch protection") cmd.Flags().StringSliceVar(&f.Checks, "checks", nil, "Check context names for branch protection. Default will add all auto-detected checks, this can be disabled by passing an empty string. Overrides \"--checks-filter\"") - cmd.Flags().StringVar(&f.ChecksFilter, "checks-filter", "aliyun", "Provide a regex to filter checks. Checks matching the regex will be ignored. Empty string disables filter (all checks are accepted).") + cmd.Flags().StringVar(&f.ChecksFilter, "checks-filter", "create-release", "Provide a regex to filter checks. Checks matching the regex will be ignored. Empty string disables filter (all checks are accepted).") // Renovate cmd.Flags().BoolVar(&f.SetupRenovate, "renovate", true, "Sets up renovate for the repo") diff --git a/pkg/githubclient/client_repository.go b/pkg/githubclient/client_repository.go index 3b90da914..b922b3532 100644 --- a/pkg/githubclient/client_repository.go +++ b/pkg/githubclient/client_repository.go @@ -262,41 +262,41 @@ func (c *Client) getGithubChecks(ctx context.Context, repository *github.Reposit } c.logger.Debugf("get commit statuses for ref: %q", ref) - var allCombinedStatus []*github.CombinedStatus + // Fetch all check runs + var allCheckRuns []*github.CheckRun { - opt := &github.ListOptions{ - PerPage: 10, + opt := &github.ListCheckRunsOptions{ + ListOptions: github.ListOptions{ + PerPage: 10, + }, } underlyingClient := c.GetUnderlyingClient(ctx) for { - combinedStatus, resp, err := underlyingClient.Repositories.GetCombinedStatus(ctx, owner, repo, ref, opt) + listCheckRunsResults, resp, err := underlyingClient.Checks.ListCheckRunsForRef(ctx, owner, repo, ref, opt) if err != nil { return nil, microerror.Mask(err) } - allCombinedStatus = append(allCombinedStatus, combinedStatus) + + allCheckRuns = append(allCheckRuns, listCheckRunsResults.CheckRuns...) if resp.NextPage == 0 { break } opt.Page = resp.NextPage - } } + // List all check names and apply filter if needed. var checks []string - for _, combinedStatus := range allCombinedStatus { - for _, status := range combinedStatus.Statuses { - if checksFilter == nil || !checksFilter.MatchString(status.GetContext()) { - checks = append(checks, status.GetContext()) - } + for _, checkRun := range allCheckRuns { + check := checkRun.GetName() + if check != "" && (checksFilter == nil || !checksFilter.MatchString(check)) { + checks = append(checks, check) + c.logger.Debugf(" - status check found: %q", check) } } - c.logger.Debugf("found %d commit statuses for ref %q:", len(checks), ref) - for id, check := range checks { - c.logger.Debugf(" - checks[%d] = %q", id, check) - } return checks, nil } From 9ad76dceb8f49c6fa641f4754540803c7f774358 Mon Sep 17 00:00:00 2001 From: Theo Brigitte Date: Tue, 14 Apr 2026 18:49:22 +0200 Subject: [PATCH 2/3] Add comments --- pkg/githubclient/client_repository.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/githubclient/client_repository.go b/pkg/githubclient/client_repository.go index b922b3532..088839b99 100644 --- a/pkg/githubclient/client_repository.go +++ b/pkg/githubclient/client_repository.go @@ -117,6 +117,8 @@ func (c *Client) SetRepositorySettings(ctx context.Context, repository, reposito return repository, nil } +// SetRepositoryPermissions grants team permissions on the repository and +// sets the default workflow permission to "write" for GitHub Actions. func (c *Client) SetRepositoryPermissions(ctx context.Context, repository *github.Repository, permissions map[string]string) error { org := repository.GetOrganization().GetLogin() owner := repository.GetOwner().GetLogin() @@ -156,6 +158,9 @@ func (c *Client) SetRepositoryPermissions(ctx context.Context, repository *githu return nil } +// SetRepositoryBranchProtection configures branch protection rules on the +// default branch. If checkNames is nil, checks are auto-detected from recent +// CI runs and optionally filtered by checksFilter. func (c *Client) SetRepositoryBranchProtection(ctx context.Context, repository *github.Repository, checkNames []string, checksFilter *regexp.Regexp) (err error) { owner := repository.GetOwner().GetLogin() repo := repository.GetName() From b73a7f8e2863aa5fb8594425b91bb5390c42b3fb Mon Sep 17 00:00:00 2001 From: Theo Brigitte Date: Tue, 14 Apr 2026 18:51:52 +0200 Subject: [PATCH 3/3] Update changelog for repo setup fix --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b5fc41d84..5d89bf722 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [Unreleased] +### Fixed + +- `devctl repo setup`: Use check runs API instead of commit statuses to correctly detect required checks. Change default `--checks-filter` from `aliyun` to `create-release`. + ## [7.38.0] - 2026-04-14 ### Changed