Skip to content

Commit 793a9e6

Browse files
committed
Fix lint
1 parent 7ea492c commit 793a9e6

File tree

5 files changed

+36
-31
lines changed

5 files changed

+36
-31
lines changed

models/issues/issue_dev_link.go

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package issues
55

66
import (
77
"context"
8-
"strconv"
98

109
"code.gitea.io/gitea/models/db"
1110
git_model "code.gitea.io/gitea/models/git"
@@ -25,7 +24,7 @@ type IssueDevLink struct {
2524
IssueID int64 `xorm:"INDEX"`
2625
LinkType IssueDevLinkType
2726
LinkedRepoID int64 `xorm:"INDEX"` // it can link to self repo or other repo
28-
LinkID int64 // branch id in branch table or pull request id
27+
LinkID int64 // branch id in branch table or the pull request id(not issue if of the pull request)
2928
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
3029
Repo *repo_model.Repository `xorm:"-"` // current repo of issue
3130
LinkedRepo *repo_model.Repository `xorm:"-"`
@@ -54,32 +53,7 @@ func FindIssueDevLinksByIssueID(ctx context.Context, issueID int64) (IssueDevLin
5453
return links, db.GetEngine(ctx).Where("issue_id = ?", issueID).Find(&links)
5554
}
5655

57-
func FindDevLinksByBranch(ctx context.Context, repoID, linkedRepoID int64, branchName string) (IssueDevLinks, error) {
58-
links := make(IssueDevLinks, 0, 5)
59-
return links, db.GetEngine(ctx).
60-
Join("INNER", "issue", "issue_dev_link.issue_id = issue.id").
61-
Where("link_type = ? AND link_index = ? AND linked_repo_id = ?",
62-
IssueDevLinkTypeBranch, branchName, linkedRepoID).
63-
And("issue.repo_id=?", repoID).
64-
Find(&links)
65-
}
66-
6756
func CreateIssueDevLink(ctx context.Context, link *IssueDevLink) error {
6857
_, err := db.GetEngine(ctx).Insert(link)
6958
return err
7059
}
71-
72-
func DeleteIssueDevLinkByBranchName(ctx context.Context, repoID int64, branchName string) error {
73-
_, err := db.GetEngine(ctx).
74-
Where("linked_repo_id = ? AND link_type = ? AND link_index = ?",
75-
repoID, IssueDevLinkTypeBranch, branchName).
76-
Delete(new(IssueDevLink))
77-
return err
78-
}
79-
80-
func DeleteIssueDevLinkByPullRequestID(ctx context.Context, pullID int64) error {
81-
pullIDStr := strconv.FormatInt(pullID, 10)
82-
_, err := db.GetEngine(ctx).Where("link_type = ? AND link_index = ?", IssueDevLinkTypePullRequest, pullIDStr).
83-
Delete(new(IssueDevLink))
84-
return err
85-
}

routers/private/hook_post_receive.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) {
114114
return
115115
}
116116

117-
if err := issues_model.DeleteIssueDevLinkByBranchName(ctx, repo.ID, update.RefFullName.BranchName()); err != nil {
117+
if err := repo_service.DeleteIssueDevLinkByBranchName(ctx, repo.ID, update.RefFullName.BranchName()); err != nil {
118118
log.Error("Failed to DeleteIssueDevLinkByBranchName: %s/%s %s Error: %v", ownerName, repoName, update.RefFullName.BranchName(), err)
119119
}
120120
} else {

services/issue/issue.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,11 @@ func deleteIssue(ctx context.Context, issue *issues_model.Issue) ([]string, erro
292292
}
293293

294294
if issue.IsPull {
295-
if err := issues_model.DeleteIssueDevLinkByPullRequestID(ctx, issue.ID); err != nil {
295+
if err := issue.LoadPullRequest(ctx); err != nil {
296+
return nil, err
297+
}
298+
if _, err := db.GetEngine(ctx).Where("link_type = ? AND link_id = ?", issues_model.IssueDevLinkTypePullRequest, issue.PullRequest.ID).
299+
Delete(new(issues_model.IssueDevLink)); err != nil {
296300
return nil, err
297301
}
298302
}

services/pull/pull.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,21 @@ func NewPullRequest(ctx context.Context, opts *NewPullRequestOptions) error {
142142
}
143143

144144
if pr.Flow == issues_model.PullRequestFlowGithub {
145-
devLinks, err := issues_model.FindDevLinksByBranch(ctx, issue.RepoID, pr.HeadRepoID, pr.HeadBranch)
145+
branch, err := git_model.GetBranch(ctx, pr.HeadRepoID, pr.HeadBranch)
146146
if err != nil {
147147
return err
148148
}
149+
150+
devLinks := make(issues_model.IssueDevLinks, 0, 5)
151+
if err := db.GetEngine(ctx).
152+
Join("INNER", "issue", "issue_dev_link.issue_id = issue.id").
153+
Where("link_type = ? AND link_id = ? AND linked_repo_id = ?",
154+
issues_model.IssueDevLinkTypeBranch, branch.ID, issue.RepoID).
155+
And("issue.repo_id=?", pr.HeadRepoID).
156+
Find(&devLinks); err != nil {
157+
return err
158+
}
159+
149160
for _, link := range devLinks {
150161
if err := issues_model.CreateIssueDevLink(ctx, &issues_model.IssueDevLink{
151162
IssueID: link.IssueID,

services/repository/branch.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,22 @@ func CanDeleteBranch(ctx context.Context, repo *repo_model.Repository, branchNam
513513
return nil
514514
}
515515

516+
func DeleteIssueDevLinkByBranchName(ctx context.Context, repoID int64, branchName string) error {
517+
awBranch, err := git_model.GetBranch(ctx, repoID, branchName)
518+
if err != nil && !git_model.IsErrBranchNotExist(err) {
519+
return fmt.Errorf("GetBranch: %vc", err)
520+
}
521+
if awBranch == nil {
522+
return nil
523+
}
524+
525+
_, err = db.GetEngine(ctx).
526+
Where("linked_repo_id = ? AND link_type = ? AND link_id = ?",
527+
repoID, issues_model.IssueDevLinkTypeBranch, awBranch.ID).
528+
Delete(new(issues_model.IssueDevLink))
529+
return err
530+
}
531+
516532
// DeleteBranch delete branch
517533
func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, gitRepo *git.Repository, branchName string, pr *issues_model.PullRequest) error {
518534
err := repo.MustNotBeArchived()
@@ -544,7 +560,7 @@ func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.R
544560
}
545561
}
546562

547-
if err := issues_model.DeleteIssueDevLinkByBranchName(ctx, repo.ID, branchName); err != nil {
563+
if err := DeleteIssueDevLinkByBranchName(ctx, repo.ID, branchName); err != nil {
548564
return err
549565
}
550566
if pr != nil {

0 commit comments

Comments
 (0)