Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: sort by commit date #459

Merged
merged 3 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 2 additions & 1 deletion go/pkg/yolosvc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"context"
"crypto/subtle"
"fmt"
"google.golang.org/grpc/credentials/insecure"
"net"
"net/http"
"strings"
"time"

"google.golang.org/grpc/credentials/insecure"

"berty.tech/yolo/v2/go/pkg/yolopb"
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
Expand Down