diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/convert/convert.go | 21 | ||||
-rw-r--r-- | modules/convert/status.go | 56 | ||||
-rw-r--r-- | modules/gitgraph/graph_models.go | 2 | ||||
-rw-r--r-- | modules/structs/commit_status.go | 12 | ||||
-rw-r--r-- | modules/structs/status.go | 64 |
5 files changed, 84 insertions, 71 deletions
diff --git a/modules/convert/convert.go b/modules/convert/convert.go index f9f4a641e2..63dd072fc4 100644 --- a/modules/convert/convert.go +++ b/modules/convert/convert.go @@ -347,27 +347,6 @@ func ToOAuth2Application(app *models.OAuth2Application) *api.OAuth2Application { } } -// ToCommitStatus converts models.CommitStatus to api.Status -func ToCommitStatus(status *models.CommitStatus) *api.Status { - apiStatus := &api.Status{ - Created: status.CreatedUnix.AsTime(), - Updated: status.CreatedUnix.AsTime(), - State: api.StatusState(status.State), - TargetURL: status.TargetURL, - Description: status.Description, - ID: status.Index, - URL: status.APIURL(), - Context: status.Context, - } - - if status.CreatorID != 0 { - creator, _ := models.GetUserByID(status.CreatorID) - apiStatus.Creator = ToUser(creator, false, false) - } - - return apiStatus -} - // ToLFSLock convert a LFSLock to api.LFSLock func ToLFSLock(l *models.LFSLock) *api.LFSLock { return &api.LFSLock{ diff --git a/modules/convert/status.go b/modules/convert/status.go new file mode 100644 index 0000000000..f972fc333c --- /dev/null +++ b/modules/convert/status.go @@ -0,0 +1,56 @@ +// Copyright 2020 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package convert + +import ( + "code.gitea.io/gitea/models" + api "code.gitea.io/gitea/modules/structs" +) + +// ToCommitStatus converts models.CommitStatus to api.CommitStatus +func ToCommitStatus(status *models.CommitStatus) *api.CommitStatus { + apiStatus := &api.CommitStatus{ + Created: status.CreatedUnix.AsTime(), + Updated: status.CreatedUnix.AsTime(), + State: status.State, + TargetURL: status.TargetURL, + Description: status.Description, + ID: status.Index, + URL: status.APIURL(), + Context: status.Context, + } + + if status.CreatorID != 0 { + creator, _ := models.GetUserByID(status.CreatorID) + apiStatus.Creator = ToUser(creator, false, false) + } + + return apiStatus +} + +// ToCombinedStatus converts List of CommitStatus to a CombinedStatus +func ToCombinedStatus(statuses []*models.CommitStatus, repo *api.Repository) *api.CombinedStatus { + + if len(statuses) == 0 { + return nil + } + + retStatus := &api.CombinedStatus{ + SHA: statuses[0].SHA, + TotalCount: len(statuses), + Repository: repo, + URL: "", + } + + retStatus.Statuses = make([]*api.CommitStatus, 0, len(statuses)) + for _, status := range statuses { + retStatus.Statuses = append(retStatus.Statuses, ToCommitStatus(status)) + if status.State.NoBetterThan(retStatus.State) { + retStatus.State = status.State + } + } + + return retStatus +} diff --git a/modules/gitgraph/graph_models.go b/modules/gitgraph/graph_models.go index ba168ab19d..2ae38188a6 100644 --- a/modules/gitgraph/graph_models.go +++ b/modules/gitgraph/graph_models.go @@ -113,7 +113,7 @@ func (graph *Graph) LoadAndProcessCommits(repository *models.Repository, gitRepo _ = models.CalculateTrustStatus(c.Verification, repository, &keyMap) - statuses, err := models.GetLatestCommitStatus(repository, c.Commit.ID.String(), 0) + statuses, err := models.GetLatestCommitStatus(repository.ID, c.Commit.ID.String(), models.ListOptions{}) if err != nil { log.Error("GetLatestCommitStatus: %v", err) } else { diff --git a/modules/structs/commit_status.go b/modules/structs/commit_status.go index 397356b133..23e0c383b8 100644 --- a/modules/structs/commit_status.go +++ b/modules/structs/commit_status.go @@ -4,20 +4,20 @@ package structs -// CommitStatusState holds the state of a Status +// CommitStatusState holds the state of a CommitStatus // It can be "pending", "success", "error", "failure", and "warning" type CommitStatusState string const ( - // CommitStatusPending is for when the Status is Pending + // CommitStatusPending is for when the CommitStatus is Pending CommitStatusPending CommitStatusState = "pending" - // CommitStatusSuccess is for when the Status is Success + // CommitStatusSuccess is for when the CommitStatus is Success CommitStatusSuccess CommitStatusState = "success" - // CommitStatusError is for when the Status is Error + // CommitStatusError is for when the CommitStatus is Error CommitStatusError CommitStatusState = "error" - // CommitStatusFailure is for when the Status is Failure + // CommitStatusFailure is for when the CommitStatus is Failure CommitStatusFailure CommitStatusState = "failure" - // CommitStatusWarning is for when the Status is Warning + // CommitStatusWarning is for when the CommitStatus is Warning CommitStatusWarning CommitStatusState = "warning" ) diff --git a/modules/structs/status.go b/modules/structs/status.go index e833bd69e5..ed42b24be8 100644 --- a/modules/structs/status.go +++ b/modules/structs/status.go @@ -8,32 +8,15 @@ import ( "time" ) -// StatusState holds the state of a Status -// It can be "pending", "success", "error", "failure", and "warning" -type StatusState string - -const ( - // StatusPending is for when the Status is Pending - StatusPending StatusState = "pending" - // StatusSuccess is for when the Status is Success - StatusSuccess StatusState = "success" - // StatusError is for when the Status is Error - StatusError StatusState = "error" - // StatusFailure is for when the Status is Failure - StatusFailure StatusState = "failure" - // StatusWarning is for when the Status is Warning - StatusWarning StatusState = "warning" -) - -// Status holds a single Status of a single Commit -type Status struct { - ID int64 `json:"id"` - State StatusState `json:"status"` - TargetURL string `json:"target_url"` - Description string `json:"description"` - URL string `json:"url"` - Context string `json:"context"` - Creator *User `json:"creator"` +// CommitStatus holds a single status of a single Commit +type CommitStatus struct { + ID int64 `json:"id"` + State CommitStatusState `json:"status"` + TargetURL string `json:"target_url"` + Description string `json:"description"` + URL string `json:"url"` + Context string `json:"context"` + Creator *User `json:"creator"` // swagger:strfmt date-time Created time.Time `json:"created_at"` // swagger:strfmt date-time @@ -42,24 +25,19 @@ type Status struct { // CombinedStatus holds the combined state of several statuses for a single commit type CombinedStatus struct { - State StatusState `json:"state"` - SHA string `json:"sha"` - TotalCount int `json:"total_count"` - Statuses []*Status `json:"statuses"` - Repository *Repository `json:"repository"` - CommitURL string `json:"commit_url"` - URL string `json:"url"` + State CommitStatusState `json:"state"` + SHA string `json:"sha"` + TotalCount int `json:"total_count"` + Statuses []*CommitStatus `json:"statuses"` + Repository *Repository `json:"repository"` + CommitURL string `json:"commit_url"` + URL string `json:"url"` } -// CreateStatusOption holds the information needed to create a new Status for a Commit +// CreateStatusOption holds the information needed to create a new CommitStatus for a Commit type CreateStatusOption struct { - State StatusState `json:"state"` - TargetURL string `json:"target_url"` - Description string `json:"description"` - Context string `json:"context"` -} - -// ListStatusesOption holds pagination information -type ListStatusesOption struct { - Page int + State CommitStatusState `json:"state"` + TargetURL string `json:"target_url"` + Description string `json:"description"` + Context string `json:"context"` } |