Skip to content

Commit

Permalink
feat: sort by commit date (#459)
Browse files Browse the repository at this point in the history
  • Loading branch information
Doozers authored Sep 15, 2022
1 parent 0ff5fde commit aec7ff9
Show file tree
Hide file tree
Showing 6 changed files with 267 additions and 191 deletions.
3 changes: 3 additions & 0 deletions api/yolopb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ message BuildList {

// filter builds with merge requests
bool with_no_mergerequest = 14;

// sort by commit date
bool sort_by_commit_date = 15;
}
message Response {
repeated Build builds = 1;
Expand Down
2 changes: 1 addition & 1 deletion go/gen.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

423 changes: 233 additions & 190 deletions go/pkg/yolopb/yolopb.pb.go

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions go/pkg/yolostore/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package yolostore

import (
"fmt"
"sort"
"strings"

"berty.tech/yolo/v2/go/pkg/yolopb"
Expand Down Expand Up @@ -240,6 +241,7 @@ type GetBuildListOpts struct {
MergeRequestState []yolopb.MergeRequest_State
Branch []string
Limit int32
SortByCommitDate bool
}

// i.e, has_project=berty/berty -> has_project=https://github.com/berty/berty
Expand Down Expand Up @@ -384,6 +386,19 @@ func (s *store) GetBuildList(bl GetBuildListOpts) ([]*yolopb.Build, error) {
}
}

// sort by commit date
if bl.SortByCommitDate {
sort.Slice(builds, func(i, j int) bool {
if builds[i].HasCommit.CreatedAt == nil {
return false
}
if builds[j].HasCommit.CreatedAt == nil {
return true
}
return builds[i].HasCommit.CreatedAt.After(*builds[j].HasCommit.CreatedAt)
})
}

return builds, nil
}

Expand Down
1 change: 1 addition & 0 deletions go/pkg/yolosvc/api_buildlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func (svc *service) BuildList(ctx context.Context, req *yolopb.BuildList_Request
MergeRequestState: req.MergerequestState,
Branch: req.Branch,
Limit: req.Limit,
SortByCommitDate: req.SortByCommitDate,
}

var err error
Expand Down
14 changes: 14 additions & 0 deletions go/pkg/yolosvc/driver_github.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,8 @@ func (worker *githubWorker) batchFromWorkflowRun(run *github.WorkflowRun, prs []
updatedAt := run.GetUpdatedAt().Time
commitURL := run.GetHeadRepository().GetHTMLURL() + "/commit/" + run.GetHeadSHA()

commitCreatedAt := run.GetHeadCommit().GetTimestamp().Time

newBuild := yolopb.Build{
ID: run.GetHTMLURL(),
ShortID: fmt.Sprintf("%d", run.GetID()),
Expand All @@ -440,6 +442,17 @@ func (worker *githubWorker) batchFromWorkflowRun(run *github.WorkflowRun, prs []
Message: run.GetHeadCommit().GetMessage(),
}

newCommit := yolopb.Commit{}
if run.GetHeadCommit() != nil {
newCommit = yolopb.Commit{
ID: run.GetHeadCommit().GetID(),
CreatedAt: &commitCreatedAt,
Message: run.GetHeadCommit().GetMessage(),
Driver: yolopb.Driver_GitHub,
Branch: run.GetHeadBranch(),
}
}

if len(prs) > 0 {
pr := prs[0] // only take the first one
newBuild.HasMergerequestID = pr.GetHTMLURL()
Expand Down Expand Up @@ -495,6 +508,7 @@ func (worker *githubWorker) batchFromWorkflowRun(run *github.WorkflowRun, prs []

guessMissingBuildInfo(&newBuild)
batch.Builds = append(batch.Builds, &newBuild)
batch.Commits = append(batch.Commits, &newCommit)
return batch
}

Expand Down

0 comments on commit aec7ff9

Please sign in to comment.