summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorAntoine GIRARD <sapk@users.noreply.github.com>2019-08-09 04:13:03 +0200
committerLunny Xiao <xiaolunwen@gmail.com>2019-08-09 10:13:03 +0800
commit2b6f45299d6e96b633a309d68055f9ae0699b8f2 (patch)
tree85ebd068cafb64fdd987b36541a9e743f0744f4c /models
parentc534b7e211d3264bbbde9b95cd8d6e9e60ad4215 (diff)
downloadgitea-2b6f45299d6e96b633a309d68055f9ae0699b8f2.tar.gz
gitea-2b6f45299d6e96b633a309d68055f9ae0699b8f2.zip
api: fix multiple bugs with statuses endpoints (#7785)
* fix commit statuses api url * search refs before passing sha * adjust tests * directly search tags and branches names + remove un-needed check in NewCommitStatus * fix comment * de-duplicate code * test: use relative setting.AppURL * Update routers/api/v1/repo/status.go Co-Authored-By: Lauris BH <lauris@nix.lv> * remove return * Update routers/api/v1/repo/status.go Co-Authored-By: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'models')
-rw-r--r--models/commit_status.go2
-rw-r--r--models/commit_status_test.go29
2 files changed, 18 insertions, 13 deletions
diff --git a/models/commit_status.go b/models/commit_status.go
index ecd319c5fe..e864dc3036 100644
--- a/models/commit_status.go
+++ b/models/commit_status.go
@@ -89,7 +89,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)
- return fmt.Sprintf("%sapi/v1/%s/statuses/%s",
+ return fmt.Sprintf("%sapi/v1/repos/%s/statuses/%s",
setting.AppURL, status.Repo.FullName(), status.SHA)
}
diff --git a/models/commit_status_test.go b/models/commit_status_test.go
index 580db127f6..97783ae6f1 100644
--- a/models/commit_status_test.go
+++ b/models/commit_status_test.go
@@ -20,20 +20,25 @@ func TestGetCommitStatuses(t *testing.T) {
statuses, maxResults, err := GetCommitStatuses(repo1, sha1, &CommitStatusOptions{})
assert.NoError(t, err)
assert.Equal(t, int(maxResults), 5)
- if assert.Len(t, statuses, 5) {
- assert.Equal(t, statuses[0].Context, "ci/awesomeness")
- assert.Equal(t, statuses[0].State, CommitStatusPending)
+ assert.Len(t, statuses, 5)
- assert.Equal(t, statuses[1].Context, "cov/awesomeness")
- assert.Equal(t, statuses[1].State, CommitStatusWarning)
+ assert.Equal(t, "ci/awesomeness", statuses[0].Context)
+ assert.Equal(t, CommitStatusPending, statuses[0].State)
+ assert.Equal(t, "https://try.gitea.io/api/v1/repos/user2/repo1/statuses/1234123412341234123412341234123412341234", statuses[0].APIURL())
- assert.Equal(t, statuses[2].Context, "cov/awesomeness")
- assert.Equal(t, statuses[2].State, CommitStatusSuccess)
+ assert.Equal(t, "cov/awesomeness", statuses[1].Context)
+ assert.Equal(t, CommitStatusWarning, statuses[1].State)
+ assert.Equal(t, "https://try.gitea.io/api/v1/repos/user2/repo1/statuses/1234123412341234123412341234123412341234", statuses[1].APIURL())
- assert.Equal(t, statuses[3].Context, "ci/awesomeness")
- assert.Equal(t, statuses[3].State, CommitStatusFailure)
+ assert.Equal(t, "cov/awesomeness", statuses[2].Context)
+ assert.Equal(t, CommitStatusSuccess, statuses[2].State)
+ assert.Equal(t, "https://try.gitea.io/api/v1/repos/user2/repo1/statuses/1234123412341234123412341234123412341234", statuses[2].APIURL())
- assert.Equal(t, statuses[4].Context, "deploy/awesomeness")
- assert.Equal(t, statuses[4].State, CommitStatusError)
- }
+ assert.Equal(t, "ci/awesomeness", statuses[3].Context)
+ assert.Equal(t, CommitStatusFailure, statuses[3].State)
+ assert.Equal(t, "https://try.gitea.io/api/v1/repos/user2/repo1/statuses/1234123412341234123412341234123412341234", statuses[3].APIURL())
+
+ assert.Equal(t, "deploy/awesomeness", statuses[4].Context)
+ assert.Equal(t, CommitStatusError, statuses[4].State)
+ assert.Equal(t, "https://try.gitea.io/api/v1/repos/user2/repo1/statuses/1234123412341234123412341234123412341234", statuses[4].APIURL())
}