-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Add a new section named development in issue view sidebar to interact with branch/pr #31899
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
Open
lunny
wants to merge
90
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.
+591
−17
Open
Changes from all commits
Commits
Show all changes
90 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 260eee2
Merge branch 'main' into lunny/issue_dev
lunny 097c649
Merge branch 'main' into lunny/issue_dev
lunny 7b4c3e2
Fix bug
lunny eaf998b
Fix bug
lunny 0735d3c
Merge branch 'main' into lunny/issue_dev
lunny 1787e02
Merge branch 'main' into lunny/issue_dev
lunny 5d73889
Use branch id or pull request id as dev link id
lunny 7ea492c
Merge branch 'main' into lunny/issue_dev
lunny 793a9e6
Fix lint
lunny 43cdc71
Merge branch 'main' into lunny/issue_dev
lunny b580b59
Fix test
lunny 27e0450
Fix test
lunny c60d6fc
Fix test
lunny 1e4da5b
Fix test
lunny 1d9b7a1
Fix test
lunny c32d4aa
Merge branch 'main' into lunny/issue_dev
lunny ed8c578
Merge branch 'main' into lunny/issue_dev
lunny 94424b7
Fix lint
lunny bad9ae0
Fix test
lunny eadebf3
Merge branch 'main' into lunny/issue_dev
lunny 9b5e3c5
Fix test
lunny 1ac03bb
Fix lint
lunny 4f4370c
Merge branch 'main' into lunny/issue_dev
lunny 72ba762
improvements
lunny baffff2
revert unnecessary change
lunny e8d4ec8
Merge branch 'main' into lunny/issue_dev
lunny e3525f5
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 hidden or 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 hidden or 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 hidden or 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,59 @@ | ||
| // Copyright 2024 The Gitea Authors. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package issues | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "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 | ||
| 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:"-"` | ||
| PullRequest *PullRequest `xorm:"-"` | ||
| Branch *git_model.Branch `xorm:"-"` | ||
| DisplayBranch bool `xorm:"-"` | ||
| } | ||
|
|
||
| func init() { | ||
| db.RegisterModel(new(IssueDevLink)) | ||
| } | ||
|
|
||
| func (i *IssueDevLink) BranchFullName() string { | ||
| if i.Repo.ID == i.LinkedRepo.ID { | ||
| return i.Branch.Name | ||
| } | ||
| return i.LinkedRepo.FullName() + ":" + i.Branch.Name | ||
| } | ||
|
|
||
| // 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 CreateIssueDevLink(ctx context.Context, link *IssueDevLink) error { | ||
| _, err := db.GetEngine(ctx).Insert(link) | ||
| return err | ||
| } | ||
This file contains hidden or 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 hidden or 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 2025 The Gitea Authors. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package v1_26 | ||
|
|
||
| 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 | ||
| LinkID int64 // branch id in branch table or pull request id | ||
| CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` | ||
| } | ||
| return x.Sync(new(IssueDevLink)) | ||
| } |
This file contains hidden or 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,20 @@ | ||
| // Copyright 2025 The Gitea Authors. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package v1_26 | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "code.gitea.io/gitea/models/migrations/base" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func Test_CreateTableIssueDevLink(t *testing.T) { | ||
| // Prepare and load the testing database | ||
| x, deferable := base.PrepareTestEnv(t, 0) | ||
| defer deferable() | ||
|
|
||
| assert.NoError(t, CreateTableIssueDevLink(x)) | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,112 @@ | ||
| // 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/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 | ||
| // if create branch in a forked repository | ||
| if form.RepoID > 0 && form.RepoID != repo.ID { | ||
| var err error | ||
| repo, err = repo_model.GetRepositoryByID(ctx, form.RepoID) | ||
| if err != nil { | ||
| ctx.ServerError("GetRepositoryByID", err) | ||
| return | ||
| } | ||
| } | ||
|
|
||
| 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.HTTPError(http.StatusForbidden, "No permission to create branch in this repository") | ||
| return | ||
| } | ||
|
|
||
| if err := repo_service.CreateNewBranch(ctx, ctx.Doer, repo, 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_model.IsErrBranchNotExist(err): | ||
| ctx.JSONError(ctx.Tr("repo.branch.branch_not_exist", form.SourceBranchName)) | ||
| 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 | ||
| } | ||
|
|
||
| branch, err := git_model.GetBranch(ctx, repo.ID, form.NewBranchName) | ||
| if err != nil { | ||
| ctx.ServerError("GetBranch", err) | ||
| return | ||
| } | ||
|
|
||
| if err := issues_model.CreateIssueDevLink(ctx, &issues_model.IssueDevLink{ | ||
| IssueID: issue.ID, | ||
| LinkType: issues_model.IssueDevLinkTypeBranch, | ||
| LinkedRepoID: repo.ID, | ||
| LinkID: branch.ID, | ||
| }); err != nil { | ||
| ctx.ServerError("CreateIssueDevLink", err) | ||
| return | ||
| } | ||
|
|
||
| ctx.Flash.Success(ctx.Tr("repo.issues.create_branch_from_issue_success", form.NewBranchName)) | ||
| ctx.JSONRedirect(issue.Link()) | ||
| } | ||
This file contains hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.