Replace checker.Commit with clients.Commit (#1950)

Co-authored-by: Azeem Shaikh <azeems@google.com>
This commit is contained in:
Azeem Shaikh 2022-05-24 16:11:37 -07:00 committed by GitHub
parent 96fac8a941
commit 25c7e1c7f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 101 additions and 460 deletions

View File

@ -15,8 +15,6 @@
package checker
import (
"time"
"github.com/ossf/scorecard/v4/clients"
)
@ -49,7 +47,7 @@ type FuzzingData struct {
// for the Maintained check.
type MaintainedData struct {
Issues []clients.Issue
DefaultBranchCommits []DefaultBranchCommit
DefaultBranchCommits []clients.Commit
ArchivedStatus ArchivedStatus
}
@ -62,12 +60,12 @@ type LicenseData struct {
// CodeReviewData contains the raw results
// for the Code-Review check.
type CodeReviewData struct {
DefaultBranchCommits []DefaultBranchCommit
DefaultBranchCommits []clients.Commit
}
// ContributorsData represents contributor information.
type ContributorsData struct {
Users []User
Users []clients.Contributor
}
// VulnerabilitiesData contains the raw results
@ -127,7 +125,7 @@ type Tool struct {
// Issues created by the tool.
Issues []clients.Issue
// Merge requests created by the tool.
MergeRequests []MergeRequest
MergeRequests []clients.PullRequest
// TODO: CodeCoverage, jsonWorkflowJob.
}
@ -138,93 +136,12 @@ type Run struct {
// TODO: add fields, e.g., Result=["success", "failure"]
}
// Comment represents a comment for a pull request or an issue.
type Comment struct {
CreatedAt *time.Time
Author *User
// TODO: add ields if needed, e.g., content.
}
// ArchivedStatus definess the archived status.
type ArchivedStatus struct {
Status bool
// TODO: add fields, e.g., date of archival.
}
// DefaultBranchCommit represents a commit
// to the default branch.
type DefaultBranchCommit struct {
// Fields below are taken directly from cloud
// version control systems, e.g. GitHub.
SHA string
CommitMessage string
MergeRequest *MergeRequest
CommitDate *time.Time
Committer User
}
// MergeRequest represents a merge request.
// nolint:govet
type MergeRequest struct {
Number int
Labels []string
Reviews []Review
Author User
MergedAt time.Time
}
// Review represent a review using the built-in review system.
type Review struct {
State string
Reviewer User
// TODO(Review): add fields here if needed.
}
// User represent a user.
type User struct {
RepoAssociation *RepoAssociation
Login string
// Orgnization refers to a GitHub org.
Organizations []Organization
// Companies refer to a claim by a user in their profile.
Companies []Company
NumContributions uint
}
// Organization represents a GitHub organization.
type Organization struct {
Login string
// TODO: other info.
}
// Company represents a company in a user's profile.
type Company struct {
Name string
// TODO: other info.
}
// RepoAssociation represents a user relationship with a repo.
type RepoAssociation string
const (
// RepoAssociationCollaborator has been invited to collaborate on the repository.
RepoAssociationCollaborator RepoAssociation = "collaborator"
// RepoAssociationContributor is an contributor to the repository.
RepoAssociationContributor RepoAssociation = "contributor"
// RepoAssociationOwner is an owner of the repository.
RepoAssociationOwner RepoAssociation = "owner"
// RepoAssociationMember is a member of the organization that owns the repository.
RepoAssociationMember RepoAssociation = "member"
// RepoAssociationFirstTimer has previously committed to the repository.
RepoAssociationFirstTimer RepoAssociation = "first-timer"
// RepoAssociationFirstTimeContributor has not previously committed to the repository.
RepoAssociationFirstTimeContributor RepoAssociation = "first-timer-contributor"
// RepoAssociationMannequin is a placeholder for an unclaimed user.
RepoAssociationMannequin RepoAssociation = "unknown"
// RepoAssociationNone has no association with the repository.
RepoAssociationNone RepoAssociation = "none"
)
// File represents a file.
type File struct {
Path string

View File

@ -61,7 +61,8 @@ func TestContributors(t *testing.T) {
name: "Valid contributors with enough contributors and companies",
contrib: []clients.Contributor{
{
Company: "company1",
Companies: []string{"company1"},
NumContributions: 10,
Organizations: []clients.User{
{
@ -73,7 +74,7 @@ func TestContributors(t *testing.T) {
},
},
{
Company: "company2",
Companies: []string{"company2"},
NumContributions: 10,
Organizations: []clients.User{
{
@ -85,7 +86,7 @@ func TestContributors(t *testing.T) {
},
},
{
Company: "company3",
Companies: []string{"company3"},
NumContributions: 10,
Organizations: []clients.User{
{
@ -97,7 +98,7 @@ func TestContributors(t *testing.T) {
},
},
{
Company: "company4",
Companies: []string{"company4"},
NumContributions: 10,
Organizations: []clients.User{
{
@ -109,7 +110,7 @@ func TestContributors(t *testing.T) {
},
},
{
Company: "company5",
Companies: []string{"company5"},
NumContributions: 10,
Organizations: []clients.User{
{
@ -121,7 +122,7 @@ func TestContributors(t *testing.T) {
},
},
{
Company: "company6",
Companies: []string{"company6"},
Organizations: []clients.User{
{
Login: "org1",

View File

@ -19,6 +19,7 @@ import (
"strings"
"github.com/ossf/scorecard/v4/checker"
"github.com/ossf/scorecard/v4/clients"
sce "github.com/ossf/scorecard/v4/errors"
)
@ -105,7 +106,7 @@ func isBot(name string) bool {
return false
}
func getApprovedReviewSystem(c *checker.DefaultBranchCommit, dl checker.DetailLogger) string {
func getApprovedReviewSystem(c *clients.Commit, dl checker.DetailLogger) string {
switch {
case isReviewedOnGitHub(c, dl):
return reviewPlatformGitHub
@ -121,9 +122,9 @@ func getApprovedReviewSystem(c *checker.DefaultBranchCommit, dl checker.DetailLo
return ""
}
func isReviewedOnGitHub(c *checker.DefaultBranchCommit, dl checker.DetailLogger) bool {
mr := c.MergeRequest
if mr == nil || mr.MergedAt.IsZero() {
func isReviewedOnGitHub(c *clients.Commit, dl checker.DetailLogger) bool {
mr := c.AssociatedMergeRequest
if mr.MergedAt.IsZero() {
return false
}
@ -152,7 +153,7 @@ func isReviewedOnGitHub(c *checker.DefaultBranchCommit, dl checker.DetailLogger)
return false
}
func isReviewedOnProw(c *checker.DefaultBranchCommit, dl checker.DetailLogger) bool {
func isReviewedOnProw(c *clients.Commit, dl checker.DetailLogger) bool {
if isBot(c.Committer.Login) {
dl.Debug(&checker.LogMessage{
Text: fmt.Sprintf("skip commit %s from bot account: %s", c.SHA, c.Committer.Login),
@ -160,12 +161,12 @@ func isReviewedOnProw(c *checker.DefaultBranchCommit, dl checker.DetailLogger) b
return true
}
if c.MergeRequest != nil && !c.MergeRequest.MergedAt.IsZero() {
for _, l := range c.MergeRequest.Labels {
if l == "lgtm" || l == "approved" {
if !c.AssociatedMergeRequest.MergedAt.IsZero() {
for _, l := range c.AssociatedMergeRequest.Labels {
if l.Name == "lgtm" || l.Name == "approved" {
dl.Debug(&checker.LogMessage{
Text: fmt.Sprintf("commit %s review was through %s #%d approved merge request",
c.SHA, reviewPlatformProw, c.MergeRequest.Number),
c.SHA, reviewPlatformProw, c.AssociatedMergeRequest.Number),
})
return true
}
@ -174,7 +175,7 @@ func isReviewedOnProw(c *checker.DefaultBranchCommit, dl checker.DetailLogger) b
return false
}
func isReviewedOnGerrit(c *checker.DefaultBranchCommit, dl checker.DetailLogger) bool {
func isReviewedOnGerrit(c *clients.Commit, dl checker.DetailLogger) bool {
if isBot(c.Committer.Login) {
dl.Debug(&checker.LogMessage{
Text: fmt.Sprintf("skip commit %s from bot account: %s", c.SHA, c.Committer.Login),
@ -182,7 +183,7 @@ func isReviewedOnGerrit(c *checker.DefaultBranchCommit, dl checker.DetailLogger)
return true
}
m := c.CommitMessage
m := c.Message
if strings.Contains(m, "\nReviewed-on: ") &&
strings.Contains(m, "\nReviewed-by: ") {
dl.Debug(&checker.LogMessage{
@ -193,7 +194,7 @@ func isReviewedOnGerrit(c *checker.DefaultBranchCommit, dl checker.DetailLogger)
return false
}
func isReviewedOnPhabricator(c *checker.DefaultBranchCommit, dl checker.DetailLogger) bool {
func isReviewedOnPhabricator(c *clients.Commit, dl checker.DetailLogger) bool {
if isBot(c.Committer.Login) {
dl.Debug(&checker.LogMessage{
Text: fmt.Sprintf("skip commit %s from bot account: %s", c.SHA, c.Committer.Login),
@ -201,7 +202,7 @@ func isReviewedOnPhabricator(c *checker.DefaultBranchCommit, dl checker.DetailLo
return true
}
m := c.CommitMessage
m := c.Message
if strings.Contains(m, "\nDifferential Revision: ") &&
strings.Contains(m, "\nReviewed By: ") {
dl.Debug(&checker.LogMessage{
@ -212,8 +213,8 @@ func isReviewedOnPhabricator(c *checker.DefaultBranchCommit, dl checker.DetailLo
return false
}
func isReviewedOnPiper(c *checker.DefaultBranchCommit, dl checker.DetailLogger) bool {
m := c.CommitMessage
func isReviewedOnPiper(c *clients.Commit, dl checker.DetailLogger) bool {
m := c.Message
if strings.Contains(m, "\nPiperOrigin-RevId: ") {
dl.Debug(&checker.LogMessage{
Text: fmt.Sprintf("commit %s was approved through %s", c.SHA, reviewPlatformPiper),

View File

@ -18,6 +18,7 @@ import (
"testing"
"github.com/ossf/scorecard/v4/checker"
"github.com/ossf/scorecard/v4/clients"
sce "github.com/ossf/scorecard/v4/errors"
scut "github.com/ossf/scorecard/v4/utests"
)
@ -53,7 +54,7 @@ func TestCodeReview(t *testing.T) {
NumberOfWarn: 2,
},
rawData: &checker.CodeReviewData{
DefaultBranchCommits: []checker.DefaultBranchCommit{
DefaultBranchCommits: []clients.Commit{
{
SHA: "1",
},

View File

@ -49,7 +49,7 @@ func Contributors(name string, dl checker.DetailLogger,
}
for _, comp := range user.Companies {
entities[comp.Name] = true
entities[comp] = true
}
}

View File

@ -44,7 +44,7 @@ func Maintained(name string, dl checker.DetailLogger, r *checker.MaintainedData)
threshold := time.Now().AddDate(0 /*years*/, 0 /*months*/, -1*lookBackDays /*days*/)
commitsWithinThreshold := 0
for i := range r.DefaultBranchCommits {
if r.DefaultBranchCommits[i].CommitDate.After(threshold) {
if r.DefaultBranchCommits[i].CommittedDate.After(threshold) {
commitsWithinThreshold++
}
}

View File

@ -23,70 +23,13 @@ import (
// CodeReview retrieves the raw data for the Code-Review check.
func CodeReview(c clients.RepoClient) (checker.CodeReviewData, error) {
results := []checker.DefaultBranchCommit{}
// Look at the latest commits.
commits, err := c.ListCommits()
if err != nil {
return checker.CodeReviewData{}, fmt.Errorf("%w", err)
}
for i := range commits {
results = append(results, getRawDataFromCommit(&commits[i]))
}
return checker.CodeReviewData{DefaultBranchCommits: results}, nil
}
func getRawDataFromCommit(c *clients.Commit) checker.DefaultBranchCommit {
r := checker.DefaultBranchCommit{
Committer: checker.User{
Login: c.Committer.Login,
},
SHA: c.SHA,
CommitMessage: c.Message,
CommitDate: &c.CommittedDate,
MergeRequest: mergeRequest(&c.AssociatedMergeRequest),
}
return r
}
func mergeRequest(mr *clients.PullRequest) *checker.MergeRequest {
r := checker.MergeRequest{
Number: mr.Number,
Author: checker.User{
Login: mr.Author.Login,
},
MergedAt: mr.MergedAt,
Labels: labels(mr),
Reviews: reviews(mr),
}
return &r
}
func labels(mr *clients.PullRequest) []string {
labels := []string{}
for _, l := range mr.Labels {
labels = append(labels, l.Name)
}
return labels
}
func reviews(mr *clients.PullRequest) []checker.Review {
reviews := []checker.Review{}
for _, m := range mr.Reviews {
r := checker.Review{
State: m.State,
}
if m.Author != nil &&
m.Author.Login != "" {
r.Reviewer = checker.User{
Login: m.Author.Login,
}
}
reviews = append(reviews, r)
}
return reviews
return checker.CodeReviewData{
DefaultBranchCommits: commits,
}, nil
}

View File

@ -16,9 +16,7 @@ package raw
import (
"errors"
"reflect"
"testing"
"time"
"github.com/golang/mock/gomock"
"github.com/google/go-cmp/cmp"
@ -28,212 +26,6 @@ import (
mockrepo "github.com/ossf/scorecard/v4/clients/mockclients"
)
// Test_reviews tests the reviews function.
func Test_reviews(t *testing.T) {
t.Parallel()
type args struct {
mr *clients.PullRequest
}
tests := []struct {
name string
args args
want []checker.Review
}{
{
name: "Test_reviews",
args: args{
mr: &clients.PullRequest{
Reviews: []clients.Review{},
},
},
want: []checker.Review{},
},
{
name: "Test_reviews",
args: args{
mr: &clients.PullRequest{
Reviews: []clients.Review{
{
State: "APPROVED",
Author: &clients.User{
Login: "user",
},
},
{
State: "APPROVED",
Author: &clients.User{
Login: "user",
},
},
},
},
},
want: []checker.Review{
{
Reviewer: checker.User{
Login: "user",
},
State: "APPROVED",
},
{
Reviewer: checker.User{
Login: "user",
},
State: "APPROVED",
},
},
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := reviews(tt.args.mr); !reflect.DeepEqual(got, tt.want) {
t.Errorf("reviews() = %v, want %v", got, tt.want)
}
})
}
}
// Test_labels tests the labels function.
func Test_labels(t *testing.T) {
t.Parallel()
type args struct {
mr *clients.PullRequest
}
tests := []struct {
name string
args args
want []string
}{
{
name: "Test_labels",
args: args{
mr: &clients.PullRequest{
Labels: []clients.Label{},
},
},
want: []string{},
},
{
name: "Test_labels",
args: args{
mr: &clients.PullRequest{
Labels: []clients.Label{
{
Name: "label",
},
{
Name: "label",
},
},
},
},
want: []string{"label", "label"},
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := labels(tt.args.mr); !reflect.DeepEqual(got, tt.want) {
t.Errorf("labels() = %v, want %v", got, tt.want)
}
})
}
}
// Test_mergeRequest tests the mergeRequest function.
func Test_mergeRequest(t *testing.T) {
t.Parallel()
type args struct {
mr *clients.PullRequest
}
//nolint
tests := []struct {
name string
args args
want *checker.MergeRequest
}{
{
name: "Test_mergeRequest",
args: args{
mr: &clients.PullRequest{
MergedAt: time.Time{},
HeadSHA: "sha",
Labels: []clients.Label{
{
Name: "label",
},
{
Name: "label",
},
},
},
},
want: &checker.MergeRequest{
MergedAt: time.Time{},
Labels: []string{"label", "label"},
Author: checker.User{},
Reviews: []checker.Review{},
},
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := mergeRequest(tt.args.mr); !cmp.Equal(got, tt.want) {
t.Errorf("mergeRequest() = %+v, want %+v", got, tt.want)
}
})
}
}
// Test_getRawDataFromCommit tests the getRawDataFromCommit function.
func Test_getRawDataFromCommit(t *testing.T) {
t.Parallel()
type args struct {
c *clients.Commit
}
tests := []struct {
name string
args args
want checker.DefaultBranchCommit
}{
{
name: "Test_getRawDataFromCommit",
args: args{
c: &clients.Commit{
CommittedDate: time.Time{},
Message: "message",
SHA: "sha",
},
},
want: checker.DefaultBranchCommit{
SHA: "sha",
CommitMessage: "message",
CommitDate: &time.Time{},
MergeRequest: &checker.MergeRequest{
Labels: []string{},
Reviews: []checker.Review{},
},
},
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := getRawDataFromCommit(tt.args.c); !cmp.Equal(got, tt.want) {
t.Errorf(cmp.Diff(got, tt.want))
}
})
}
}
// TestCodeReviews tests the CodeReviews function.
func TestCodeReview(t *testing.T) {
t.Parallel()
@ -257,12 +49,12 @@ func TestCodeReview(t *testing.T) {
t.Parallel()
ctrl := gomock.NewController(t)
mr := mockrepo.NewMockRepoClient(ctrl)
mr.EXPECT().ListCommits().DoAndReturn(func() ([]*clients.Commit, error) {
mr.EXPECT().ListCommits().DoAndReturn(func() ([]clients.Commit, error) {
if tt.wantErr {
//nolint
return nil, errors.New("error")
}
return []*clients.Commit{
return []clients.Commit{
{
SHA: "sha",
},

View File

@ -24,7 +24,7 @@ import (
// Contributors retrieves the raw data for the Contributors check.
func Contributors(c clients.RepoClient) (checker.ContributorsData, error) {
var users []checker.User
var users []clients.Contributor
contribs, err := c.ListContributors()
if err != nil {
@ -32,23 +32,21 @@ func Contributors(c clients.RepoClient) (checker.ContributorsData, error) {
}
for _, contrib := range contribs {
user := checker.User{
Login: contrib.User.Login,
NumContributions: uint(contrib.NumContributions),
user := clients.Contributor{
User: contrib.User,
NumContributions: contrib.NumContributions,
}
for _, org := range contrib.Organizations {
if org.Login != "" && !orgContains(user.Organizations, org.Login) {
user.Organizations = append(user.Organizations,
checker.Organization{
Login: org.Login,
},
)
user.Organizations = append(user.Organizations, org)
}
}
company := contrib.Company
if company != "" {
for _, company := range contrib.Companies {
if company == "" {
continue
}
company = strings.ToLower(company)
company = strings.ReplaceAll(company, "inc.", "")
company = strings.ReplaceAll(company, "llc", "")
@ -56,11 +54,7 @@ func Contributors(c clients.RepoClient) (checker.ContributorsData, error) {
company = strings.TrimLeft(company, "@")
company = strings.Trim(company, " ")
if company != "" && !companyContains(user.Companies, company) {
user.Companies = append(user.Companies,
checker.Company{
Name: company,
},
)
user.Companies = append(user.Companies, company)
}
}
@ -70,16 +64,16 @@ func Contributors(c clients.RepoClient) (checker.ContributorsData, error) {
return checker.ContributorsData{Users: users}, nil
}
func companyContains(cs []checker.Company, name string) bool {
func companyContains(cs []string, name string) bool {
for _, a := range cs {
if a.Name == name {
if a == name {
return true
}
}
return false
}
func orgContains(os []checker.Organization, login string) bool {
func orgContains(os []clients.User, login string) bool {
for _, a := range os {
if a.Login == login {
return true

View File

@ -36,12 +36,7 @@ func Maintained(c *checker.CheckRequest) (checker.MaintainedData, error) {
if err != nil {
return result, fmt.Errorf("%w", err)
}
for i := range commits {
// Note: getRawDataFromCommit() is defined in Code-Review check.
result.DefaultBranchCommits = append(result.DefaultBranchCommits,
getRawDataFromCommit(&commits[i]))
}
result.DefaultBranchCommits = commits
// Recent issues.
issues, err := c.RepoClient.ListIssues()

View File

@ -16,7 +16,7 @@ package clients
// Contributor represents a contributor to a repo.
type Contributor struct {
Company string
Companies []string
User User
Organizations []User
NumContributions int

View File

@ -77,7 +77,7 @@ func (handler *contributorsHandler) setup() error {
if err != nil {
handler.errSetup = fmt.Errorf("error during Users.Get: %w", err)
}
contributor.Company = user.GetCompany()
contributor.Companies = append(contributor.Companies, user.GetCompany())
handler.contributors = append(handler.contributors, contributor)
}
handler.errSetup = nil

View File

@ -124,36 +124,34 @@ func addCodeReviewRawResults(r *jsonScorecardRawResult, cr *checker.CodeReviewDa
Committer: jsonUser{
Login: commit.Committer.Login,
},
CommitMessage: commit.CommitMessage,
CommitMessage: commit.Message,
SHA: commit.SHA,
}
// Merge request field.
if commit.MergeRequest != nil {
mr := jsonMergeRequest{
Number: commit.MergeRequest.Number,
Author: jsonUser{
Login: commit.MergeRequest.Author.Login,
},
}
if len(commit.MergeRequest.Labels) > 0 {
mr.Labels = commit.MergeRequest.Labels
}
for _, r := range commit.MergeRequest.Reviews {
mr.Reviews = append(mr.Reviews, jsonReview{
State: r.State,
Reviewer: jsonUser{
Login: r.Reviewer.Login,
},
})
}
com.MergeRequest = &mr
mr := jsonMergeRequest{
Number: commit.AssociatedMergeRequest.Number,
Author: jsonUser{
Login: commit.AssociatedMergeRequest.Author.Login,
},
}
com.CommitMessage = commit.CommitMessage
for _, l := range commit.AssociatedMergeRequest.Labels {
mr.Labels = append(mr.Labels, l.Name)
}
for _, r := range commit.AssociatedMergeRequest.Reviews {
mr.Reviews = append(mr.Reviews, jsonReview{
State: r.State,
Reviewer: jsonUser{
Login: r.Author.Login,
},
})
}
com.MergeRequest = &mr
com.CommitMessage = commit.Message
r.Results.DefaultBranchCommits = append(r.Results.DefaultBranchCommits, com)
}

View File

@ -21,6 +21,7 @@ import (
"time"
"github.com/ossf/scorecard/v4/checker"
"github.com/ossf/scorecard/v4/clients"
sce "github.com/ossf/scorecard/v4/errors"
)
@ -82,7 +83,7 @@ type jsonUser struct {
Organizations []jsonOrganization `json:"organization,omitempty"`
// Companies refer to a claim by a user in their profile.
Companies []jsonCompany `json:"company,omitempty"`
NumContributions uint `json:"NumContributions"`
NumContributions int `json:"NumContributions"`
}
type jsonContributors struct {
@ -246,7 +247,7 @@ func (r *jsonScorecardRawResult) addContributorsRawResults(cr *checker.Contribut
for _, user := range cr.Users {
u := jsonUser{
Login: user.Login,
Login: user.User.Login,
NumContributions: user.NumContributions,
}
@ -261,7 +262,7 @@ func (r *jsonScorecardRawResult) addContributorsRawResults(cr *checker.Contribut
for _, comp := range user.Companies {
u.Companies = append(u.Companies,
jsonCompany{
Name: comp.Name,
Name: comp,
},
)
}
@ -338,7 +339,7 @@ func getStrPtr(s string) *string {
}
// Function shared between addMaintainedRawResults() and addCodeReviewRawResults().
func (r *jsonScorecardRawResult) setDefaultCommitData(commits []checker.DefaultBranchCommit) error {
func (r *jsonScorecardRawResult) setDefaultCommitData(commits []clients.Commit) error {
if len(r.Results.DefaultBranchCommits) > 0 {
return nil
}
@ -353,36 +354,34 @@ func (r *jsonScorecardRawResult) setDefaultCommitData(commits []checker.DefaultB
// try to use issue information to set it, but we're likely to miss
// many anyway.
},
CommitMessage: commit.CommitMessage,
CommitMessage: commit.Message,
SHA: commit.SHA,
}
// Merge request field.
if commit.MergeRequest != nil {
mr := jsonMergeRequest{
Number: commit.MergeRequest.Number,
Author: jsonUser{
Login: commit.MergeRequest.Author.Login,
},
}
if len(commit.MergeRequest.Labels) > 0 {
mr.Labels = commit.MergeRequest.Labels
}
for _, r := range commit.MergeRequest.Reviews {
mr.Reviews = append(mr.Reviews, jsonReview{
State: r.State,
Reviewer: jsonUser{
Login: r.Reviewer.Login,
},
})
}
com.MergeRequest = &mr
mr := jsonMergeRequest{
Number: commit.AssociatedMergeRequest.Number,
Author: jsonUser{
Login: commit.AssociatedMergeRequest.Author.Login,
},
}
com.CommitMessage = commit.CommitMessage
for _, l := range commit.AssociatedMergeRequest.Labels {
mr.Labels = append(mr.Labels, l.Name)
}
for _, r := range commit.AssociatedMergeRequest.Reviews {
mr.Reviews = append(mr.Reviews, jsonReview{
State: r.State,
Reviewer: jsonUser{
Login: r.Author.Login,
},
})
}
com.MergeRequest = &mr
com.CommitMessage = commit.Message
r.Results.DefaultBranchCommits = append(r.Results.DefaultBranchCommits, com)
}