diff options
author | Cornel <cornelk@users.noreply.github.com> | 2019-12-28 16:55:09 +0800 |
---|---|---|
committer | zeripath <art27@cantab.net> | 2019-12-28 08:55:09 +0000 |
commit | 81e63d0714f1539fcd688cf3e216b0eab89e88aa (patch) | |
tree | cddd201be48da86ba309e7d794f8c6becf3c1b05 /modules/webhook/general_test.go | |
parent | 10455a88dc28c00f86587266a1ecd736bea63d03 (diff) | |
download | gitea-81e63d0714f1539fcd688cf3e216b0eab89e88aa.tar.gz gitea-81e63d0714f1539fcd688cf3e216b0eab89e88aa.zip |
Refactor webhooks to reduce code duplication (#9422)
* Start webhook refactoring to reduce code duplication
* More webhook refactoring
* Unify webhook release messages
* Fix webhook release link
* Remove sql import
* More webhook refactoring
* More webhook refactoring
* Webhook tests extended
* Fixed issue opened webhook
Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: zeripath <art27@cantab.net>
Co-authored-by: techknowlogick <matti@mdranta.net>
Diffstat (limited to 'modules/webhook/general_test.go')
-rw-r--r-- | modules/webhook/general_test.go | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/modules/webhook/general_test.go b/modules/webhook/general_test.go new file mode 100644 index 0000000000..3033b57880 --- /dev/null +++ b/modules/webhook/general_test.go @@ -0,0 +1,125 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package webhook + +import ( + api "code.gitea.io/gitea/modules/structs" +) + +func issueTestPayload() *api.IssuePayload { + return &api.IssuePayload{ + Index: 2, + Sender: &api.User{ + UserName: "user1", + }, + Repository: &api.Repository{ + HTMLURL: "http://localhost:3000/test/repo", + Name: "repo", + FullName: "test/repo", + }, + Issue: &api.Issue{ + ID: 2, + Index: 2, + URL: "http://localhost:3000/api/v1/repos/test/repo/issues/2", + Title: "crash", + }, + } +} + +func issueCommentTestPayload() *api.IssueCommentPayload { + return &api.IssueCommentPayload{ + Action: api.HookIssueCommentCreated, + Sender: &api.User{ + UserName: "user1", + }, + Repository: &api.Repository{ + HTMLURL: "http://localhost:3000/test/repo", + Name: "repo", + FullName: "test/repo", + }, + Comment: &api.Comment{ + HTMLURL: "http://localhost:3000/test/repo/issues/2#issuecomment-4", + IssueURL: "http://localhost:3000/test/repo/issues/2", + Body: "more info needed", + }, + Issue: &api.Issue{ + ID: 2, + Index: 2, + URL: "http://localhost:3000/api/v1/repos/test/repo/issues/2", + Title: "crash", + Body: "this happened", + }, + } +} + +func pullRequestCommentTestPayload() *api.IssueCommentPayload { + return &api.IssueCommentPayload{ + Action: api.HookIssueCommentCreated, + Sender: &api.User{ + UserName: "user1", + }, + Repository: &api.Repository{ + HTMLURL: "http://localhost:3000/test/repo", + Name: "repo", + FullName: "test/repo", + }, + Comment: &api.Comment{ + HTMLURL: "http://localhost:3000/test/repo/pulls/2#issuecomment-4", + PRURL: "http://localhost:3000/test/repo/pulls/2", + Body: "changes requested", + }, + Issue: &api.Issue{ + ID: 2, + Index: 2, + URL: "http://localhost:3000/api/v1/repos/test/repo/issues/2", + Title: "Fix bug", + Body: "fixes bug #2", + }, + IsPull: true, + } +} + +func pullReleaseTestPayload() *api.ReleasePayload { + return &api.ReleasePayload{ + Action: api.HookReleasePublished, + Sender: &api.User{ + UserName: "user1", + }, + Repository: &api.Repository{ + HTMLURL: "http://localhost:3000/test/repo", + Name: "repo", + FullName: "test/repo", + }, + Release: &api.Release{ + TagName: "v1.0", + Target: "master", + Title: "First stable release", + URL: "http://localhost:3000/api/v1/repos/test/repo/releases/2", + }, + } +} + +func pullRequestTestPayload() *api.PullRequestPayload { + return &api.PullRequestPayload{ + Action: api.HookIssueOpened, + Index: 2, + Sender: &api.User{ + UserName: "user1", + }, + Repository: &api.Repository{ + HTMLURL: "http://localhost:3000/test/repo", + Name: "repo", + FullName: "test/repo", + }, + PullRequest: &api.PullRequest{ + ID: 2, + Index: 2, + URL: "http://localhost:3000/test/repo/pulls/12", + Title: "Fix bug", + Body: "fixes bug #2", + Mergeable: true, + }, + } +} |