Backport #36264 by wxiaoguang Fix #36253 Support slashes in `{ref}` (follow GitHub's behavior) Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
parent
7d010c6932
commit
163113d173
@ -1400,19 +1400,19 @@ func Routes() *web.Router {
|
|||||||
})
|
})
|
||||||
m.Get("/{base}/*", repo.GetPullRequestByBaseHead)
|
m.Get("/{base}/*", repo.GetPullRequestByBaseHead)
|
||||||
}, mustAllowPulls, reqRepoReader(unit.TypeCode), context.ReferencesGitRepo())
|
}, mustAllowPulls, reqRepoReader(unit.TypeCode), context.ReferencesGitRepo())
|
||||||
m.Group("/statuses", func() {
|
m.Group("/statuses", func() { // "/statuses/{sha}" only accepts commit ID
|
||||||
m.Combo("/{sha}").Get(repo.GetCommitStatuses).
|
m.Combo("/{sha}").Get(repo.GetCommitStatuses).
|
||||||
Post(reqToken(), reqRepoWriter(unit.TypeCode), bind(api.CreateStatusOption{}), repo.NewCommitStatus)
|
Post(reqToken(), reqRepoWriter(unit.TypeCode), bind(api.CreateStatusOption{}), repo.NewCommitStatus)
|
||||||
}, reqRepoReader(unit.TypeCode))
|
}, reqRepoReader(unit.TypeCode))
|
||||||
m.Group("/commits", func() {
|
m.Group("/commits", func() {
|
||||||
m.Get("", context.ReferencesGitRepo(), repo.GetAllCommits)
|
m.Get("", context.ReferencesGitRepo(), repo.GetAllCommits)
|
||||||
m.Group("/{ref}", func() {
|
m.PathGroup("/*", func(g *web.RouterPathGroup) {
|
||||||
m.Get("/status", repo.GetCombinedCommitStatusByRef)
|
// Mis-configured reverse proxy might decode the `%2F` to slash ahead, so we need to support both formats (escaped, unescaped) here.
|
||||||
m.Get("/statuses", repo.GetCommitStatusesByRef)
|
// It also matches GitHub's behavior
|
||||||
}, context.ReferencesGitRepo())
|
g.MatchPath("GET", "/<ref:*>/status", repo.GetCombinedCommitStatusByRef)
|
||||||
m.Group("/{sha}", func() {
|
g.MatchPath("GET", "/<ref:*>/statuses", repo.GetCommitStatusesByRef)
|
||||||
m.Get("/pull", repo.GetCommitPullRequest)
|
g.MatchPath("GET", "/<sha>/pull", repo.GetCommitPullRequest)
|
||||||
}, context.ReferencesGitRepo())
|
})
|
||||||
}, reqRepoReader(unit.TypeCode))
|
}, reqRepoReader(unit.TypeCode))
|
||||||
m.Group("/git", func() {
|
m.Group("/git", func() {
|
||||||
m.Group("/commits", func() {
|
m.Group("/commits", func() {
|
||||||
|
|||||||
@ -738,17 +738,8 @@ func doAutoPRMerge(baseCtx *APITestContext, dstPath string) func(t *testing.T) {
|
|||||||
|
|
||||||
commitID := path.Base(commitURL)
|
commitID := path.Base(commitURL)
|
||||||
|
|
||||||
addCommitStatus := func(status commitstatus.CommitStatusState) func(*testing.T) {
|
|
||||||
return doAPICreateCommitStatus(ctx, commitID, api.CreateStatusOption{
|
|
||||||
State: status,
|
|
||||||
TargetURL: "http://test.ci/",
|
|
||||||
Description: "",
|
|
||||||
Context: "testci",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Call API to add Pending status for commit
|
// Call API to add Pending status for commit
|
||||||
t.Run("CreateStatus", addCommitStatus(commitstatus.CommitStatusPending))
|
t.Run("CreateStatus", doAPICreateCommitStatusTest(ctx, commitID, commitstatus.CommitStatusPending, "testci"))
|
||||||
|
|
||||||
// Cancel not existing auto merge
|
// Cancel not existing auto merge
|
||||||
ctx.ExpectedCode = http.StatusNotFound
|
ctx.ExpectedCode = http.StatusNotFound
|
||||||
@ -777,7 +768,7 @@ func doAutoPRMerge(baseCtx *APITestContext, dstPath string) func(t *testing.T) {
|
|||||||
assert.False(t, pr.HasMerged)
|
assert.False(t, pr.HasMerged)
|
||||||
|
|
||||||
// Call API to add Failure status for commit
|
// Call API to add Failure status for commit
|
||||||
t.Run("CreateStatus", addCommitStatus(commitstatus.CommitStatusFailure))
|
t.Run("CreateStatus", doAPICreateCommitStatusTest(ctx, commitID, commitstatus.CommitStatusFailure, "testci"))
|
||||||
|
|
||||||
// Check pr status
|
// Check pr status
|
||||||
pr, err = doAPIGetPullRequest(ctx, baseCtx.Username, baseCtx.Reponame, pr.Index)(t)
|
pr, err = doAPIGetPullRequest(ctx, baseCtx.Username, baseCtx.Reponame, pr.Index)(t)
|
||||||
@ -785,8 +776,7 @@ func doAutoPRMerge(baseCtx *APITestContext, dstPath string) func(t *testing.T) {
|
|||||||
assert.False(t, pr.HasMerged)
|
assert.False(t, pr.HasMerged)
|
||||||
|
|
||||||
// Call API to add Success status for commit
|
// Call API to add Success status for commit
|
||||||
t.Run("CreateStatus", addCommitStatus(commitstatus.CommitStatusSuccess))
|
t.Run("CreateStatus", doAPICreateCommitStatusTest(ctx, commitID, commitstatus.CommitStatusSuccess, "testci"))
|
||||||
|
|
||||||
// wait to let gitea merge stuff
|
// wait to let gitea merge stuff
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
|
|
||||||
|
|||||||
@ -338,7 +338,7 @@ func NewRequestWithBody(t testing.TB, method, urlStr string, body io.Reader) *Re
|
|||||||
return &RequestWrapper{req}
|
return &RequestWrapper{req}
|
||||||
}
|
}
|
||||||
|
|
||||||
const NoExpectedStatus = -1
|
const NoExpectedStatus = 0
|
||||||
|
|
||||||
func MakeRequest(t testing.TB, rw *RequestWrapper, expectedStatus int) *httptest.ResponseRecorder {
|
func MakeRequest(t testing.TB, rw *RequestWrapper, expectedStatus int) *httptest.ResponseRecorder {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|||||||
@ -77,12 +77,7 @@ func TestPullCreate_CommitStatus(t *testing.T) {
|
|||||||
// Update commit status, and check if icon is updated as well
|
// Update commit status, and check if icon is updated as well
|
||||||
for _, status := range statusList {
|
for _, status := range statusList {
|
||||||
// Call API to add status for commit
|
// Call API to add status for commit
|
||||||
t.Run("CreateStatus", doAPICreateCommitStatus(testCtx, commitID, api.CreateStatusOption{
|
t.Run("CreateStatus", doAPICreateCommitStatusTest(testCtx, commitID, status, "testci"))
|
||||||
State: status,
|
|
||||||
TargetURL: "http://test.ci/",
|
|
||||||
Description: "",
|
|
||||||
Context: "testci",
|
|
||||||
}))
|
|
||||||
|
|
||||||
req = NewRequest(t, "GET", "/user1/repo1/pulls/1/commits")
|
req = NewRequest(t, "GET", "/user1/repo1/pulls/1/commits")
|
||||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||||
@ -104,19 +99,15 @@ func TestPullCreate_CommitStatus(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func doAPICreateCommitStatus(ctx APITestContext, commitID string, data api.CreateStatusOption) func(*testing.T) {
|
func doAPICreateCommitStatusTest(ctx APITestContext, ref string, state commitstatus.CommitStatusState, statusContext string) func(*testing.T) {
|
||||||
return func(t *testing.T) {
|
return func(t *testing.T) {
|
||||||
req := NewRequestWithJSON(
|
link := fmt.Sprintf("/api/v1/repos/%s/%s/statuses/%s", ctx.Username, ctx.Reponame, url.PathEscape(ref))
|
||||||
t,
|
req := NewRequestWithJSON(t, http.MethodPost, link, api.CreateStatusOption{
|
||||||
http.MethodPost,
|
State: state,
|
||||||
fmt.Sprintf("/api/v1/repos/%s/%s/statuses/%s", ctx.Username, ctx.Reponame, commitID),
|
TargetURL: "http://test.ci/",
|
||||||
data,
|
Context: statusContext,
|
||||||
).AddTokenAuth(ctx.Token)
|
}).AddTokenAuth(ctx.Token)
|
||||||
if ctx.ExpectedCode != 0 {
|
ctx.Session.MakeRequest(t, req, ctx.ExpectedCode)
|
||||||
ctx.Session.MakeRequest(t, req, ctx.ExpectedCode)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ctx.Session.MakeRequest(t, req, http.StatusCreated)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,12 +6,13 @@ package integration
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
|
||||||
"path"
|
"path"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
auth_model "code.gitea.io/gitea/models/auth"
|
auth_model "code.gitea.io/gitea/models/auth"
|
||||||
|
"code.gitea.io/gitea/models/db"
|
||||||
|
git_model "code.gitea.io/gitea/models/git"
|
||||||
"code.gitea.io/gitea/modules/commitstatus"
|
"code.gitea.io/gitea/modules/commitstatus"
|
||||||
"code.gitea.io/gitea/modules/json"
|
"code.gitea.io/gitea/modules/json"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
@ -20,6 +21,7 @@ import (
|
|||||||
|
|
||||||
"github.com/PuerkitoBio/goquery"
|
"github.com/PuerkitoBio/goquery"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRepoCommits(t *testing.T) {
|
func TestRepoCommits(t *testing.T) {
|
||||||
@ -79,98 +81,87 @@ func TestRepoCommits(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) {
|
func TestRepoCommitsWithStatus(t *testing.T) {
|
||||||
defer tests.PrepareTestEnv(t)()
|
defer tests.PrepareTestEnv(t)()
|
||||||
|
|
||||||
session := loginUser(t, "user2")
|
session := loginUser(t, "user2")
|
||||||
|
|
||||||
// Request repository commits page
|
|
||||||
req := NewRequest(t, "GET", "/user2/repo1/commits/branch/master")
|
|
||||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
|
||||||
|
|
||||||
doc := NewHTMLParser(t, resp.Body)
|
|
||||||
// Get first commit URL
|
|
||||||
commitURL, exists := doc.doc.Find("#commits-table .commit-id-short").Attr("href")
|
|
||||||
assert.True(t, exists)
|
|
||||||
assert.NotEmpty(t, commitURL)
|
|
||||||
|
|
||||||
// Call API to add status for commit
|
|
||||||
ctx := NewAPITestContext(t, "user2", "repo1", auth_model.AccessTokenScopeWriteRepository)
|
ctx := NewAPITestContext(t, "user2", "repo1", auth_model.AccessTokenScopeWriteRepository)
|
||||||
t.Run("CreateStatus", doAPICreateCommitStatus(ctx, path.Base(commitURL), api.CreateStatusOption{
|
|
||||||
State: commitstatus.CommitStatusState(state),
|
|
||||||
TargetURL: "http://test.ci/",
|
|
||||||
Description: "",
|
|
||||||
Context: "testci",
|
|
||||||
}))
|
|
||||||
|
|
||||||
req = NewRequest(t, "GET", "/user2/repo1/commits/branch/master")
|
requestCommitStatuses := func(t *testing.T, linkList, linkCombined string) (statuses []*api.CommitStatus, status api.CombinedStatus) {
|
||||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
assert.NoError(t, json.Unmarshal(session.MakeRequest(t, NewRequest(t, "GET", linkList), http.StatusOK).Body.Bytes(), &statuses))
|
||||||
|
assert.NoError(t, json.Unmarshal(session.MakeRequest(t, NewRequest(t, "GET", linkCombined), http.StatusOK).Body.Bytes(), &status))
|
||||||
doc = NewHTMLParser(t, resp.Body)
|
return statuses, status
|
||||||
// Check if commit status is displayed in message column (.tippy-target to ignore the tippy trigger)
|
|
||||||
sel := doc.doc.Find("#commits-table .message .tippy-target .commit-status")
|
|
||||||
assert.Equal(t, 1, sel.Length())
|
|
||||||
for _, class := range classes {
|
|
||||||
assert.True(t, sel.HasClass(class))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// By SHA
|
testRefMaster := func(t *testing.T, state commitstatus.CommitStatusState, classes ...string) {
|
||||||
req = NewRequest(t, "GET", "/api/v1/repos/user2/repo1/commits/"+path.Base(commitURL)+"/statuses")
|
_ = db.TruncateBeans(t.Context(), &git_model.CommitStatus{})
|
||||||
reqOne := NewRequest(t, "GET", "/api/v1/repos/user2/repo1/commits/"+path.Base(commitURL)+"/status")
|
|
||||||
testRepoCommitsWithStatus(t, session.MakeRequest(t, req, http.StatusOK), session.MakeRequest(t, reqOne, http.StatusOK), state)
|
|
||||||
|
|
||||||
// By short SHA
|
// Request repository commits page
|
||||||
req = NewRequest(t, "GET", "/api/v1/repos/user2/repo1/commits/"+path.Base(commitURL)[:10]+"/statuses")
|
req := NewRequest(t, "GET", "/user2/repo1/commits/branch/master")
|
||||||
reqOne = NewRequest(t, "GET", "/api/v1/repos/user2/repo1/commits/"+path.Base(commitURL)[:10]+"/status")
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
testRepoCommitsWithStatus(t, session.MakeRequest(t, req, http.StatusOK), session.MakeRequest(t, reqOne, http.StatusOK), state)
|
|
||||||
|
|
||||||
// By Ref
|
doc := NewHTMLParser(t, resp.Body)
|
||||||
req = NewRequest(t, "GET", "/api/v1/repos/user2/repo1/commits/master/statuses")
|
// Get first commit URL
|
||||||
reqOne = NewRequest(t, "GET", "/api/v1/repos/user2/repo1/commits/master/status")
|
commitURL, _ := doc.doc.Find("#commits-table .commit-id-short").Attr("href")
|
||||||
testRepoCommitsWithStatus(t, session.MakeRequest(t, req, http.StatusOK), session.MakeRequest(t, reqOne, http.StatusOK), state)
|
require.NotEmpty(t, commitURL)
|
||||||
req = NewRequest(t, "GET", "/api/v1/repos/user2/repo1/commits/v1.1/statuses")
|
commitID := path.Base(commitURL)
|
||||||
reqOne = NewRequest(t, "GET", "/api/v1/repos/user2/repo1/commits/v1.1/status")
|
|
||||||
testRepoCommitsWithStatus(t, session.MakeRequest(t, req, http.StatusOK), session.MakeRequest(t, reqOne, http.StatusOK), state)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testRepoCommitsWithStatus(t *testing.T, resp, respOne *httptest.ResponseRecorder, state string) {
|
// Call API to add status for commit
|
||||||
var statuses []*api.CommitStatus
|
doAPICreateCommitStatusTest(ctx, path.Base(commitURL), state, "testci")(t)
|
||||||
assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), &statuses))
|
|
||||||
var status api.CombinedStatus
|
|
||||||
assert.NoError(t, json.Unmarshal(respOne.Body.Bytes(), &status))
|
|
||||||
assert.NotNil(t, status)
|
|
||||||
|
|
||||||
if assert.Len(t, statuses, 1) {
|
req = NewRequest(t, "GET", "/user2/repo1/commits/branch/master")
|
||||||
assert.Equal(t, commitstatus.CommitStatusState(state), statuses[0].State)
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||||
assert.Equal(t, setting.AppURL+"api/v1/repos/user2/repo1/statuses/65f1bf27bc3bf70f64657658635e66094edbcb4d", statuses[0].URL)
|
|
||||||
assert.Equal(t, "http://test.ci/", statuses[0].TargetURL)
|
|
||||||
assert.Empty(t, statuses[0].Description)
|
|
||||||
assert.Equal(t, "testci", statuses[0].Context)
|
|
||||||
|
|
||||||
assert.Len(t, status.Statuses, 1)
|
doc = NewHTMLParser(t, resp.Body)
|
||||||
assert.Equal(t, statuses[0], status.Statuses[0])
|
// Check if commit status is displayed in message column (.tippy-target to ignore the tippy trigger)
|
||||||
assert.Equal(t, "65f1bf27bc3bf70f64657658635e66094edbcb4d", status.SHA)
|
sel := doc.doc.Find("#commits-table .message .tippy-target .commit-status")
|
||||||
|
assert.Equal(t, 1, sel.Length())
|
||||||
|
for _, class := range classes {
|
||||||
|
assert.True(t, sel.HasClass(class))
|
||||||
|
}
|
||||||
|
|
||||||
|
testRepoCommitsWithStatus := func(t *testing.T, linkList, linkCombined string, state commitstatus.CommitStatusState) {
|
||||||
|
statuses, status := requestCommitStatuses(t, linkList, linkCombined)
|
||||||
|
require.Len(t, statuses, 1)
|
||||||
|
require.NotNil(t, status)
|
||||||
|
|
||||||
|
assert.Equal(t, state, statuses[0].State)
|
||||||
|
assert.Equal(t, setting.AppURL+"api/v1/repos/user2/repo1/statuses/"+commitID, statuses[0].URL)
|
||||||
|
assert.Equal(t, "http://test.ci/", statuses[0].TargetURL)
|
||||||
|
assert.Empty(t, statuses[0].Description)
|
||||||
|
assert.Equal(t, "testci", statuses[0].Context)
|
||||||
|
|
||||||
|
assert.Len(t, status.Statuses, 1)
|
||||||
|
assert.Equal(t, statuses[0], status.Statuses[0])
|
||||||
|
assert.Equal(t, commitID, status.SHA)
|
||||||
|
}
|
||||||
|
// By SHA
|
||||||
|
testRepoCommitsWithStatus(t, "/api/v1/repos/user2/repo1/commits/"+commitID+"/statuses", "/api/v1/repos/user2/repo1/commits/"+commitID+"/status", state)
|
||||||
|
// By short SHA
|
||||||
|
testRepoCommitsWithStatus(t, "/api/v1/repos/user2/repo1/commits/"+commitID[:7]+"/statuses", "/api/v1/repos/user2/repo1/commits/"+commitID[:7]+"/status", state)
|
||||||
|
// By Ref
|
||||||
|
testRepoCommitsWithStatus(t, "/api/v1/repos/user2/repo1/commits/master/statuses", "/api/v1/repos/user2/repo1/commits/master/status", state)
|
||||||
|
// Tag "v1.1" points to master
|
||||||
|
testRepoCommitsWithStatus(t, "/api/v1/repos/user2/repo1/commits/v1.1/statuses", "/api/v1/repos/user2/repo1/commits/v1.1/status", state)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func TestRepoCommitsWithStatusPending(t *testing.T) {
|
t.Run("pending", func(t *testing.T) { testRefMaster(t, "pending", "octicon-dot-fill", "yellow") })
|
||||||
doTestRepoCommitWithStatus(t, "pending", "octicon-dot-fill", "yellow")
|
t.Run("success", func(t *testing.T) { testRefMaster(t, "success", "octicon-check", "green") })
|
||||||
}
|
t.Run("error", func(t *testing.T) { testRefMaster(t, "error", "gitea-exclamation", "red") })
|
||||||
|
t.Run("failure", func(t *testing.T) { testRefMaster(t, "failure", "octicon-x", "red") })
|
||||||
|
t.Run("warning", func(t *testing.T) { testRefMaster(t, "warning", "gitea-exclamation", "yellow") })
|
||||||
|
t.Run("BranchWithSlash", func(t *testing.T) {
|
||||||
|
_ = db.TruncateBeans(t.Context(), &git_model.CommitStatus{})
|
||||||
|
|
||||||
func TestRepoCommitsWithStatusSuccess(t *testing.T) {
|
linkList, linkCombined := "/api/v1/repos/user2/repo1/commits/feature%2F1/statuses", "/api/v1/repos/user2/repo1/commits/feature/1/status"
|
||||||
doTestRepoCommitWithStatus(t, "success", "octicon-check", "green")
|
statuses, status := requestCommitStatuses(t, linkList, linkCombined)
|
||||||
}
|
assert.Empty(t, statuses)
|
||||||
|
assert.Empty(t, status.Statuses)
|
||||||
func TestRepoCommitsWithStatusError(t *testing.T) {
|
doAPICreateCommitStatusTest(ctx, "feature/1", commitstatus.CommitStatusSuccess, "testci")(t)
|
||||||
doTestRepoCommitWithStatus(t, "error", "gitea-exclamation", "red")
|
statuses, status = requestCommitStatuses(t, linkList, linkCombined)
|
||||||
}
|
assert.NotEmpty(t, statuses)
|
||||||
|
assert.NotEmpty(t, status.Statuses)
|
||||||
func TestRepoCommitsWithStatusFailure(t *testing.T) {
|
})
|
||||||
doTestRepoCommitWithStatus(t, "failure", "octicon-x", "red")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRepoCommitsWithStatusWarning(t *testing.T) {
|
|
||||||
doTestRepoCommitWithStatus(t, "warning", "gitea-exclamation", "yellow")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRepoCommitsStatusParallel(t *testing.T) {
|
func TestRepoCommitsStatusParallel(t *testing.T) {
|
||||||
@ -194,13 +185,7 @@ func TestRepoCommitsStatusParallel(t *testing.T) {
|
|||||||
go func(parentT *testing.T, i int) {
|
go func(parentT *testing.T, i int) {
|
||||||
parentT.Run(fmt.Sprintf("ParallelCreateStatus_%d", i), func(t *testing.T) {
|
parentT.Run(fmt.Sprintf("ParallelCreateStatus_%d", i), func(t *testing.T) {
|
||||||
ctx := NewAPITestContext(t, "user2", "repo1", auth_model.AccessTokenScopeWriteRepository)
|
ctx := NewAPITestContext(t, "user2", "repo1", auth_model.AccessTokenScopeWriteRepository)
|
||||||
runBody := doAPICreateCommitStatus(ctx, path.Base(commitURL), api.CreateStatusOption{
|
doAPICreateCommitStatusTest(ctx, path.Base(commitURL), commitstatus.CommitStatusPending, "testci")(t)
|
||||||
State: commitstatus.CommitStatusPending,
|
|
||||||
TargetURL: "http://test.ci/",
|
|
||||||
Description: "",
|
|
||||||
Context: "testci",
|
|
||||||
})
|
|
||||||
runBody(t)
|
|
||||||
wg.Done()
|
wg.Done()
|
||||||
})
|
})
|
||||||
}(t, i)
|
}(t, i)
|
||||||
@ -225,20 +210,8 @@ func TestRepoCommitsStatusMultiple(t *testing.T) {
|
|||||||
|
|
||||||
// Call API to add status for commit
|
// Call API to add status for commit
|
||||||
ctx := NewAPITestContext(t, "user2", "repo1", auth_model.AccessTokenScopeWriteRepository)
|
ctx := NewAPITestContext(t, "user2", "repo1", auth_model.AccessTokenScopeWriteRepository)
|
||||||
t.Run("CreateStatus", doAPICreateCommitStatus(ctx, path.Base(commitURL), api.CreateStatusOption{
|
t.Run("CreateStatus", doAPICreateCommitStatusTest(ctx, path.Base(commitURL), commitstatus.CommitStatusSuccess, "testci"))
|
||||||
State: commitstatus.CommitStatusSuccess,
|
t.Run("CreateStatus", doAPICreateCommitStatusTest(ctx, path.Base(commitURL), commitstatus.CommitStatusSuccess, "other_context"))
|
||||||
TargetURL: "http://test.ci/",
|
|
||||||
Description: "",
|
|
||||||
Context: "testci",
|
|
||||||
}))
|
|
||||||
|
|
||||||
t.Run("CreateStatus", doAPICreateCommitStatus(ctx, path.Base(commitURL), api.CreateStatusOption{
|
|
||||||
State: commitstatus.CommitStatusSuccess,
|
|
||||||
TargetURL: "http://test.ci/",
|
|
||||||
Description: "",
|
|
||||||
Context: "other_context",
|
|
||||||
}))
|
|
||||||
|
|
||||||
req = NewRequest(t, "GET", "/user2/repo1/commits/branch/master")
|
req = NewRequest(t, "GET", "/user2/repo1/commits/branch/master")
|
||||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||||
|
|
||||||
|
|||||||
@ -934,12 +934,7 @@ func Test_WebhookStatus(t *testing.T) {
|
|||||||
testCtx := NewAPITestContext(t, "user2", "repo1", auth_model.AccessTokenScopeAll)
|
testCtx := NewAPITestContext(t, "user2", "repo1", auth_model.AccessTokenScopeAll)
|
||||||
|
|
||||||
// update a status for a commit via API
|
// update a status for a commit via API
|
||||||
doAPICreateCommitStatus(testCtx, commitID, api.CreateStatusOption{
|
doAPICreateCommitStatusTest(testCtx, commitID, commitstatus.CommitStatusSuccess, "testci")(t)
|
||||||
State: commitstatus.CommitStatusSuccess,
|
|
||||||
TargetURL: "http://test.ci/",
|
|
||||||
Description: "",
|
|
||||||
Context: "testci",
|
|
||||||
})(t)
|
|
||||||
|
|
||||||
// 3. validate the webhook is triggered
|
// 3. validate the webhook is triggered
|
||||||
assert.Equal(t, "status", triggeredEvent)
|
assert.Equal(t, "status", triggeredEvent)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user