mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-10 20:31:25 +02:00
Fix lint
This commit is contained in:
parent
7ea492cb90
commit
793a9e6639
@ -5,7 +5,6 @@ package issues
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
git_model "code.gitea.io/gitea/models/git"
|
||||
@ -25,7 +24,7 @@ type IssueDevLink struct {
|
||||
IssueID int64 `xorm:"INDEX"`
|
||||
LinkType IssueDevLinkType
|
||||
LinkedRepoID int64 `xorm:"INDEX"` // it can link to self repo or other repo
|
||||
LinkID int64 // branch id in branch table or pull request id
|
||||
LinkID int64 // branch id in branch table or the pull request id(not issue if of the pull request)
|
||||
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
|
||||
Repo *repo_model.Repository `xorm:"-"` // current repo of issue
|
||||
LinkedRepo *repo_model.Repository `xorm:"-"`
|
||||
@ -54,32 +53,7 @@ func FindIssueDevLinksByIssueID(ctx context.Context, issueID int64) (IssueDevLin
|
||||
return links, db.GetEngine(ctx).Where("issue_id = ?", issueID).Find(&links)
|
||||
}
|
||||
|
||||
func FindDevLinksByBranch(ctx context.Context, repoID, linkedRepoID int64, branchName string) (IssueDevLinks, error) {
|
||||
links := make(IssueDevLinks, 0, 5)
|
||||
return links, db.GetEngine(ctx).
|
||||
Join("INNER", "issue", "issue_dev_link.issue_id = issue.id").
|
||||
Where("link_type = ? AND link_index = ? AND linked_repo_id = ?",
|
||||
IssueDevLinkTypeBranch, branchName, linkedRepoID).
|
||||
And("issue.repo_id=?", repoID).
|
||||
Find(&links)
|
||||
}
|
||||
|
||||
func CreateIssueDevLink(ctx context.Context, link *IssueDevLink) error {
|
||||
_, err := db.GetEngine(ctx).Insert(link)
|
||||
return err
|
||||
}
|
||||
|
||||
func DeleteIssueDevLinkByBranchName(ctx context.Context, repoID int64, branchName string) error {
|
||||
_, err := db.GetEngine(ctx).
|
||||
Where("linked_repo_id = ? AND link_type = ? AND link_index = ?",
|
||||
repoID, IssueDevLinkTypeBranch, branchName).
|
||||
Delete(new(IssueDevLink))
|
||||
return err
|
||||
}
|
||||
|
||||
func DeleteIssueDevLinkByPullRequestID(ctx context.Context, pullID int64) error {
|
||||
pullIDStr := strconv.FormatInt(pullID, 10)
|
||||
_, err := db.GetEngine(ctx).Where("link_type = ? AND link_index = ?", IssueDevLinkTypePullRequest, pullIDStr).
|
||||
Delete(new(IssueDevLink))
|
||||
return err
|
||||
}
|
||||
|
||||
@ -114,7 +114,7 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := issues_model.DeleteIssueDevLinkByBranchName(ctx, repo.ID, update.RefFullName.BranchName()); err != nil {
|
||||
if err := repo_service.DeleteIssueDevLinkByBranchName(ctx, repo.ID, update.RefFullName.BranchName()); err != nil {
|
||||
log.Error("Failed to DeleteIssueDevLinkByBranchName: %s/%s %s Error: %v", ownerName, repoName, update.RefFullName.BranchName(), err)
|
||||
}
|
||||
} else {
|
||||
|
||||
@ -292,7 +292,11 @@ func deleteIssue(ctx context.Context, issue *issues_model.Issue) ([]string, erro
|
||||
}
|
||||
|
||||
if issue.IsPull {
|
||||
if err := issues_model.DeleteIssueDevLinkByPullRequestID(ctx, issue.ID); err != nil {
|
||||
if err := issue.LoadPullRequest(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, err := db.GetEngine(ctx).Where("link_type = ? AND link_id = ?", issues_model.IssueDevLinkTypePullRequest, issue.PullRequest.ID).
|
||||
Delete(new(issues_model.IssueDevLink)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
@ -142,10 +142,21 @@ func NewPullRequest(ctx context.Context, opts *NewPullRequestOptions) error {
|
||||
}
|
||||
|
||||
if pr.Flow == issues_model.PullRequestFlowGithub {
|
||||
devLinks, err := issues_model.FindDevLinksByBranch(ctx, issue.RepoID, pr.HeadRepoID, pr.HeadBranch)
|
||||
branch, err := git_model.GetBranch(ctx, pr.HeadRepoID, pr.HeadBranch)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
devLinks := make(issues_model.IssueDevLinks, 0, 5)
|
||||
if err := db.GetEngine(ctx).
|
||||
Join("INNER", "issue", "issue_dev_link.issue_id = issue.id").
|
||||
Where("link_type = ? AND link_id = ? AND linked_repo_id = ?",
|
||||
issues_model.IssueDevLinkTypeBranch, branch.ID, issue.RepoID).
|
||||
And("issue.repo_id=?", pr.HeadRepoID).
|
||||
Find(&devLinks); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, link := range devLinks {
|
||||
if err := issues_model.CreateIssueDevLink(ctx, &issues_model.IssueDevLink{
|
||||
IssueID: link.IssueID,
|
||||
|
||||
@ -513,6 +513,22 @@ func CanDeleteBranch(ctx context.Context, repo *repo_model.Repository, branchNam
|
||||
return nil
|
||||
}
|
||||
|
||||
func DeleteIssueDevLinkByBranchName(ctx context.Context, repoID int64, branchName string) error {
|
||||
awBranch, err := git_model.GetBranch(ctx, repoID, branchName)
|
||||
if err != nil && !git_model.IsErrBranchNotExist(err) {
|
||||
return fmt.Errorf("GetBranch: %vc", err)
|
||||
}
|
||||
if awBranch == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err = db.GetEngine(ctx).
|
||||
Where("linked_repo_id = ? AND link_type = ? AND link_id = ?",
|
||||
repoID, issues_model.IssueDevLinkTypeBranch, awBranch.ID).
|
||||
Delete(new(issues_model.IssueDevLink))
|
||||
return err
|
||||
}
|
||||
|
||||
// DeleteBranch delete branch
|
||||
func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, gitRepo *git.Repository, branchName string, pr *issues_model.PullRequest) error {
|
||||
err := repo.MustNotBeArchived()
|
||||
@ -544,7 +560,7 @@ func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.R
|
||||
}
|
||||
}
|
||||
|
||||
if err := issues_model.DeleteIssueDevLinkByBranchName(ctx, repo.ID, branchName); err != nil {
|
||||
if err := DeleteIssueDevLinkByBranchName(ctx, repo.ID, branchName); err != nil {
|
||||
return err
|
||||
}
|
||||
if pr != nil {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user