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 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..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() @@ -262,41 +267,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 }