Skip to content

Commit 9a20c6a

Browse files
authored
Merge branch 'master' into fix-8301
2 parents dcb3ddb + c6fb7fe commit 9a20c6a

File tree

10 files changed

+62
-38
lines changed

10 files changed

+62
-38
lines changed

models/pull.go

-27
Original file line numberDiff line numberDiff line change
@@ -700,33 +700,6 @@ func NewPullRequest(repo *Repository, pull *Issue, labelIDs []int64, uuids []str
700700
return fmt.Errorf("Commit: %v", err)
701701
}
702702

703-
if err = NotifyWatchers(&Action{
704-
ActUserID: pull.Poster.ID,
705-
ActUser: pull.Poster,
706-
OpType: ActionCreatePullRequest,
707-
Content: fmt.Sprintf("%d|%s", pull.Index, pull.Title),
708-
RepoID: repo.ID,
709-
Repo: repo,
710-
IsPrivate: repo.IsPrivate,
711-
}); err != nil {
712-
log.Error("NotifyWatchers: %v", err)
713-
}
714-
715-
pr.Issue = pull
716-
pull.PullRequest = pr
717-
mode, _ := AccessLevel(pull.Poster, repo)
718-
if err = PrepareWebhooks(repo, HookEventPullRequest, &api.PullRequestPayload{
719-
Action: api.HookIssueOpened,
720-
Index: pull.Index,
721-
PullRequest: pr.APIFormat(),
722-
Repository: repo.APIFormat(mode),
723-
Sender: pull.Poster.APIFormat(),
724-
}); err != nil {
725-
log.Error("PrepareWebhooks: %v", err)
726-
} else {
727-
go HookQueue.Add(repo.ID)
728-
}
729-
730703
return nil
731704
}
732705

routers/api/v1/repo/pull.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ import (
1515
"code.gitea.io/gitea/modules/git"
1616
"code.gitea.io/gitea/modules/log"
1717
"code.gitea.io/gitea/modules/notification"
18-
"code.gitea.io/gitea/modules/pull"
19-
pull_service "code.gitea.io/gitea/modules/pull"
2018
api "code.gitea.io/gitea/modules/structs"
2119
"code.gitea.io/gitea/modules/timeutil"
2220
milestone_service "code.gitea.io/gitea/services/milestone"
21+
pull_service "code.gitea.io/gitea/services/pull"
2322
)
2423

2524
// ListPullRequests returns a list of all PRs
@@ -295,7 +294,7 @@ func CreatePullRequest(ctx *context.APIContext, form api.CreatePullRequestOption
295294
return
296295
}
297296

298-
if err := models.NewPullRequest(repo, prIssue, labelIDs, []string{}, pr, patch, assigneeIDs); err != nil {
297+
if err := pull_service.NewPullRequest(repo, prIssue, labelIDs, []string{}, pr, patch, assigneeIDs); err != nil {
299298
if models.IsErrUserDoesNotHaveAccessToRepo(err) {
300299
ctx.Error(400, "UserDoesNotHaveAccessToRepo", err)
301300
return
@@ -609,7 +608,7 @@ func MergePullRequest(ctx *context.APIContext, form auth.MergePullRequestForm) {
609608
message += "\n\n" + form.MergeMessageField
610609
}
611610

612-
if err := pull.Merge(pr, ctx.User, ctx.Repo.GitRepo, models.MergeStyle(form.Do), message); err != nil {
611+
if err := pull_service.Merge(pr, ctx.User, ctx.Repo.GitRepo, models.MergeStyle(form.Do), message); err != nil {
613612
if models.IsErrInvalidMergeStyle(err) {
614613
ctx.Status(405)
615614
return

routers/api/v1/repo/release_attachment.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"code.gitea.io/gitea/models"
1111
"code.gitea.io/gitea/modules/context"
12+
"code.gitea.io/gitea/modules/log"
1213
"code.gitea.io/gitea/modules/setting"
1314
api "code.gitea.io/gitea/modules/structs"
1415
"code.gitea.io/gitea/modules/upload"
@@ -55,6 +56,7 @@ func GetReleaseAttachment(ctx *context.APIContext) {
5556
return
5657
}
5758
if attach.ReleaseID != releaseID {
59+
log.Info("User requested attachment is not in release, release_id %v, attachment_id: %v", releaseID, attachID)
5860
ctx.NotFound()
5961
return
6062
}
@@ -242,13 +244,14 @@ func EditReleaseAttachment(ctx *context.APIContext, form api.EditAttachmentOptio
242244

243245
// Check if release exists an load release
244246
releaseID := ctx.ParamsInt64(":id")
245-
attachID := ctx.ParamsInt64(":attachment")
247+
attachID := ctx.ParamsInt64(":asset")
246248
attach, err := models.GetAttachmentByID(attachID)
247249
if err != nil {
248250
ctx.Error(500, "GetAttachmentByID", err)
249251
return
250252
}
251253
if attach.ReleaseID != releaseID {
254+
log.Info("User requested attachment is not in release, release_id %v, attachment_id: %v", releaseID, attachID)
252255
ctx.NotFound()
253256
return
254257
}
@@ -299,13 +302,14 @@ func DeleteReleaseAttachment(ctx *context.APIContext) {
299302

300303
// Check if release exists an load release
301304
releaseID := ctx.ParamsInt64(":id")
302-
attachID := ctx.ParamsInt64(":attachment")
305+
attachID := ctx.ParamsInt64(":asset")
303306
attach, err := models.GetAttachmentByID(attachID)
304307
if err != nil {
305308
ctx.Error(500, "GetAttachmentByID", err)
306309
return
307310
}
308311
if attach.ReleaseID != releaseID {
312+
log.Info("User requested attachment is not in release, release_id %v, attachment_id: %v", releaseID, attachID)
309313
ctx.NotFound()
310314
return
311315
}

routers/repo/pull.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ import (
2121
"code.gitea.io/gitea/modules/git"
2222
"code.gitea.io/gitea/modules/log"
2323
"code.gitea.io/gitea/modules/notification"
24-
"code.gitea.io/gitea/modules/pull"
25-
pull_service "code.gitea.io/gitea/modules/pull"
2624
"code.gitea.io/gitea/modules/setting"
2725
"code.gitea.io/gitea/modules/util"
2826
"code.gitea.io/gitea/services/gitdiff"
27+
pull_service "code.gitea.io/gitea/services/pull"
2928

3029
"github.com/unknwon/com"
3130
)
@@ -676,7 +675,7 @@ func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) {
676675
return
677676
}
678677

679-
if err = pull.Merge(pr, ctx.User, ctx.Repo.GitRepo, models.MergeStyle(form.Do), message); err != nil {
678+
if err = pull_service.Merge(pr, ctx.User, ctx.Repo.GitRepo, models.MergeStyle(form.Do), message); err != nil {
680679
if models.IsErrInvalidMergeStyle(err) {
681680
ctx.Flash.Error(ctx.Tr("repo.pulls.invalid_merge_option"))
682681
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
@@ -796,7 +795,7 @@ func CompareAndPullRequestPost(ctx *context.Context, form auth.CreateIssueForm)
796795
// FIXME: check error in the case two people send pull request at almost same time, give nice error prompt
797796
// instead of 500.
798797

799-
if err := models.NewPullRequest(repo, pullIssue, labelIDs, attachments, pullRequest, patch, assigneeIDs); err != nil {
798+
if err := pull_service.NewPullRequest(repo, pullIssue, labelIDs, attachments, pullRequest, patch, assigneeIDs); err != nil {
800799
if models.IsErrUserDoesNotHaveAccessToRepo(err) {
801800
ctx.Error(400, "UserDoesNotHaveAccessToRepo", err.Error())
802801
return

routers/repo/pull_review.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import (
1212
"code.gitea.io/gitea/modules/context"
1313
"code.gitea.io/gitea/modules/log"
1414
"code.gitea.io/gitea/modules/notification"
15-
pull_service "code.gitea.io/gitea/modules/pull"
1615
comment_service "code.gitea.io/gitea/services/comments"
16+
pull_service "code.gitea.io/gitea/services/pull"
1717
)
1818

1919
// CreateCodeComment will create a code comment including an pending review if required
File renamed without changes.
File renamed without changes.
File renamed without changes.

services/pull/pull.go

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2019 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package pull
6+
7+
import (
8+
"fmt"
9+
10+
"code.gitea.io/gitea/models"
11+
"code.gitea.io/gitea/modules/log"
12+
api "code.gitea.io/gitea/modules/structs"
13+
)
14+
15+
// NewPullRequest creates new pull request with labels for repository.
16+
func NewPullRequest(repo *models.Repository, pull *models.Issue, labelIDs []int64, uuids []string, pr *models.PullRequest, patch []byte, assigneeIDs []int64) error {
17+
if err := models.NewPullRequest(repo, pull, labelIDs, uuids, pr, patch, assigneeIDs); err != nil {
18+
return err
19+
}
20+
21+
if err := models.NotifyWatchers(&models.Action{
22+
ActUserID: pull.Poster.ID,
23+
ActUser: pull.Poster,
24+
OpType: models.ActionCreatePullRequest,
25+
Content: fmt.Sprintf("%d|%s", pull.Index, pull.Title),
26+
RepoID: repo.ID,
27+
Repo: repo,
28+
IsPrivate: repo.IsPrivate,
29+
}); err != nil {
30+
log.Error("NotifyWatchers: %v", err)
31+
}
32+
33+
pr.Issue = pull
34+
pull.PullRequest = pr
35+
mode, _ := models.AccessLevel(pull.Poster, repo)
36+
if err := models.PrepareWebhooks(repo, models.HookEventPullRequest, &api.PullRequestPayload{
37+
Action: api.HookIssueOpened,
38+
Index: pull.Index,
39+
PullRequest: pr.APIFormat(),
40+
Repository: repo.APIFormat(mode),
41+
Sender: pull.Poster.APIFormat(),
42+
}); err != nil {
43+
log.Error("PrepareWebhooks: %v", err)
44+
} else {
45+
go models.HookQueue.Add(repo.ID)
46+
}
47+
48+
return nil
49+
}
File renamed without changes.

0 commit comments

Comments
 (0)