mirror of
https://github.com/go-gitea/gitea
synced 2025-07-20 01:08:35 +00:00
Backport #34420 by lunny Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
@@ -54,6 +54,8 @@ func ToggleAssigneeWithNotify(ctx context.Context, issue *issues_model.Issue, do
|
||||
if err != nil {
|
||||
return false, nil, err
|
||||
}
|
||||
issue.AssigneeID = assigneeID
|
||||
issue.Assignee = assignee
|
||||
|
||||
notify_service.IssueChangeAssignee(ctx, doer, issue, assignee, removed, comment)
|
||||
|
||||
|
@@ -151,6 +151,15 @@ func testNewIssue(t *testing.T, session *TestSession, user, repo, title, content
|
||||
return issueURL
|
||||
}
|
||||
|
||||
func testIssueAssign(t *testing.T, session *TestSession, repoLink string, issueID, assigneeID int64) {
|
||||
req := NewRequestWithValues(t, "POST", fmt.Sprintf(repoLink+"/issues/assignee?issue_ids=%d", issueID), map[string]string{
|
||||
"_csrf": GetUserCSRFToken(t, session),
|
||||
"id": strconv.FormatInt(assigneeID, 10),
|
||||
"action": "", // empty action means assign
|
||||
})
|
||||
session.MakeRequest(t, req, http.StatusOK)
|
||||
}
|
||||
|
||||
func testIssueAddComment(t *testing.T, session *TestSession, issueURL, content, status string) int64 {
|
||||
req := NewRequest(t, "GET", issueURL)
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
|
@@ -126,6 +126,7 @@ func (m *mockWebhookProvider) Close() {
|
||||
}
|
||||
|
||||
func Test_WebhookCreate(t *testing.T) {
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
var payloads []api.CreatePayload
|
||||
var triggeredEvent string
|
||||
provider := newMockWebhookProvider(func(r *http.Request) {
|
||||
@@ -138,7 +139,6 @@ func Test_WebhookCreate(t *testing.T) {
|
||||
}, http.StatusOK)
|
||||
defer provider.Close()
|
||||
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
// 1. create a new webhook with special webhook for repo1
|
||||
session := loginUser(t, "user2")
|
||||
|
||||
@@ -158,6 +158,7 @@ func Test_WebhookCreate(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_WebhookDelete(t *testing.T) {
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
var payloads []api.DeletePayload
|
||||
var triggeredEvent string
|
||||
provider := newMockWebhookProvider(func(r *http.Request) {
|
||||
@@ -170,7 +171,6 @@ func Test_WebhookDelete(t *testing.T) {
|
||||
}, http.StatusOK)
|
||||
defer provider.Close()
|
||||
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
// 1. create a new webhook with special webhook for repo1
|
||||
session := loginUser(t, "user2")
|
||||
|
||||
@@ -191,6 +191,7 @@ func Test_WebhookDelete(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_WebhookFork(t *testing.T) {
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
var payloads []api.ForkPayload
|
||||
var triggeredEvent string
|
||||
provider := newMockWebhookProvider(func(r *http.Request) {
|
||||
@@ -203,7 +204,6 @@ func Test_WebhookFork(t *testing.T) {
|
||||
}, http.StatusOK)
|
||||
defer provider.Close()
|
||||
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
// 1. create a new webhook with special webhook for repo1
|
||||
session := loginUser(t, "user1")
|
||||
|
||||
@@ -223,6 +223,7 @@ func Test_WebhookFork(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_WebhookIssueComment(t *testing.T) {
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
var payloads []api.IssueCommentPayload
|
||||
var triggeredEvent string
|
||||
provider := newMockWebhookProvider(func(r *http.Request) {
|
||||
@@ -235,7 +236,6 @@ func Test_WebhookIssueComment(t *testing.T) {
|
||||
}, http.StatusOK)
|
||||
defer provider.Close()
|
||||
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
// 1. create a new webhook with special webhook for repo1
|
||||
session := loginUser(t, "user2")
|
||||
|
||||
@@ -307,6 +307,7 @@ func Test_WebhookIssueComment(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_WebhookRelease(t *testing.T) {
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
var payloads []api.ReleasePayload
|
||||
var triggeredEvent string
|
||||
provider := newMockWebhookProvider(func(r *http.Request) {
|
||||
@@ -319,7 +320,6 @@ func Test_WebhookRelease(t *testing.T) {
|
||||
}, http.StatusOK)
|
||||
defer provider.Close()
|
||||
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
// 1. create a new webhook with special webhook for repo1
|
||||
session := loginUser(t, "user2")
|
||||
|
||||
@@ -340,6 +340,7 @@ func Test_WebhookRelease(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_WebhookPush(t *testing.T) {
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
var payloads []api.PushPayload
|
||||
var triggeredEvent string
|
||||
provider := newMockWebhookProvider(func(r *http.Request) {
|
||||
@@ -352,7 +353,6 @@ func Test_WebhookPush(t *testing.T) {
|
||||
}, http.StatusOK)
|
||||
defer provider.Close()
|
||||
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
// 1. create a new webhook with special webhook for repo1
|
||||
session := loginUser(t, "user2")
|
||||
|
||||
@@ -372,6 +372,7 @@ func Test_WebhookPush(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_WebhookIssue(t *testing.T) {
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
var payloads []api.IssuePayload
|
||||
var triggeredEvent string
|
||||
provider := newMockWebhookProvider(func(r *http.Request) {
|
||||
@@ -384,7 +385,6 @@ func Test_WebhookIssue(t *testing.T) {
|
||||
}, http.StatusOK)
|
||||
defer provider.Close()
|
||||
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
// 1. create a new webhook with special webhook for repo1
|
||||
session := loginUser(t, "user2")
|
||||
|
||||
@@ -401,6 +401,45 @@ func Test_WebhookIssue(t *testing.T) {
|
||||
assert.Equal(t, "user2/repo1", payloads[0].Issue.Repo.FullName)
|
||||
assert.Equal(t, "Title1", payloads[0].Issue.Title)
|
||||
assert.Equal(t, "Description1", payloads[0].Issue.Body)
|
||||
assert.Positive(t, payloads[0].Issue.Created.Unix())
|
||||
assert.Positive(t, payloads[0].Issue.Updated.Unix())
|
||||
})
|
||||
}
|
||||
|
||||
func Test_WebhookIssueAssign(t *testing.T) {
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
var payloads []api.PullRequestPayload
|
||||
var triggeredEvent string
|
||||
provider := newMockWebhookProvider(func(r *http.Request) {
|
||||
content, _ := io.ReadAll(r.Body)
|
||||
var payload api.PullRequestPayload
|
||||
err := json.Unmarshal(content, &payload)
|
||||
assert.NoError(t, err)
|
||||
payloads = append(payloads, payload)
|
||||
triggeredEvent = "pull_request_assign"
|
||||
}, http.StatusOK)
|
||||
defer provider.Close()
|
||||
|
||||
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
repo1 := unittest.AssertExistsAndLoadBean(t, &repo.Repository{ID: 1})
|
||||
|
||||
// 1. create a new webhook with special webhook for repo1
|
||||
session := loginUser(t, "user2")
|
||||
|
||||
testAPICreateWebhookForRepo(t, session, "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)
|
||||
|
||||
// 3. validate the webhook is triggered
|
||||
assert.Equal(t, "pull_request_assign", triggeredEvent)
|
||||
assert.Len(t, payloads, 1)
|
||||
assert.EqualValues(t, "assigned", payloads[0].Action)
|
||||
assert.Equal(t, "repo1", payloads[0].PullRequest.Base.Repository.Name)
|
||||
assert.Equal(t, "user2/repo1", payloads[0].PullRequest.Base.Repository.FullName)
|
||||
assert.Equal(t, "issue2", payloads[0].PullRequest.Title)
|
||||
assert.Equal(t, "content for the second issue", payloads[0].PullRequest.Body)
|
||||
assert.Equal(t, user2.ID, payloads[0].PullRequest.Assignee.ID)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -477,6 +516,7 @@ func Test_WebhookIssueMilestone(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_WebhookPullRequest(t *testing.T) {
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
var payloads []api.PullRequestPayload
|
||||
var triggeredEvent string
|
||||
provider := newMockWebhookProvider(func(r *http.Request) {
|
||||
@@ -489,7 +529,6 @@ func Test_WebhookPullRequest(t *testing.T) {
|
||||
}, http.StatusOK)
|
||||
defer provider.Close()
|
||||
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
// 1. create a new webhook with special webhook for repo1
|
||||
session := loginUser(t, "user2")
|
||||
|
||||
@@ -514,6 +553,7 @@ func Test_WebhookPullRequest(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_WebhookPullRequestComment(t *testing.T) {
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
var payloads []api.IssueCommentPayload
|
||||
var triggeredEvent string
|
||||
provider := newMockWebhookProvider(func(r *http.Request) {
|
||||
@@ -526,7 +566,6 @@ func Test_WebhookPullRequestComment(t *testing.T) {
|
||||
}, http.StatusOK)
|
||||
defer provider.Close()
|
||||
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
// 1. create a new webhook with special webhook for repo1
|
||||
session := loginUser(t, "user2")
|
||||
|
||||
@@ -552,6 +591,7 @@ func Test_WebhookPullRequestComment(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_WebhookWiki(t *testing.T) {
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
var payloads []api.WikiPayload
|
||||
var triggeredEvent string
|
||||
provider := newMockWebhookProvider(func(r *http.Request) {
|
||||
@@ -564,7 +604,6 @@ func Test_WebhookWiki(t *testing.T) {
|
||||
}, http.StatusOK)
|
||||
defer provider.Close()
|
||||
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
// 1. create a new webhook with special webhook for repo1
|
||||
session := loginUser(t, "user2")
|
||||
|
||||
@@ -584,6 +623,7 @@ func Test_WebhookWiki(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_WebhookRepository(t *testing.T) {
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
var payloads []api.RepositoryPayload
|
||||
var triggeredEvent string
|
||||
provider := newMockWebhookProvider(func(r *http.Request) {
|
||||
@@ -596,7 +636,6 @@ func Test_WebhookRepository(t *testing.T) {
|
||||
}, http.StatusOK)
|
||||
defer provider.Close()
|
||||
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
// 1. create a new webhook with special webhook for repo1
|
||||
session := loginUser(t, "user1")
|
||||
|
||||
@@ -616,6 +655,7 @@ func Test_WebhookRepository(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_WebhookPackage(t *testing.T) {
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
var payloads []api.PackagePayload
|
||||
var triggeredEvent string
|
||||
provider := newMockWebhookProvider(func(r *http.Request) {
|
||||
@@ -628,7 +668,6 @@ func Test_WebhookPackage(t *testing.T) {
|
||||
}, http.StatusOK)
|
||||
defer provider.Close()
|
||||
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
// 1. create a new webhook with special webhook for repo1
|
||||
session := loginUser(t, "user1")
|
||||
|
||||
@@ -653,6 +692,7 @@ func Test_WebhookPackage(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_WebhookStatus(t *testing.T) {
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
var payloads []api.CommitStatusPayload
|
||||
var triggeredEvent string
|
||||
provider := newMockWebhookProvider(func(r *http.Request) {
|
||||
@@ -670,7 +710,6 @@ func Test_WebhookStatus(t *testing.T) {
|
||||
}, http.StatusOK)
|
||||
defer provider.Close()
|
||||
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
// 1. create a new webhook with special webhook for repo1
|
||||
session := loginUser(t, "user2")
|
||||
|
||||
@@ -706,6 +745,7 @@ func Test_WebhookStatus(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_WebhookStatus_NoWrongTrigger(t *testing.T) {
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
var trigger string
|
||||
provider := newMockWebhookProvider(func(r *http.Request) {
|
||||
assert.NotContains(t, r.Header["X-Github-Event-Type"], "status", "X-GitHub-Event-Type should not contain status")
|
||||
@@ -715,7 +755,6 @@ func Test_WebhookStatus_NoWrongTrigger(t *testing.T) {
|
||||
}, http.StatusOK)
|
||||
defer provider.Close()
|
||||
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
// 1. create a new webhook with special webhook for repo1
|
||||
session := loginUser(t, "user2")
|
||||
|
||||
@@ -731,6 +770,7 @@ func Test_WebhookStatus_NoWrongTrigger(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_WebhookWorkflowJob(t *testing.T) {
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
var payloads []api.WorkflowJobPayload
|
||||
var triggeredEvent string
|
||||
provider := newMockWebhookProvider(func(r *http.Request) {
|
||||
@@ -746,7 +786,6 @@ func Test_WebhookWorkflowJob(t *testing.T) {
|
||||
}, http.StatusOK)
|
||||
defer provider.Close()
|
||||
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
// 1. create a new webhook with special webhook for repo1
|
||||
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
session := loginUser(t, "user2")
|
||||
|
Reference in New Issue
Block a user