diff options
author | 6543 <6543@obermui.de> | 2020-12-18 03:33:32 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-18 11:33:32 +0800 |
commit | e483220ea3c54137cec543842261f99c4696129a (patch) | |
tree | 2f81f173315b8ebe92403290977c09bfc32bf754 /models | |
parent | 27edc1aa19afb043a497a7dc628afa420cb1de55 (diff) | |
download | gitea-e483220ea3c54137cec543842261f99c4696129a.tar.gz gitea-e483220ea3c54137cec543842261f99c4696129a.zip |
[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 fix
Diffstat (limited to 'models')
-rw-r--r-- | models/commit_status.go | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/models/commit_status.go b/models/commit_status.go index 15fcbff6f9..9dffece378 100644 --- a/models/commit_status.go +++ b/models/commit_status.go @@ -38,7 +38,7 @@ type CommitStatus struct { UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` } -func (status *CommitStatus) loadRepo(e Engine) (err error) { +func (status *CommitStatus) loadAttributes(e Engine) (err error) { if status.Repo == nil { status.Repo, err = getRepositoryByID(e, status.RepoID) if err != nil { @@ -56,7 +56,7 @@ func (status *CommitStatus) loadRepo(e Engine) (err error) { // APIURL returns the absolute APIURL to this commit-status. func (status *CommitStatus) APIURL() string { - _ = status.loadRepo(x) + _ = status.loadAttributes(x) return fmt.Sprintf("%sapi/v1/repos/%s/statuses/%s", setting.AppURL, status.Repo.FullName(), status.SHA) } @@ -139,13 +139,20 @@ func sortCommitStatusesSession(sess *xorm.Session, sortType string) { } // GetLatestCommitStatus returns all statuses with a unique context for a given commit. -func GetLatestCommitStatus(repo *Repository, sha string, page int) ([]*CommitStatus, error) { +func GetLatestCommitStatus(repoID int64, sha string, listOptions ListOptions) ([]*CommitStatus, error) { + return getLatestCommitStatus(x, repoID, sha, listOptions) +} + +func getLatestCommitStatus(e Engine, repoID int64, sha string, listOptions ListOptions) ([]*CommitStatus, error) { ids := make([]int64, 0, 10) - err := x.Limit(10, page*10). - Table(&CommitStatus{}). - Where("repo_id = ?", repo.ID).And("sha = ?", sha). + sess := e.Table(&CommitStatus{}). + Where("repo_id = ?", repoID).And("sha = ?", sha). Select("max( id ) as id"). - GroupBy("context_hash").OrderBy("max( id ) desc").Find(&ids) + GroupBy("context_hash").OrderBy("max( id ) desc") + + sess = listOptions.setSessionPagination(sess) + + err := sess.Find(&ids) if err != nil { return nil, err } @@ -261,7 +268,7 @@ func ParseCommitsWithStatus(oldCommits *list.List, repo *Repository) *list.List commit := SignCommitWithStatuses{ SignCommit: &c, } - statuses, err := GetLatestCommitStatus(repo, commit.ID.String(), 0) + statuses, err := GetLatestCommitStatus(repo.ID, commit.ID.String(), ListOptions{}) if err != nil { log.Error("GetLatestCommitStatus: %v", err) } else { |