Skip to content

Commit

Permalink
enhance: code cleanup, moved netrc defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 committed Oct 24, 2024
1 parent 6efbf90 commit 9df0c04
Show file tree
Hide file tree
Showing 11 changed files with 258 additions and 181 deletions.
26 changes: 24 additions & 2 deletions compiler/native/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,30 @@ func (c *client) Compile(ctx context.Context, v interface{}) (*pipeline.Build, *
return nil, nil, err
}

// set git configurations after parsing them from the yaml configuration
c.WithGit(&p.Git)
// create the netrc using the scm
// this has to occur after Parse because the scm configurations might be set in yaml
// netrc can be provided directly using WithNetrc for situations like local exec
if c.netrc == nil && c.scm != nil {
// ensure restrictive defaults for the netrc for scms that support granular permissions
if p.Git.Repositories == nil {
p.Git.Repositories = []string{c.repo.GetName()}
}

if p.Git.Permissions == nil {
p.Git.Permissions = map[string]string{
"contents": "read",
"checks": "write",
}
}

// get the netrc password from the scm
netrc, err := c.scm.GetNetrcPassword(context.Background(), c.repo, c.user, p.Git.Repositories, p.Git.Permissions)
if err != nil {
return nil, nil, err
}

c.WithNetrc(netrc)
}

// create the API pipeline object from the yaml configuration
_pipeline := p.ToPipelineAPI()
Expand Down
Loading

0 comments on commit 9df0c04

Please sign in to comment.