mirror of
https://github.com/go-gitea/gitea
synced 2025-12-07 13:28:25 +00:00
Add a new section named development in issue view sidebar to interact with branch/pr
This commit is contained in:
@@ -14,9 +14,10 @@ import (
|
||||
|
||||
// NewBranchForm form for creating a new branch
|
||||
type NewBranchForm struct {
|
||||
NewBranchName string `binding:"Required;MaxSize(100);GitRefName"`
|
||||
CurrentPath string
|
||||
CreateTag bool
|
||||
NewBranchName string `binding:"Required;MaxSize(100);GitRefName"`
|
||||
SourceBranchName string
|
||||
CurrentPath string
|
||||
CreateTag bool
|
||||
}
|
||||
|
||||
// Validate validates the fields
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
// Copyright 2024 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package issue
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
git_model "code.gitea.io/gitea/models/git"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
)
|
||||
|
||||
func FindIssueDevLinksByIssue(ctx context.Context, issue *issues_model.Issue) (issues_model.IssueDevLinks, error) {
|
||||
devLinks, err := issues_model.FindIssueDevLinksByIssueID(ctx, issue.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := issue.LoadRepo(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, link := range devLinks {
|
||||
if link.LinkedRepoID == 0 {
|
||||
link.LinkedRepoID = issue.RepoID
|
||||
}
|
||||
isSameRepo := issue.RepoID == link.LinkedRepoID
|
||||
if isSameRepo {
|
||||
link.LinkedRepo = issue.Repo
|
||||
} else if link.LinkedRepoID > 0 {
|
||||
repo, err := repo_model.GetRepositoryByID(ctx, link.LinkedRepoID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
link.LinkedRepo = repo
|
||||
}
|
||||
|
||||
switch link.LinkType {
|
||||
case issues_model.IssueDevLinkTypePullRequest:
|
||||
pullID, err := strconv.ParseInt(link.LinkIndex, 10, 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pull, err := issues_model.GetPullRequestByID(ctx, pullID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
link.PullRequest = pull
|
||||
link.PullRequest.Issue = issue
|
||||
link.PullRequest.BaseRepo = issue.Repo
|
||||
case issues_model.IssueDevLinkTypeBranch:
|
||||
branch, err := git_model.GetBranch(ctx, link.LinkedRepoID, link.LinkIndex)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
link.Branch = branch
|
||||
link.Branch.Repo = link.LinkedRepo
|
||||
}
|
||||
}
|
||||
|
||||
return devLinks, nil
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -166,6 +167,24 @@ func NewPullRequest(ctx context.Context, repo *repo_model.Repository, issue *iss
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if pr.Flow == issues_model.PullRequestFlowGithub {
|
||||
devLinks, err := issues_model.FindDevLinksByBranch(ctx, issue.RepoID, pr.HeadRepoID, pr.HeadBranch)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, link := range devLinks {
|
||||
if err := issues_model.CreateIssueDevLink(ctx, &issues_model.IssueDevLink{
|
||||
IssueID: link.IssueID,
|
||||
LinkType: issues_model.IssueDevLinkTypePullRequest,
|
||||
LinkedRepoID: pr.HeadRepoID,
|
||||
LinkIndex: strconv.FormatInt(pr.ID, 10),
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}); err != nil {
|
||||
// cleanup: this will only remove the reference, the real commit will be clean up when next GC
|
||||
|
||||
Reference in New Issue
Block a user