Skip to content

Commit a7dbc60

Browse files
authored
feat: adds support for release-related policies (#6)
* feat: adds support for release-related policies Signed-off-by: Gustavo Carvalho <gustavo.carvalho@container-solutions.com> * fix: remove debug line * fix: remove evidenceJson Signed-off-by: Gustavo Carvalho <gustavo.carvalho@container-solutions.com> --------- Signed-off-by: Gustavo Carvalho <gustavo.carvalho@container-solutions.com>
1 parent dbff7cd commit a7dbc60

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

main.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type SaturatedRepository struct {
5454
// RequiredStatusChecks maps branch name -> required status checks configuration
5555
RequiredStatusChecks map[string]*github.RequiredStatusChecks `json:"required_status_checks"`
5656
SBOM *github.SBOM `json:"sbom"`
57+
LastRelease *github.RepositoryRelease `json:"last_release"`
5758
OpenPullRequests []*github.PullRequest `json:"pull_requests"`
5859
}
5960

@@ -175,13 +176,20 @@ func (l *GithubReposPlugin) Eval(req *proto.EvalRequest, apiHelper runner.ApiHel
175176
Status: proto.ExecutionStatus_FAILURE,
176177
}, err
177178
}
178-
179+
release, err := l.FecthLatestRelease(ctx, repo)
180+
if err != nil {
181+
l.Logger.Error("error gathering latest release", "error", err)
182+
return &proto.EvalResponse{
183+
Status: proto.ExecutionStatus_FAILURE,
184+
}, err
185+
}
179186
data := &SaturatedRepository{
180187
Settings: repo,
181188
Workflows: workflows,
182189
WorkflowRuns: workflowRuns,
183190
ProtectedBranches: branchNames,
184191
RequiredStatusChecks: requiredChecks,
192+
LastRelease: release,
185193
SBOM: sbom,
186194
OpenPullRequests: pullRequests,
187195
}
@@ -282,6 +290,23 @@ func (l *GithubReposPlugin) FetchRepositories(ctx context.Context, req *proto.Ev
282290
return repochan, errchan
283291
}
284292

293+
func (l *GithubReposPlugin) FecthLatestRelease(ctx context.Context, repo *github.Repository) (*github.RepositoryRelease, error) {
294+
owner := repo.GetOwner().GetLogin()
295+
name := repo.GetName()
296+
297+
release, resp, err := l.githubClient.Repositories.GetLatestRelease(ctx, owner, name)
298+
if err != nil {
299+
// If there is simply no release, GitHub returns 404. Treat this as "no release" rather than a hard error.
300+
if resp != nil && resp.Response != nil && resp.StatusCode == 404 {
301+
l.Logger.Trace("No releases found for repository", "repo", repo.GetFullName())
302+
return nil, nil
303+
}
304+
return nil, err
305+
}
306+
307+
return release, nil
308+
}
309+
285310
func (l *GithubReposPlugin) GatherConfiguredWorkflows(ctx context.Context, repo *github.Repository) ([]*github.Workflow, error) {
286311
workflows, _, err := l.githubClient.Actions.ListWorkflows(ctx, repo.GetOwner().GetLogin(), repo.GetName(), nil)
287312
if err != nil {

0 commit comments

Comments
 (0)