summaryrefslogtreecommitdiffstats
path: root/modules/convert
diff options
context:
space:
mode:
Diffstat (limited to 'modules/convert')
-rw-r--r--modules/convert/convert.go21
-rw-r--r--modules/convert/status.go56
2 files changed, 56 insertions, 21 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
+}