mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Add a new section named development in issue view sidebar to interact with branch/pr
This commit is contained in:
77
models/issues/issue_dev_link.go
Normal file
77
models/issues/issue_dev_link.go
Normal file
@@ -0,0 +1,77 @@
|
||||
// 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:"-"`
|
||||
}
|
||||
|
||||
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("link_type = ? AND link_index = ? AND linked_repo_id = ?",
|
||||
IssueDevLinkTypeBranch, branchName, repoID).
|
||||
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
|
||||
}
|
@@ -601,6 +601,8 @@ var migrations = []Migration{
|
||||
NewMigration("Add metadata column for comment table", v1_23.AddCommentMetaDataColumn),
|
||||
// v304 -> v305
|
||||
NewMigration("Add index for release sha1", v1_23.AddIndexForReleaseSha1),
|
||||
// v305 -> v306
|
||||
NewMigration("Add table issue_dev_link", v1_23.CreateTableIssueDevLink),
|
||||
}
|
||||
|
||||
// GetCurrentDBVersion returns the current db version
|
||||
|
21
models/migrations/v1_23/v305.go
Normal file
21
models/migrations/v1_23/v305.go
Normal file
@@ -0,0 +1,21 @@
|
||||
// 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
|
||||
LinkIndex string // branch name, pull request number or commit sha
|
||||
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
|
||||
}
|
||||
return x.Sync(new(IssueDevLink))
|
||||
}
|
@@ -508,16 +508,20 @@ func HasOrgsVisible(ctx context.Context, orgs []*Organization, user *user_model.
|
||||
return false
|
||||
}
|
||||
|
||||
func orgAllowedCreatedRepoSubQuery(userID int64) *builder.Builder {
|
||||
return builder.Select("`user`.id").From("`user`").
|
||||
Join("INNER", "`team_user`", "`team_user`.org_id = `user`.id").
|
||||
Join("INNER", "`team`", "`team`.id = `team_user`.team_id").
|
||||
Where(builder.Eq{"`team_user`.uid": userID}).
|
||||
And(builder.Eq{"`team`.authorize": perm.AccessModeOwner}.Or(builder.Eq{"`team`.can_create_org_repo": true}))
|
||||
}
|
||||
|
||||
// GetOrgsCanCreateRepoByUserID returns a list of organizations where given user ID
|
||||
// are allowed to create repos.
|
||||
func GetOrgsCanCreateRepoByUserID(ctx context.Context, userID int64) ([]*Organization, error) {
|
||||
orgs := make([]*Organization, 0, 10)
|
||||
|
||||
return orgs, db.GetEngine(ctx).Where(builder.In("id", builder.Select("`user`.id").From("`user`").
|
||||
Join("INNER", "`team_user`", "`team_user`.org_id = `user`.id").
|
||||
Join("INNER", "`team`", "`team`.id = `team_user`.team_id").
|
||||
Where(builder.Eq{"`team_user`.uid": userID}).
|
||||
And(builder.Eq{"`team`.authorize": perm.AccessModeOwner}.Or(builder.Eq{"`team`.can_create_org_repo": true})))).
|
||||
return orgs, db.GetEngine(ctx).Where(builder.In("id", orgAllowedCreatedRepoSubQuery(userID))).
|
||||
Asc("`user`.name").
|
||||
Find(&orgs)
|
||||
}
|
||||
|
Reference in New Issue
Block a user