Skip to content

Commit 94eec6a

Browse files
committed
Send policy PR to policy repo
Signed-off-by: Adolfo García Veytia (Puerco) <puerco@carabiner.dev>
1 parent 4537b37 commit 94eec6a

4 files changed

Lines changed: 24 additions & 4 deletions

File tree

sourcetool/internal/cmd/setup.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ func (so *setupCtlOpts) Validate() error {
199199
errs := []error{
200200
so.setupOpts.Validate(),
201201
}
202+
if len(so.configs) == 0 {
203+
errs = append(errs, fmt.Errorf("at least one config value must be set %v", sourcetool.ControlConfigurations))
204+
}
202205
for _, c := range so.configs {
203206
if !slices.Contains(sourcetool.ControlConfigurations, models.ControlConfiguration(c)) {
204207
errs = append(errs, fmt.Errorf("unknown configuration: %q", c))

sourcetool/pkg/repo/pullrequest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func (prm *PullRequestManager) PullRequestFileList(
108108
}
109109

110110
if err := prm.impl.PushFeatureBranch(&prm.Options, clone); err != nil {
111-
return nil, fmt.Errorf("pushing feature branch to remote")
111+
return nil, fmt.Errorf("pushing feature branch to remote: %w", err)
112112
}
113113

114114
// Use the base branch from the options, unless not set we use the default

sourcetool/pkg/sourcetool/implementation.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,29 @@ func (impl *defaultToolImplementation) CreatePolicyPR(a *auth.Authenticator, opt
105105

106106
// Create a pull request manager
107107
prManager := repo.NewPullRequestManager(repo.WithAuthenticator(a))
108+
prManager.Options.UseFork = true
108109

109-
// TODO(puerco): Honor forks settings, etc
110+
// Define the policy repo...
111+
policyRepoOwner := policy.SourcePolicyRepoOwner
112+
policyRepoName := policy.SourcePolicyRepo
113+
// ... but honor if there is one in the options
114+
if opts.PolicyRepo != "" {
115+
var ok bool
116+
policyRepoOwner, policyRepoName, ok = strings.Cut(opts.PolicyRepo, "/")
117+
if !ok {
118+
return nil, fmt.Errorf("invalid policy repository")
119+
}
120+
}
121+
122+
policyRepo := &models.Repository{
123+
Hostname: "github.com",
124+
Path: fmt.Sprintf("%s/%s", policyRepoOwner, policyRepoName),
125+
DefaultBranch: "main",
126+
}
110127

111128
// Open the pull request
112129
pr, err := prManager.PullRequestFileList(
113-
r,
130+
policyRepo,
114131
&roptions.PullRequestFileListOptions{
115132
Title: fmt.Sprintf("Add %s/%s SLSA Source policy file", repoOwner, repoName),
116133
Body: fmt.Sprintf(`This pull request adds the SLSA source policy for github.com/%s/%s`, repoOwner, repoName),

sourcetool/pkg/sourcetool/tool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func (t *Tool) CheckPolicyRepoFork(repo *models.Repository) (bool, error) {
173173

174174
// CreateBranchPolicy creates a repository policy
175175
func (t *Tool) CreateBranchPolicy(ctx context.Context, r *models.Repository, branches []*models.Branch) (*policy.RepoPolicy, error) {
176-
if len(branches) > 0 {
176+
if len(branches) > 1 {
177177
// Chanfe this once we support merging policies
178178
return nil, fmt.Errorf("only one branch is supported at a time")
179179
}

0 commit comments

Comments
 (0)