-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a new section named development in issue view sidebar to interact with branch/pr #31899
Draft
lunny
wants to merge
63
commits into
go-gitea:main
Choose a base branch
from
lunny:lunny/issue_dev
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 34 commits
Commits
Show all changes
63 commits
Select commit
Hold shift + click to select a range
62fda25
Add a new section named development in issue view sidebar to interact…
lunny 2361ec5
Improvements for creating branch model
lunny b4eac75
Some improvements
lunny 359e660
some improvements
lunny 9ea3376
revert unnecessary change
lunny bc1b296
revert unnecessary change
lunny e2d7980
Fix template
lunny 6feb5a1
Merge branch 'main' into lunny/issue_dev
lunny bb98848
Allow multiple branches, pull requests
lunny e64f232
Avoid template lint bug
lunny 6b829f7
Delete dev links when repository/issue/pull/branch deleted
lunny 0208f5b
Add ref issue when creating pull request from issue
lunny 3abb729
Revert unnecessary change
lunny 6e0bc0d
Fix test
lunny 5fb581a
Merge branch 'main' into lunny/issue_dev
lunny 003707f
Improve the name of branch creation dialog
lunny 837526a
Merge branch 'main' into lunny/issue_dev
lunny 8951291
Merge branch 'main' into lunny/issue_dev
techknowlogick abe592c
Fix repository list permissions
lunny cb37b59
Merge branch 'main' into lunny/issue_dev
lunny e49445b
Merge branch 'lunny/issue_dev' of github.com:lunny/gitea into lunny/i…
lunny 0e05274
Don't use SafeHTML
lunny cbeed11
Merge branch 'main' into lunny/issue_dev
lunny 86e4f29
Update routers/web/repo/issue_dev.go
lunny f11fc41
Update routers/web/repo/issue_dev.go
lunny 7fd210b
Add missed language content
lunny 30d4010
Some improvements
lunny 66681c3
merge if conditions
lunny f3c1634
Merge branch 'main' into lunny/issue_dev
lunny c8a8fc6
Don't display create branch link for closed issue
lunny f17020c
Merge branch 'main' into lunny/issue_dev
lunny 570f338
Merge branch 'lunny/issue_dev' of github.com:lunny/gitea into lunny/i…
lunny d3f3fb1
Merge branch 'main' into lunny/issue_dev
lunny fcc2c57
Merge branch 'main' into lunny/issue_dev
lunny 72d06ee
Remove issue.ref
lunny 3d8ed0e
Merge branch 'main' into lunny/issue_dev
lunny 121b823
Follow template change
lunny 703eebf
Adjust development sidebar
lunny ab6d2ed
Display forked repository's branch
lunny 79cb889
display pull request on float window
lunny b3086c9
improve the popup branch create window
lunny e5b581c
More ui improvements
lunny c0d1960
Fix lint
lunny 267a2ec
fill default branch name
lunny 17956ae
Make toast in front of modal
lunny f52a57d
Fix bug
lunny f77d7e7
Merge branch 'main' into lunny/issue_dev
lunny 35b7d32
add margin top 2 for item
lunny 3556305
Merge branch 'main' into lunny/issue_dev
lunny 029a444
Fix dropdown list
lunny 66dbadc
Merge branch 'main' into lunny/issue_dev
lunny 051b42a
Add ellipsis
lunny f2a28d0
Add missing locale string
lunny 478fbd5
Merge branch 'main' into lunny/issue_dev
lunny d869d32
Merge branch 'main' into lunny/issue_dev
lunny a81c785
Merge branch 'main' into lunny/issue_dev
lunny da7f700
Fix create branch permission
lunny 832b78e
Empty, mirror & archived repository will not allow create branch
lunny 2d49aec
Merge branch 'main' into lunny/issue_dev
lunny 3addd3a
Move migration to v1.24
lunny a84034a
Merge branch 'main' into lunny/issue_dev
lunny 479364a
Merge branch 'main' into lunny/issue_dev
lunny b3e6d4b
Merge branch 'main' into lunny/issue_dev
lunny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright 2024 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package issues | ||
|
||
import ( | ||
"context" | ||
"strconv" | ||
|
||
"code.gitea.io/gitea/models/db" | ||
git_model "code.gitea.io/gitea/models/git" | ||
repo_model "code.gitea.io/gitea/models/repo" | ||
"code.gitea.io/gitea/modules/timeutil" | ||
) | ||
|
||
type IssueDevLinkType int | ||
|
||
const ( | ||
IssueDevLinkTypeBranch IssueDevLinkType = iota + 1 | ||
IssueDevLinkTypePullRequest | ||
) | ||
|
||
type IssueDevLink struct { | ||
ID int64 `xorm:"pk autoincr"` | ||
IssueID int64 `xorm:"INDEX"` | ||
LinkType IssueDevLinkType | ||
LinkedRepoID int64 `xorm:"INDEX"` // it can link to self repo or other repo | ||
LinkIndex string // branch name, pull request number or commit sha | ||
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` | ||
|
||
LinkedRepo *repo_model.Repository `xorm:"-"` | ||
PullRequest *PullRequest `xorm:"-"` | ||
Branch *git_model.Branch `xorm:"-"` | ||
DisplayBranch bool `xorm:"-"` | ||
} | ||
|
||
func init() { | ||
db.RegisterModel(new(IssueDevLink)) | ||
} | ||
|
||
// IssueDevLinks represents a list of issue development links | ||
type IssueDevLinks []*IssueDevLink | ||
|
||
// FindIssueDevLinksByIssueID returns a list of issue development links by issue ID | ||
func FindIssueDevLinksByIssueID(ctx context.Context, issueID int64) (IssueDevLinks, error) { | ||
links := make(IssueDevLinks, 0, 5) | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2024 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package v1_23 //nolint | ||
|
||
import ( | ||
"code.gitea.io/gitea/modules/timeutil" | ||
|
||
"xorm.io/xorm" | ||
) | ||
|
||
func CreateTableIssueDevLink(x *xorm.Engine) error { | ||
type IssueDevLink struct { | ||
ID int64 `xorm:"pk autoincr"` | ||
IssueID int64 `xorm:"INDEX"` | ||
LinkType int | ||
LinkedRepoID int64 `xorm:"INDEX"` // it can link to self repo or other repo | ||
LinkIndex string // branch name, pull request number or commit sha | ||
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` | ||
} | ||
return x.Sync(new(IssueDevLink)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// Copyright 2024 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package repo | ||
|
||
import ( | ||
"net/http" | ||
|
||
git_model "code.gitea.io/gitea/models/git" | ||
issues_model "code.gitea.io/gitea/models/issues" | ||
access_model "code.gitea.io/gitea/models/perm/access" | ||
repo_model "code.gitea.io/gitea/models/repo" | ||
unit_model "code.gitea.io/gitea/models/unit" | ||
"code.gitea.io/gitea/modules/git" | ||
"code.gitea.io/gitea/modules/gitrepo" | ||
"code.gitea.io/gitea/modules/web" | ||
"code.gitea.io/gitea/routers/utils" | ||
"code.gitea.io/gitea/services/context" | ||
"code.gitea.io/gitea/services/forms" | ||
repo_service "code.gitea.io/gitea/services/repository" | ||
) | ||
|
||
func CreateBranchFromIssue(ctx *context.Context) { | ||
if ctx.HasError() { // form binding error check | ||
ctx.JSONError(ctx.GetErrMsg()) | ||
return | ||
} | ||
|
||
issue := GetActionIssue(ctx) | ||
if ctx.Written() { | ||
return | ||
} | ||
|
||
if issue.IsPull { | ||
ctx.Flash.Error(ctx.Tr("repo.issues.create_branch_from_issue_error_is_pull")) | ||
lunny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ctx.JSONRedirect(issue.Link()) | ||
return | ||
} | ||
|
||
form := web.GetForm(ctx).(*forms.NewBranchForm) | ||
repo := ctx.Repo.Repository | ||
gitRepo := ctx.Repo.GitRepo | ||
if form.RepoID > 0 { | ||
var err error | ||
repo, err = repo_model.GetRepositoryByID(ctx, form.RepoID) | ||
if err != nil { | ||
ctx.ServerError("GetRepositoryByID", err) | ||
return | ||
} | ||
gitRepo, err = gitrepo.OpenRepository(ctx, repo) | ||
if err != nil { | ||
ctx.ServerError("OpenRepository", err) | ||
return | ||
} | ||
defer gitRepo.Close() | ||
} | ||
|
||
perm, err := access_model.GetUserRepoPermission(ctx, repo, ctx.Doer) | ||
if err != nil { | ||
ctx.ServerError("GetUserRepoPermission", err) | ||
return | ||
} | ||
|
||
canCreateBranch := perm.CanWrite(unit_model.TypeCode) && repo.CanCreateBranch() | ||
if !canCreateBranch { | ||
ctx.Error(http.StatusForbidden, "No permission to create branch in this repository") | ||
return | ||
} | ||
|
||
if err := repo_service.CreateNewBranch(ctx, ctx.Doer, repo, gitRepo, form.SourceBranchName, form.NewBranchName); err != nil { | ||
switch { | ||
case git_model.IsErrBranchAlreadyExists(err) || git.IsErrPushOutOfDate(err): | ||
ctx.JSONError(ctx.Tr("repo.branch.branch_already_exists", form.NewBranchName)) | ||
case git_model.IsErrBranchNameConflict(err): | ||
e := err.(git_model.ErrBranchNameConflict) | ||
ctx.JSONError(ctx.Tr("repo.branch.branch_name_conflict", form.NewBranchName, e.BranchName)) | ||
case git.IsErrPushRejected(err): | ||
e := err.(*git.ErrPushRejected) | ||
if len(e.Message) == 0 { | ||
ctx.Flash.Error(ctx.Tr("repo.editor.push_rejected_no_message")) | ||
} else { | ||
flashError, err := ctx.RenderToHTML(tplAlertDetails, map[string]any{ | ||
"Message": ctx.Tr("repo.editor.push_rejected"), | ||
"Summary": ctx.Tr("repo.editor.push_rejected_summary"), | ||
"Details": utils.SanitizeFlashErrorString(e.Message), | ||
}) | ||
if err != nil { | ||
ctx.ServerError("UpdatePullRequest.HTMLString", err) | ||
return | ||
} | ||
ctx.JSONError(flashError) | ||
} | ||
default: | ||
ctx.ServerError("CreateNewBranch", err) | ||
} | ||
return | ||
} | ||
|
||
if err := issues_model.CreateIssueDevLink(ctx, &issues_model.IssueDevLink{ | ||
IssueID: issue.ID, | ||
LinkType: issues_model.IssueDevLinkTypeBranch, | ||
LinkedRepoID: repo.ID, | ||
LinkIndex: form.NewBranchName, | ||
}); err != nil { | ||
ctx.ServerError("CreateIssueDevLink", err) | ||
return | ||
} | ||
|
||
ctx.Flash.Success(ctx.Tr("repo.issues.create_branch_from_issue_success", ctx.Repo.BranchName)) | ||
ctx.JSONRedirect(issue.Link()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just tried to play with GitHub's development sidebar for a while. I can see there could be a lot of edge cases:
123-my-issue
, rename the branch to123-my-issue-other
, the link disappears, rename another branch to123-my-issue
, the link won't appear again.123-my-issue
, create a PR from123-my-issue
, then the link is updated to PR, the branch link is replaced.I believe these details need enough documents(comments) and tests.