mirror of
https://github.com/go-gitea/gitea.git
synced 2026-04-04 14:36:16 +02:00
fix broken hooks
This commit is contained in:
parent
96de1004e6
commit
6c08c3d17c
@ -474,7 +474,7 @@ func TestActionsGiteaContext(t *testing.T) {
|
||||
|
||||
apiBaseRepo := createActionsTestRepo(t, user2Token, "actions-gitea-context", false)
|
||||
baseRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: apiBaseRepo.ID})
|
||||
user2APICtx := NewAPITestContext(t, baseRepo.OwnerName, baseRepo.Name, auth_model.AccessTokenScopeWriteRepository)
|
||||
user2APICtx := NewAPITestContext(t, baseRepo.OwnerName, baseRepo.Name, baseRepo.GroupID, auth_model.AccessTokenScopeWriteRepository)
|
||||
|
||||
runner := newMockRunner()
|
||||
runner.registerAsRepoRunner(t, baseRepo.OwnerName, baseRepo.Name, "mock-runner", []string{"ubuntu-latest"}, false)
|
||||
@ -558,7 +558,7 @@ func TestActionsGiteaContextEphemeral(t *testing.T) {
|
||||
|
||||
apiBaseRepo := createActionsTestRepo(t, user2Token, "actions-gitea-context", false)
|
||||
baseRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: apiBaseRepo.ID})
|
||||
user2APICtx := NewAPITestContext(t, baseRepo.OwnerName, baseRepo.Name, auth_model.AccessTokenScopeWriteRepository)
|
||||
user2APICtx := NewAPITestContext(t, baseRepo.OwnerName, baseRepo.Name, baseRepo.GroupID, auth_model.AccessTokenScopeWriteRepository)
|
||||
|
||||
runner := newMockRunner()
|
||||
runner.registerAsRepoRunner(t, baseRepo.OwnerName, baseRepo.Name, "mock-runner", []string{"ubuntu-latest"}, true)
|
||||
|
||||
@ -61,7 +61,7 @@ func TestPullRequestTargetEvent(t *testing.T) {
|
||||
assert.NotEmpty(t, baseRepo)
|
||||
|
||||
// add user4 as the collaborator
|
||||
ctx := NewAPITestContext(t, baseRepo.OwnerName, baseRepo.Name, auth_model.AccessTokenScopeWriteRepository)
|
||||
ctx := NewAPITestContext(t, baseRepo.OwnerName, baseRepo.Name, baseRepo.GroupID, auth_model.AccessTokenScopeWriteRepository)
|
||||
t.Run("AddUser4AsCollaboratorWithReadAccess", doAPIAddCollaborator(ctx, "user4", perm.AccessModeRead))
|
||||
|
||||
// create the forked repo
|
||||
@ -487,7 +487,7 @@ func TestPullRequestCommitStatusEvent(t *testing.T) {
|
||||
assert.NotEmpty(t, repo)
|
||||
|
||||
// add user4 as the collaborator
|
||||
ctx := NewAPITestContext(t, repo.OwnerName, repo.Name, auth_model.AccessTokenScopeWriteRepository)
|
||||
ctx := NewAPITestContext(t, repo.OwnerName, repo.Name, repo.GroupID, auth_model.AccessTokenScopeWriteRepository)
|
||||
t.Run("AddUser4AsCollaboratorWithReadAccess", doAPIAddCollaborator(ctx, "user4", perm.AccessModeRead))
|
||||
|
||||
// add the workflow file to the repo
|
||||
@ -1542,7 +1542,7 @@ func TestClosePullRequestWithPath(t *testing.T) {
|
||||
// create the base repo
|
||||
apiBaseRepo := createActionsTestRepo(t, user2Token, "close-pull-request-with-path", false)
|
||||
baseRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: apiBaseRepo.ID})
|
||||
user2APICtx := NewAPITestContext(t, baseRepo.OwnerName, baseRepo.Name, auth_model.AccessTokenScopeWriteRepository)
|
||||
user2APICtx := NewAPITestContext(t, baseRepo.OwnerName, baseRepo.Name, baseRepo.GroupID, auth_model.AccessTokenScopeWriteRepository)
|
||||
|
||||
// init the workflow
|
||||
wfTreePath := ".gitea/workflows/pull.yml"
|
||||
@ -1571,7 +1571,7 @@ jobs:
|
||||
var apiForkRepo api.Repository
|
||||
DecodeJSON(t, resp, &apiForkRepo)
|
||||
forkRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: apiForkRepo.ID})
|
||||
user4APICtx := NewAPITestContext(t, user4.Name, forkRepo.Name, auth_model.AccessTokenScopeWriteRepository)
|
||||
user4APICtx := NewAPITestContext(t, user4.Name, forkRepo.Name, forkRepo.GroupID, auth_model.AccessTokenScopeWriteRepository)
|
||||
|
||||
// user4 creates a pull request to add file "app/main.go"
|
||||
doAPICreateFile(user4APICtx, "app/main.go", &api.CreateFileOptions{
|
||||
|
||||
@ -115,7 +115,7 @@ func TestAPICreateBranch(t *testing.T) {
|
||||
|
||||
func testAPICreateBranches(t *testing.T, giteaURL *url.URL) {
|
||||
username := "user2"
|
||||
ctx := NewAPITestContext(t, username, "my-noo-repo", auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
|
||||
ctx := NewAPITestContext(t, username, "my-noo-repo", 0, auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
|
||||
giteaURL.Path = ctx.GitPath()
|
||||
|
||||
t.Run("CreateRepo", doAPICreateRepository(ctx, false))
|
||||
@ -166,14 +166,18 @@ func testAPICreateBranches(t *testing.T, giteaURL *url.URL) {
|
||||
for _, test := range testCases {
|
||||
session := ctx.Session
|
||||
t.Run(test.NewBranch, func(t *testing.T) {
|
||||
testAPICreateBranch(t, session, "user2", "my-noo-repo", test.OldBranch, test.NewBranch, test.ExpectedHTTPStatus)
|
||||
testAPICreateBranch(t, session, 0, "user2", "my-noo-repo", test.OldBranch, test.NewBranch, test.ExpectedHTTPStatus)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func testAPICreateBranch(t testing.TB, session *TestSession, user, repo, oldBranch, newBranch string, status int) bool {
|
||||
func testAPICreateBranch(t testing.TB, session *TestSession, groupID int64, user, repo, oldBranch, newBranch string, status int) bool {
|
||||
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
|
||||
req := NewRequestWithJSON(t, "POST", "/api/v1/repos/"+user+"/"+repo+"/branches", &api.CreateBranchRepoOption{
|
||||
var groupSegment string
|
||||
if groupID > 0 {
|
||||
groupSegment = fmt.Sprintf("%d/", groupID)
|
||||
}
|
||||
req := NewRequestWithJSON(t, "POST", "/api/v1/repos/"+user+"/"+groupSegment+repo+"/branches", &api.CreateBranchRepoOption{
|
||||
BranchName: newBranch,
|
||||
OldBranchName: oldBranch,
|
||||
}).AddTokenAuth(token)
|
||||
@ -420,10 +424,10 @@ func TestAPICreateBranchWithSyncBranches(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
ctx := NewAPITestContext(t, "user2", "repo1", auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
|
||||
ctx := NewAPITestContext(t, "user2", "repo1", 0, auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
|
||||
giteaURL.Path = ctx.GitPath()
|
||||
|
||||
testAPICreateBranch(t, ctx.Session, "user2", "repo1", "", "new_branch", http.StatusCreated)
|
||||
testAPICreateBranch(t, ctx.Session, 0, "user2", "repo1", "", "new_branch", http.StatusCreated)
|
||||
})
|
||||
|
||||
branches, err = db.Find[git_model.Branch](t.Context(), git_model.FindBranchOptions{
|
||||
|
||||
@ -29,9 +29,10 @@ type APITestContext struct {
|
||||
Token string
|
||||
Username string
|
||||
ExpectedCode int
|
||||
GroupID int64
|
||||
}
|
||||
|
||||
func NewAPITestContext(t *testing.T, username, reponame string, scope ...auth.AccessTokenScope) APITestContext {
|
||||
func NewAPITestContext(t *testing.T, username, reponame string, groupID int64, scope ...auth.AccessTokenScope) APITestContext {
|
||||
session := loginUser(t, username)
|
||||
if len(scope) == 0 {
|
||||
// FIXME: legacy logic: no scope means all
|
||||
@ -41,6 +42,7 @@ func NewAPITestContext(t *testing.T, username, reponame string, scope ...auth.Ac
|
||||
return APITestContext{
|
||||
Session: session,
|
||||
Token: token,
|
||||
GroupID: groupID,
|
||||
Username: username,
|
||||
Reponame: reponame,
|
||||
}
|
||||
@ -60,6 +62,7 @@ func doAPICreateRepository(ctx APITestContext, empty bool, callback ...func(*tes
|
||||
Template: true,
|
||||
Gitignores: "",
|
||||
License: "WTFPL",
|
||||
GroupID: ctx.GroupID,
|
||||
Readme: "Default",
|
||||
}
|
||||
req := NewRequestWithJSON(t, "POST", "/api/v1/user/repos", createRepoOption).
|
||||
|
||||
@ -61,7 +61,7 @@ func TestAPILFSMediaType(t *testing.T) {
|
||||
}
|
||||
|
||||
func createLFSTestRepository(t *testing.T, repoName string) *repo_model.Repository {
|
||||
ctx := NewAPITestContext(t, "user2", repoName, auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
|
||||
ctx := NewAPITestContext(t, "user2", repoName, 0, auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
|
||||
t.Run("CreateRepo", doAPICreateRepository(ctx, false))
|
||||
|
||||
repo, err := repo_model.GetRepositoryByOwnerAndName(t.Context(), "user2", repoName, 0)
|
||||
|
||||
@ -37,8 +37,8 @@ func TestEditor(t *testing.T) {
|
||||
t.Run("DiffPreview", testEditorDiffPreview)
|
||||
t.Run("CreateFile", testEditorCreateFile)
|
||||
t.Run("EditFile", func(t *testing.T) {
|
||||
testEditFile(t, sessionUser2, "user2", "repo1", "master", "README.md", "Hello, World (direct)\n")
|
||||
testEditFileToNewBranch(t, sessionUser2, "user2", "repo1", "master", "feature/test", "README.md", "Hello, World (commit-to-new-branch)\n")
|
||||
testEditFile(t, sessionUser2, 0, "user2", "repo1", "master", "README.md", "Hello, World (direct)\n")
|
||||
testEditFileToNewBranch(t, sessionUser2, 0, "user2", "repo1", "master", "feature/test", "README.md", "Hello, World (commit-to-new-branch)\n")
|
||||
})
|
||||
t.Run("PatchFile", testEditorPatchFile)
|
||||
t.Run("DeleteFile", func(t *testing.T) {
|
||||
@ -57,7 +57,7 @@ func TestEditor(t *testing.T) {
|
||||
|
||||
func testEditorCreateFile(t *testing.T) {
|
||||
session := loginUser(t, "user2")
|
||||
testCreateFile(t, session, "user2", "repo1", "master", "", "test.txt", "Content")
|
||||
testCreateFile(t, session, 0, "user2", "repo1", "master", "", "test.txt", "Content")
|
||||
testEditorActionPostRequestError(t, session, "/user2/repo1/_new/master/", map[string]string{
|
||||
"tree_path": "test.txt",
|
||||
"commit_choice": "direct",
|
||||
@ -70,12 +70,12 @@ func testEditorCreateFile(t *testing.T) {
|
||||
}, `Branch "master" already exists in this repository.`)
|
||||
}
|
||||
|
||||
func testCreateFile(t *testing.T, session *TestSession, user, repo, baseBranchName, newBranchName, filePath, content string) {
|
||||
func testCreateFile(t *testing.T, session *TestSession, groupID int64, user, repo, baseBranchName, newBranchName, filePath, content string) {
|
||||
commitChoice := "direct"
|
||||
if newBranchName != "" && newBranchName != baseBranchName {
|
||||
commitChoice = "commit-to-new-branch"
|
||||
}
|
||||
testEditorActionEdit(t, session, user, repo, "_new", baseBranchName, "", map[string]string{
|
||||
testEditorActionEdit(t, session, groupID, user, repo, "_new", baseBranchName, "", map[string]string{
|
||||
"tree_path": filePath,
|
||||
"content": content,
|
||||
"commit_choice": commitChoice,
|
||||
@ -118,10 +118,14 @@ func testEditorActionPostRequestError(t *testing.T, session *TestSession, reques
|
||||
assert.Equal(t, errorMessage, test.ParseJSONError(resp.Body.Bytes()).ErrorMessage)
|
||||
}
|
||||
|
||||
func testEditorActionEdit(t *testing.T, session *TestSession, user, repo, editorAction, branch, filePath string, params map[string]string) *httptest.ResponseRecorder {
|
||||
func testEditorActionEdit(t *testing.T, session *TestSession, groupID int64, user, repo, editorAction, branch, filePath string, params map[string]string) *httptest.ResponseRecorder {
|
||||
params["tree_path"] = util.IfZero(params["tree_path"], filePath)
|
||||
newBranchName := util.Iif(params["commit_choice"] == "direct", branch, params["new_branch_name"])
|
||||
resp := testEditorActionPostRequest(t, session, fmt.Sprintf("/%s/%s/%s/%s/%s", user, repo, editorAction, branch, filePath), params)
|
||||
var groupSegment string
|
||||
if groupID > 0 {
|
||||
groupSegment = fmt.Sprintf("%d/", groupID)
|
||||
}
|
||||
resp := testEditorActionPostRequest(t, session, fmt.Sprintf("/%s/%s%s/%s/%s/%s", user, groupSegment, repo, editorAction, branch, filePath), params)
|
||||
assert.Equal(t, http.StatusOK, resp.Code)
|
||||
assert.NotEmpty(t, test.RedirectURL(resp))
|
||||
req := NewRequest(t, "GET", path.Join(user, repo, "raw/branch", newBranchName, params["tree_path"]))
|
||||
@ -130,15 +134,15 @@ func testEditorActionEdit(t *testing.T, session *TestSession, user, repo, editor
|
||||
return resp
|
||||
}
|
||||
|
||||
func testEditFile(t *testing.T, session *TestSession, user, repo, branch, filePath, newContent string) {
|
||||
testEditorActionEdit(t, session, user, repo, "_edit", branch, filePath, map[string]string{
|
||||
func testEditFile(t *testing.T, session *TestSession, groupID int64, user, repo, branch, filePath, newContent string) {
|
||||
testEditorActionEdit(t, session, groupID, user, repo, "_edit", branch, filePath, map[string]string{
|
||||
"content": newContent,
|
||||
"commit_choice": "direct",
|
||||
})
|
||||
}
|
||||
|
||||
func testEditFileToNewBranch(t *testing.T, session *TestSession, user, repo, branch, targetBranch, filePath, newContent string) {
|
||||
testEditorActionEdit(t, session, user, repo, "_edit", branch, filePath, map[string]string{
|
||||
func testEditFileToNewBranch(t *testing.T, session *TestSession, groupID int64, user, repo, branch, targetBranch, filePath, newContent string) {
|
||||
testEditorActionEdit(t, session, groupID, user, repo, "_edit", branch, filePath, map[string]string{
|
||||
"content": newContent,
|
||||
"commit_choice": "commit-to-new-branch",
|
||||
"new_branch_name": targetBranch,
|
||||
|
||||
@ -64,7 +64,7 @@ func TestNewWebHookLink(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func testAPICreateWebhookForRepo(t *testing.T, session *TestSession, userName, repoName, url, event string, branchFilter ...string) {
|
||||
func testAPICreateWebhookForRepo(t *testing.T, session *TestSession, groupID int64, userName, repoName, url, event string, branchFilter ...string) {
|
||||
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeAll)
|
||||
var branchFilterString string
|
||||
if len(branchFilter) > 0 {
|
||||
@ -153,10 +153,10 @@ func Test_WebhookCreate(t *testing.T) {
|
||||
// 1. create a new webhook with special webhook for repo1
|
||||
session := loginUser(t, "user2")
|
||||
|
||||
testAPICreateWebhookForRepo(t, session, "user2", "repo1", provider.URL(), "create")
|
||||
testAPICreateWebhookForRepo(t, session, 0, "user2", "repo1", provider.URL(), "create")
|
||||
|
||||
// 2. trigger the webhook
|
||||
testAPICreateBranch(t, session, "user2", "repo1", "master", "master2", http.StatusCreated)
|
||||
testAPICreateBranch(t, session, 0, "user2", "repo1", "master", "master2", http.StatusCreated)
|
||||
|
||||
// 3. validate the webhook is triggered
|
||||
assert.Len(t, payloads, 1)
|
||||
@ -185,10 +185,10 @@ func Test_WebhookDelete(t *testing.T) {
|
||||
// 1. create a new webhook with special webhook for repo1
|
||||
session := loginUser(t, "user2")
|
||||
|
||||
testAPICreateWebhookForRepo(t, session, "user2", "repo1", provider.URL(), "delete")
|
||||
testAPICreateWebhookForRepo(t, session, 0, "user2", "repo1", provider.URL(), "delete")
|
||||
|
||||
// 2. trigger the webhook
|
||||
testAPICreateBranch(t, session, "user2", "repo1", "master", "master2", http.StatusCreated)
|
||||
testAPICreateBranch(t, session, 0, "user2", "repo1", "master", "master2", http.StatusCreated)
|
||||
testAPIDeleteBranch(t, "master2", http.StatusNoContent)
|
||||
|
||||
// 3. validate the webhook is triggered
|
||||
@ -218,7 +218,7 @@ func Test_WebhookFork(t *testing.T) {
|
||||
// 1. create a new webhook with special webhook for repo1
|
||||
session := loginUser(t, "user1")
|
||||
|
||||
testAPICreateWebhookForRepo(t, session, "user2", "repo1", provider.URL(), "fork")
|
||||
testAPICreateWebhookForRepo(t, session, 0, "user2", "repo1", provider.URL(), "fork")
|
||||
|
||||
// 2. trigger the webhook
|
||||
testRepoFork(t, session, "user2", "repo1", "user1", "repo1-fork", "master")
|
||||
@ -250,7 +250,7 @@ func Test_WebhookIssueComment(t *testing.T) {
|
||||
// 1. create a new webhook with special webhook for repo1
|
||||
session := loginUser(t, "user2")
|
||||
|
||||
testAPICreateWebhookForRepo(t, session, "user2", "repo1", provider.URL(), "issue_comment")
|
||||
testAPICreateWebhookForRepo(t, session, 0, "user2", "repo1", provider.URL(), "issue_comment")
|
||||
|
||||
t.Run("create comment", func(t *testing.T) {
|
||||
// 2. trigger the webhook
|
||||
@ -332,7 +332,7 @@ func Test_WebhookRelease(t *testing.T) {
|
||||
// 1. create a new webhook with special webhook for repo1
|
||||
session := loginUser(t, "user2")
|
||||
|
||||
testAPICreateWebhookForRepo(t, session, "user2", "repo1", provider.URL(), "release")
|
||||
testAPICreateWebhookForRepo(t, session, 0, "user2", "repo1", provider.URL(), "release")
|
||||
|
||||
// 2. trigger the webhook
|
||||
createNewRelease(t, session, "/user2/repo1", "v0.0.99", "v0.0.99", false, false)
|
||||
@ -365,10 +365,10 @@ func Test_WebhookPush(t *testing.T) {
|
||||
// 1. create a new webhook with special webhook for repo1
|
||||
session := loginUser(t, "user2")
|
||||
|
||||
testAPICreateWebhookForRepo(t, session, "user2", "repo1", provider.URL(), "push")
|
||||
testAPICreateWebhookForRepo(t, session, 0, "user2", "repo1", provider.URL(), "push")
|
||||
|
||||
// 2. trigger the webhook
|
||||
testCreateFile(t, session, "user2", "repo1", "master", "", "test_webhook_push.md", "# a test file for webhook push")
|
||||
testCreateFile(t, session, 0, "user2", "repo1", "master", "", "test_webhook_push.md", "# a test file for webhook push")
|
||||
|
||||
// 3. validate the webhook is triggered
|
||||
assert.Equal(t, "push", triggeredEvent)
|
||||
@ -398,10 +398,10 @@ func Test_WebhookPushDevBranch(t *testing.T) {
|
||||
session := loginUser(t, "user2")
|
||||
|
||||
// only for dev branch
|
||||
testAPICreateWebhookForRepo(t, session, "user2", "repo1", provider.URL(), "push", "develop")
|
||||
testAPICreateWebhookForRepo(t, session, 0, "user2", "repo1", provider.URL(), "push", "develop")
|
||||
|
||||
// 2. this should not trigger the webhook
|
||||
testCreateFile(t, session, "user2", "repo1", "master", "", "test_webhook_push.md", "# a test file for webhook push")
|
||||
testCreateFile(t, session, 0, "user2", "repo1", "master", "", "test_webhook_push.md", "# a test file for webhook push")
|
||||
assert.Empty(t, triggeredEvent)
|
||||
assert.Empty(t, payloads)
|
||||
|
||||
@ -414,7 +414,7 @@ func Test_WebhookPushDevBranch(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
|
||||
// 3. trigger the webhook
|
||||
testCreateFile(t, session, "user2", "repo1", "develop", "", "test_webhook_push.md", "# a test file for webhook push")
|
||||
testCreateFile(t, session, 0, "user2", "repo1", "develop", "", "test_webhook_push.md", "# a test file for webhook push")
|
||||
|
||||
afterCommitID, err := gitRepo.GetBranchCommitID("develop")
|
||||
assert.NoError(t, err)
|
||||
@ -454,7 +454,7 @@ func Test_WebhookPushToNewBranch(t *testing.T) {
|
||||
session := loginUser(t, "user2")
|
||||
|
||||
// only for dev branch
|
||||
testAPICreateWebhookForRepo(t, session, "user2", "repo1", provider.URL(), "push", "new_branch")
|
||||
testAPICreateWebhookForRepo(t, session, 0, "user2", "repo1", provider.URL(), "push", "new_branch")
|
||||
|
||||
repo1 := unittest.AssertExistsAndLoadBean(t, &repo.Repository{ID: 1})
|
||||
gitRepo, err := gitrepo.OpenRepository(t.Context(), repo1)
|
||||
@ -465,7 +465,7 @@ func Test_WebhookPushToNewBranch(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
|
||||
// 2. trigger the webhook
|
||||
testCreateFile(t, session, "user2", "repo1", "master", "new_branch", "test_webhook_push.md", "# a new push from new branch")
|
||||
testCreateFile(t, session, 0, "user2", "repo1", "master", "new_branch", "test_webhook_push.md", "# a new push from new branch")
|
||||
|
||||
afterCommitID, err := gitRepo.GetBranchCommitID("new_branch")
|
||||
assert.NoError(t, err)
|
||||
@ -505,7 +505,7 @@ func Test_WebhookIssue(t *testing.T) {
|
||||
// 1. create a new webhook with special webhook for repo1
|
||||
session := loginUser(t, "user2")
|
||||
|
||||
testAPICreateWebhookForRepo(t, session, "user2", "repo1", provider.URL(), "issues")
|
||||
testAPICreateWebhookForRepo(t, session, 0, "user2", "repo1", provider.URL(), "issues")
|
||||
|
||||
// 2. trigger the webhook
|
||||
testNewIssue(t, session, "user2", "repo1", "Title1", "Description1")
|
||||
@ -539,7 +539,7 @@ func Test_WebhookIssueDelete(t *testing.T) {
|
||||
|
||||
// 1. create a new webhook with special webhook for repo1
|
||||
session := loginUser(t, "user2")
|
||||
testAPICreateWebhookForRepo(t, session, "user2", "repo1", provider.URL(), "issues")
|
||||
testAPICreateWebhookForRepo(t, session, 0, "user2", "repo1", provider.URL(), "issues")
|
||||
issueURL := testNewIssue(t, session, "user2", "repo1", "Title1", "Description1")
|
||||
|
||||
// 2. trigger the webhook
|
||||
@ -576,7 +576,7 @@ func Test_WebhookIssueAssign(t *testing.T) {
|
||||
// 1. create a new webhook with special webhook for repo1
|
||||
session := loginUser(t, "user2")
|
||||
|
||||
testAPICreateWebhookForRepo(t, session, "user2", "repo1", provider.URL(), "pull_request_assign")
|
||||
testAPICreateWebhookForRepo(t, session, 0, "user2", "repo1", provider.URL(), "pull_request_assign")
|
||||
|
||||
// 2. trigger the webhook, issue 2 is a pull request
|
||||
testIssueAssign(t, session, repo1.Link(), 2, user2.ID)
|
||||
@ -610,7 +610,7 @@ func Test_WebhookIssueMilestone(t *testing.T) {
|
||||
// create a new webhook with special webhook for repo1
|
||||
session := loginUser(t, "user2")
|
||||
repo1 := unittest.AssertExistsAndLoadBean(t, &repo.Repository{ID: 1})
|
||||
testAPICreateWebhookForRepo(t, session, "user2", "repo1", provider.URL(), "issue_milestone")
|
||||
testAPICreateWebhookForRepo(t, session, 0, "user2", "repo1", provider.URL(), "issue_milestone")
|
||||
|
||||
t.Run("assign a milestone", func(t *testing.T) {
|
||||
// trigger the webhook
|
||||
@ -688,9 +688,9 @@ func Test_WebhookPullRequest(t *testing.T) {
|
||||
sessionUser4 := loginUser(t, "user4")
|
||||
|
||||
// ignore the possible review_requested event to keep the test deterministic
|
||||
testAPICreateWebhookForRepo(t, sessionUser2, "user2", "repo1", provider.URL(), "pull_request_only")
|
||||
testAPICreateWebhookForRepo(t, sessionUser2, 0, "user2", "repo1", provider.URL(), "pull_request_only")
|
||||
|
||||
testAPICreateBranch(t, sessionUser2, "user2", "repo1", "master", "master2", http.StatusCreated)
|
||||
testAPICreateBranch(t, sessionUser2, 0, "user2", "repo1", "master", "master2", http.StatusCreated)
|
||||
// 2. trigger the webhook
|
||||
repo1 := unittest.AssertExistsAndLoadBean(t, &repo.Repository{ID: 1})
|
||||
testPullCreateDirectly(t, sessionUser4, createPullRequestOptions{
|
||||
@ -735,9 +735,9 @@ func Test_WebhookPullRequestDelete(t *testing.T) {
|
||||
|
||||
// 1. create a new webhook with special webhook for repo1
|
||||
session := loginUser(t, "user2")
|
||||
testAPICreateWebhookForRepo(t, session, "user2", "repo1", provider.URL(), "pull_request")
|
||||
testAPICreateWebhookForRepo(t, session, 0, "user2", "repo1", provider.URL(), "pull_request")
|
||||
|
||||
testAPICreateBranch(t, session, "user2", "repo1", "master", "master2", http.StatusCreated)
|
||||
testAPICreateBranch(t, session, 0, "user2", "repo1", "master", "master2", http.StatusCreated)
|
||||
|
||||
repo1 := unittest.AssertExistsAndLoadBean(t, &repo.Repository{ID: 1})
|
||||
issueURL := testCreatePullToDefaultBranch(t, session, repo1, repo1, "master2", "first pull request")
|
||||
@ -774,10 +774,10 @@ func Test_WebhookPullRequestComment(t *testing.T) {
|
||||
// 1. create a new webhook with special webhook for repo1
|
||||
session := loginUser(t, "user2")
|
||||
|
||||
testAPICreateWebhookForRepo(t, session, "user2", "repo1", provider.URL(), "pull_request_comment")
|
||||
testAPICreateWebhookForRepo(t, session, 0, "user2", "repo1", provider.URL(), "pull_request_comment")
|
||||
|
||||
// 2. trigger the webhook
|
||||
testAPICreateBranch(t, session, "user2", "repo1", "master", "master2", http.StatusCreated)
|
||||
testAPICreateBranch(t, session, 0, "user2", "repo1", "master", "master2", http.StatusCreated)
|
||||
repo1 := unittest.AssertExistsAndLoadBean(t, &repo.Repository{ID: 1})
|
||||
prID := testCreatePullToDefaultBranch(t, session, repo1, repo1, "master2", "first pull request")
|
||||
|
||||
@ -812,7 +812,7 @@ func Test_WebhookWiki(t *testing.T) {
|
||||
// 1. create a new webhook with special webhook for repo1
|
||||
session := loginUser(t, "user2")
|
||||
|
||||
testAPICreateWebhookForRepo(t, session, "user2", "repo1", provider.URL(), "wiki")
|
||||
testAPICreateWebhookForRepo(t, session, 0, "user2", "repo1", provider.URL(), "wiki")
|
||||
|
||||
// 2. trigger the webhook
|
||||
testAPICreateWikiPage(t, session, "user2", "repo1", "Test Wiki Page", http.StatusCreated)
|
||||
@ -918,7 +918,7 @@ func Test_WebhookStatus(t *testing.T) {
|
||||
// 1. create a new webhook with special webhook for repo1
|
||||
session := loginUser(t, "user2")
|
||||
|
||||
testAPICreateWebhookForRepo(t, session, "user2", "repo1", provider.URL(), "status")
|
||||
testAPICreateWebhookForRepo(t, session, 0, "user2", "repo1", provider.URL(), "status")
|
||||
|
||||
repo1 := unittest.AssertExistsAndLoadBean(t, &repo.Repository{ID: 1})
|
||||
|
||||
@ -962,7 +962,7 @@ func Test_WebhookStatus_NoWrongTrigger(t *testing.T) {
|
||||
testCreateWebhookForRepo(t, session, "gitea", "user2", "repo1", provider.URL(), "push_only")
|
||||
|
||||
// 2. trigger the webhook with a push action
|
||||
testCreateFile(t, session, "user2", "repo1", "master", "", "test_webhook_push.md", "# a test file for webhook push")
|
||||
testCreateFile(t, session, 0, "user2", "repo1", "master", "", "test_webhook_push.md", "# a test file for webhook push")
|
||||
|
||||
// 3. validate the webhook is triggered with right event
|
||||
assert.Equal(t, "push", trigger)
|
||||
@ -991,7 +991,7 @@ func Test_WebhookWorkflowJob(t *testing.T) {
|
||||
session := loginUser(t, "user2")
|
||||
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
|
||||
|
||||
testAPICreateWebhookForRepo(t, session, "user2", "repo1", provider.URL(), "workflow_job")
|
||||
testAPICreateWebhookForRepo(t, session, 0, "user2", "repo1", provider.URL(), "workflow_job")
|
||||
|
||||
repo1 := unittest.AssertExistsAndLoadBean(t, &repo.Repository{ID: 1})
|
||||
|
||||
@ -1696,7 +1696,7 @@ func testWebhookWorkflowRun(t *testing.T, webhookData *workflowRunWebhook) {
|
||||
session := loginUser(t, "user2")
|
||||
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
|
||||
|
||||
testAPICreateWebhookForRepo(t, session, "user2", "repo1", webhookData.URL, "workflow_run")
|
||||
testAPICreateWebhookForRepo(t, session, 0, "user2", "repo1", webhookData.URL, "workflow_run")
|
||||
|
||||
repo1 := unittest.AssertExistsAndLoadBean(t, &repo.Repository{ID: 1})
|
||||
|
||||
@ -1797,7 +1797,7 @@ func testWebhookWorkflowRunDepthLimit(t *testing.T, webhookData *workflowRunWebh
|
||||
session := loginUser(t, "user2")
|
||||
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
|
||||
|
||||
testAPICreateWebhookForRepo(t, session, "user2", "repo1", webhookData.URL, "workflow_run")
|
||||
testAPICreateWebhookForRepo(t, session, 0, "user2", "repo1", webhookData.URL, "workflow_run")
|
||||
|
||||
repo1 := unittest.AssertExistsAndLoadBean(t, &repo.Repository{ID: 1})
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user