Browse Source
[Refactor] CombinedStatus and CommitStatus related functions & structs (#14026)
[Refactor] CombinedStatus and CommitStatus related functions & structs (#14026)
* RM unused struct * rename (*CommitStatus) loadRepo() -> loadAttributes() * move ToCommitStatus into its own file * use CommitStatusState instead of StatusState * move CombinedStatus convertion into convert package * let models.GetLatestCommitStatus use repoID direct and accept ListOptions * update swagger docs * fix tests * Fix swagger docs * rm page * fix swagger docs!!! * return json null * always return json * rename api.Status to api.CommitStatus * fix swagger docs * sec swagger fixmj-v1.14.3
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 341 additions and 206 deletions
-
2integrations/pull_status_test.go
-
6integrations/repo_commits_test.go
-
23models/commit_status.go
-
21modules/convert/convert.go
-
56modules/convert/status.go
-
2modules/gitgraph/graph_models.go
-
12modules/structs/commit_status.go
-
64modules/structs/status.go
-
54routers/api/v1/repo/status.go
-
21routers/api/v1/swagger/repo.go
-
2routers/repo/blame.go
-
2routers/repo/commit.go
-
4routers/repo/pull.go
-
2routers/repo/view.go
-
2services/pull/commit_status.go
-
2services/pull/pull.go
-
272templates/swagger/v1_json.tmpl
@ -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 |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue