summaryrefslogtreecommitdiffstats
path: root/models/status.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2017-04-24 22:33:54 +0800
committerGitHub <noreply@github.com>2017-04-24 22:33:54 +0800
commit3012971e92b79683178a286511c091fb31ee90f6 (patch)
tree7c691b872e3f53f4734e7650c1379b973affc037 /models/status.go
parenteb1075dd4cdeed4cacc17a9a4286254edb6bb4cd (diff)
downloadgitea-3012971e92b79683178a286511c091fb31ee90f6.tar.gz
gitea-3012971e92b79683178a286511c091fb31ee90f6.zip
fix bug on status API (#1533)
Diffstat (limited to 'models/status.go')
-rw-r--r--models/status.go21
1 files changed, 5 insertions, 16 deletions
diff --git a/models/status.go b/models/status.go
index c06dad822e..2e44ed93e6 100644
--- a/models/status.go
+++ b/models/status.go
@@ -139,18 +139,13 @@ func (status *CommitStatus) APIFormat() *api.Status {
// GetCommitStatuses returns all statuses for a given commit.
func GetCommitStatuses(repo *Repository, sha string, page int) ([]*CommitStatus, error) {
statuses := make([]*CommitStatus, 0, 10)
- sess := x.NewSession()
- defer sess.Close()
- return statuses, sess.Limit(10, page*10).Where("repo_id = ?", repo.ID).And("sha = ?", sha).Find(&statuses)
+ return statuses, x.Limit(10, page*10).Where("repo_id = ?", repo.ID).And("sha = ?", sha).Find(&statuses)
}
// GetLatestCommitStatus returns all statuses with a unique context for a given commit.
func GetLatestCommitStatus(repo *Repository, sha string, page int) ([]*CommitStatus, error) {
statuses := make([]*CommitStatus, 0, 10)
- sess := x.NewSession()
- defer sess.Close()
-
- return statuses, sess.Limit(10, page*10).
+ return statuses, x.Limit(10, page*10).
Where("repo_id = ?", repo.ID).And("sha = ?", sha).Select("*").
GroupBy("context").Desc("created_unix").Find(&statuses)
}
@@ -184,7 +179,7 @@ type NewCommitStatusOptions struct {
CommitStatus *CommitStatus
}
-func newCommitStatus(e Engine, opts NewCommitStatusOptions) error {
+func newCommitStatus(sess *xorm.Session, opts NewCommitStatusOptions) error {
opts.CommitStatus.Description = strings.TrimSpace(opts.CommitStatus.Description)
opts.CommitStatus.Context = strings.TrimSpace(opts.CommitStatus.Context)
opts.CommitStatus.TargetURL = strings.TrimSpace(opts.CommitStatus.TargetURL)
@@ -208,12 +203,6 @@ func newCommitStatus(e Engine, opts NewCommitStatusOptions) error {
return fmt.Errorf("GetCommit[%s]: %v", opts.SHA, err)
}
- sess := x.NewSession()
- defer sess.Close()
- if err = sess.Begin(); err != nil {
- return fmt.Errorf("newCommitStatus[%s, %s]: %v", opts.Repo.RepoPath(), opts.SHA, err)
- }
-
// Get the next Status Index
var nextIndex int64
lastCommitStatus := &CommitStatus{
@@ -238,7 +227,7 @@ func newCommitStatus(e Engine, opts NewCommitStatusOptions) error {
return fmt.Errorf("newCommitStatus[%s, %s]: %v", opts.Repo.RepoPath(), opts.SHA, err)
}
- return sess.Commit()
+ return nil
}
// NewCommitStatus creates a new CommitStatus given a bunch of parameters
@@ -261,5 +250,5 @@ func NewCommitStatus(repo *Repository, creator *User, sha string, status *Commit
return fmt.Errorf("NewCommitStatus[repo_id: %d, user_id: %d, sha: %s]: %v", repo.ID, creator.ID, sha, err)
}
- return nil
+ return sess.Commit()
}