mirror of
https://github.com/go-gitea/gitea
synced 2024-06-01 19:06:52 +02:00
Compare commits
5 Commits
ed56a0f5fc
...
f7f36ddbaa
Author | SHA1 | Date | |
---|---|---|---|
|
f7f36ddbaa | ||
|
cf9ef10510 | ||
|
e8e934cb16 | ||
|
b27dde914d | ||
|
c7bb3aa034 |
|
@ -90,68 +90,63 @@ func LoadIssuesFromBoardList(ctx context.Context, bs project_model.BoardList) (m
|
||||||
return issuesMap, nil
|
return issuesMap, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChangeProjectAssign changes the project associated with an issue, if newProjectID is 0, the issue is removed from the project
|
// IssueAssignOrRemoveProject changes the project associated with an issue
|
||||||
func ChangeProjectAssign(ctx context.Context, issue *Issue, doer *user_model.User, newProjectID, newColumnID int64) error {
|
|
||||||
return db.WithTx(ctx, func(ctx context.Context) error {
|
|
||||||
return addUpdateIssueProject(ctx, issue, doer, newProjectID, newColumnID)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// addUpdateIssueProject adds or updates the project the default column associated with an issue
|
|
||||||
// If newProjectID is 0, the issue is removed from the project
|
// If newProjectID is 0, the issue is removed from the project
|
||||||
func addUpdateIssueProject(ctx context.Context, issue *Issue, doer *user_model.User, newProjectID, newColumnID int64) error {
|
func IssueAssignOrRemoveProject(ctx context.Context, issue *Issue, doer *user_model.User, newProjectID, newColumnID int64) error {
|
||||||
oldProjectID := issue.projectID(ctx)
|
return db.WithTx(ctx, func(ctx context.Context) error {
|
||||||
|
oldProjectID := issue.projectID(ctx)
|
||||||
|
|
||||||
if err := issue.LoadRepo(ctx); err != nil {
|
if err := issue.LoadRepo(ctx); err != nil {
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Only check if we add a new project and not remove it.
|
|
||||||
if newProjectID > 0 {
|
|
||||||
newProject, err := project_model.GetProjectByID(ctx, newProjectID)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if newProject.RepoID != issue.RepoID && newProject.OwnerID != issue.Repo.OwnerID {
|
|
||||||
return fmt.Errorf("issue's repository is not the same as project's repository")
|
// Only check if we add a new project and not remove it.
|
||||||
|
if newProjectID > 0 {
|
||||||
|
newProject, err := project_model.GetProjectByID(ctx, newProjectID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if newProject.RepoID != issue.RepoID && newProject.OwnerID != issue.Repo.OwnerID {
|
||||||
|
return fmt.Errorf("issue's repository is not the same as project's repository")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := db.GetEngine(ctx).Where("project_issue.issue_id=?", issue.ID).Delete(&project_model.ProjectIssue{}); err != nil {
|
if _, err := db.GetEngine(ctx).Where("project_issue.issue_id=?", issue.ID).Delete(&project_model.ProjectIssue{}); err != nil {
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if oldProjectID > 0 || newProjectID > 0 {
|
|
||||||
if _, err := CreateComment(ctx, &CreateCommentOptions{
|
|
||||||
Type: CommentTypeProject,
|
|
||||||
Doer: doer,
|
|
||||||
Repo: issue.Repo,
|
|
||||||
Issue: issue,
|
|
||||||
OldProjectID: oldProjectID,
|
|
||||||
ProjectID: newProjectID,
|
|
||||||
}); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if newProjectID == 0 || newColumnID == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var maxSorting int64
|
if oldProjectID > 0 || newProjectID > 0 {
|
||||||
if _, err := db.GetEngine(ctx).Select("Max(sorting)").Table("project_issue").
|
if _, err := CreateComment(ctx, &CreateCommentOptions{
|
||||||
Where("project_id=?", newProjectID).
|
Type: CommentTypeProject,
|
||||||
And("project_board_id=?", newColumnID).
|
Doer: doer,
|
||||||
Get(&maxSorting); err != nil {
|
Repo: issue.Repo,
|
||||||
return err
|
Issue: issue,
|
||||||
}
|
OldProjectID: oldProjectID,
|
||||||
if maxSorting > 0 {
|
ProjectID: newProjectID,
|
||||||
maxSorting++
|
}); err != nil {
|
||||||
}
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if newProjectID == 0 || newColumnID == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
return db.Insert(ctx, &project_model.ProjectIssue{
|
var maxSorting int64
|
||||||
IssueID: issue.ID,
|
if _, err := db.GetEngine(ctx).Select("Max(sorting)").Table("project_issue").
|
||||||
ProjectID: newProjectID,
|
Where("project_id=?", newProjectID).
|
||||||
ProjectBoardID: newColumnID,
|
And("project_board_id=?", newColumnID).
|
||||||
Sorting: maxSorting,
|
Get(&maxSorting); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if maxSorting > 0 {
|
||||||
|
maxSorting++
|
||||||
|
}
|
||||||
|
|
||||||
|
return db.Insert(ctx, &project_model.ProjectIssue{
|
||||||
|
IssueID: issue.ID,
|
||||||
|
ProjectID: newProjectID,
|
||||||
|
ProjectBoardID: newColumnID,
|
||||||
|
Sorting: maxSorting,
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
|
"code.gitea.io/gitea/modules/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ProjectIssue saves relation from issue to a project
|
// ProjectIssue saves relation from issue to a project
|
||||||
|
@ -79,11 +80,8 @@ func (p *Project) NumOpenIssues(ctx context.Context) int {
|
||||||
func MoveIssuesOnProjectBoard(ctx context.Context, board *Board, sortedIssueIDs map[int64]int64) error {
|
func MoveIssuesOnProjectBoard(ctx context.Context, board *Board, sortedIssueIDs map[int64]int64) error {
|
||||||
return db.WithTx(ctx, func(ctx context.Context) error {
|
return db.WithTx(ctx, func(ctx context.Context) error {
|
||||||
sess := db.GetEngine(ctx)
|
sess := db.GetEngine(ctx)
|
||||||
|
issueIDs := util.ValuesOfMap(sortedIssueIDs)
|
||||||
|
|
||||||
issueIDs := make([]int64, 0, len(sortedIssueIDs))
|
|
||||||
for _, issueID := range sortedIssueIDs {
|
|
||||||
issueIDs = append(issueIDs, issueID)
|
|
||||||
}
|
|
||||||
count, err := sess.Table(new(ProjectIssue)).Where("project_id=?", board.ProjectID).In("issue_id", issueIDs).Count()
|
count, err := sess.Table(new(ProjectIssue)).Where("project_id=?", board.ProjectID).In("issue_id", issueIDs).Count()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -103,12 +101,38 @@ func MoveIssuesOnProjectBoard(ctx context.Context, board *Board, sortedIssueIDs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Board) moveIssuesToAnotherColumn(ctx context.Context, newColumn *Board) error {
|
func (b *Board) moveIssuesToAnotherColumn(ctx context.Context, newColumn *Board) error {
|
||||||
if b.ID == newColumn.ID {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if b.ProjectID != newColumn.ProjectID {
|
if b.ProjectID != newColumn.ProjectID {
|
||||||
return fmt.Errorf("columns have to be in the same project")
|
return fmt.Errorf("columns have to be in the same project")
|
||||||
}
|
}
|
||||||
_, err := db.GetEngine(ctx).Exec("UPDATE `project_issue` SET project_board_id = ? WHERE project_board_id = ? ", newColumn.ID, b.ID)
|
|
||||||
return err
|
if b.ID == newColumn.ID {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var maxSorting int8
|
||||||
|
if _, err := db.GetEngine(ctx).Select("Max(sorting)").Table("project_issue").
|
||||||
|
Where("project_id=?", newColumn.ProjectID).
|
||||||
|
And("project_board_id=?", newColumn.ID).
|
||||||
|
Get(&maxSorting); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if maxSorting > 0 {
|
||||||
|
maxSorting++
|
||||||
|
}
|
||||||
|
|
||||||
|
issues, err := b.GetIssues(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return db.WithTx(ctx, func(ctx context.Context) error {
|
||||||
|
for i, issue := range issues {
|
||||||
|
issue.ProjectBoardID = newColumn.ID
|
||||||
|
issue.Sorting = int64(maxSorting) + int64(i)
|
||||||
|
if _, err := db.GetEngine(ctx).Cols("project_board_id", "sorting").Update(issue); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
@ -54,7 +55,7 @@ var (
|
||||||
shortLinkPattern = regexp.MustCompile(`\[\[(.*?)\]\](\w*)`)
|
shortLinkPattern = regexp.MustCompile(`\[\[(.*?)\]\](\w*)`)
|
||||||
|
|
||||||
// anyHashPattern splits url containing SHA into parts
|
// anyHashPattern splits url containing SHA into parts
|
||||||
anyHashPattern = regexp.MustCompile(`https?://(?:\S+/){4,5}([0-9a-f]{40,64})(/[-+~_%.a-zA-Z0-9/]+)?(#[-+~_%.a-zA-Z0-9]+)?`)
|
anyHashPattern = regexp.MustCompile(`https?://(?:\S+/){4,5}([0-9a-f]{40,64})(/[-+~%./\w]+)?(\?[-+~%.\w&=]+)?(#[-+~%.\w]+)?`)
|
||||||
|
|
||||||
// comparePattern matches "http://domain/org/repo/compare/COMMIT1...COMMIT2#hash"
|
// comparePattern matches "http://domain/org/repo/compare/COMMIT1...COMMIT2#hash"
|
||||||
comparePattern = regexp.MustCompile(`https?://(?:\S+/){4,5}([0-9a-f]{7,64})(\.\.\.?)([0-9a-f]{7,64})?(#[-+~_%.a-zA-Z0-9]+)?`)
|
comparePattern = regexp.MustCompile(`https?://(?:\S+/){4,5}([0-9a-f]{7,64})(\.\.\.?)([0-9a-f]{7,64})?(#[-+~_%.a-zA-Z0-9]+)?`)
|
||||||
|
@ -591,7 +592,8 @@ func replaceContentList(node *html.Node, i, j int, newNodes []*html.Node) {
|
||||||
|
|
||||||
func mentionProcessor(ctx *RenderContext, node *html.Node) {
|
func mentionProcessor(ctx *RenderContext, node *html.Node) {
|
||||||
start := 0
|
start := 0
|
||||||
for node != nil {
|
nodeStop := node.NextSibling
|
||||||
|
for node != nodeStop {
|
||||||
found, loc := references.FindFirstMentionBytes(util.UnsafeStringToBytes(node.Data[start:]))
|
found, loc := references.FindFirstMentionBytes(util.UnsafeStringToBytes(node.Data[start:]))
|
||||||
if !found {
|
if !found {
|
||||||
node = node.NextSibling
|
node = node.NextSibling
|
||||||
|
@ -962,57 +964,68 @@ func commitCrossReferencePatternProcessor(ctx *RenderContext, node *html.Node) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type anyHashPatternResult struct {
|
||||||
|
PosStart int
|
||||||
|
PosEnd int
|
||||||
|
FullURL string
|
||||||
|
CommitID string
|
||||||
|
SubPath string
|
||||||
|
QueryHash string
|
||||||
|
}
|
||||||
|
|
||||||
|
func anyHashPatternExtract(s string) (ret anyHashPatternResult, ok bool) {
|
||||||
|
m := anyHashPattern.FindStringSubmatchIndex(s)
|
||||||
|
if m == nil {
|
||||||
|
return ret, false
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.PosStart, ret.PosEnd = m[0], m[1]
|
||||||
|
ret.FullURL = s[ret.PosStart:ret.PosEnd]
|
||||||
|
if strings.HasSuffix(ret.FullURL, ".") {
|
||||||
|
// if url ends in '.', it's very likely that it is not part of the actual url but used to finish a sentence.
|
||||||
|
ret.PosEnd--
|
||||||
|
ret.FullURL = ret.FullURL[:len(ret.FullURL)-1]
|
||||||
|
for i := 0; i < len(m); i++ {
|
||||||
|
m[i] = min(m[i], ret.PosEnd)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.CommitID = s[m[2]:m[3]]
|
||||||
|
if m[5] > 0 {
|
||||||
|
ret.SubPath = s[m[4]:m[5]]
|
||||||
|
}
|
||||||
|
|
||||||
|
lastStart, lastEnd := m[len(m)-2], m[len(m)-1]
|
||||||
|
if lastEnd > 0 {
|
||||||
|
ret.QueryHash = s[lastStart:lastEnd][1:]
|
||||||
|
}
|
||||||
|
return ret, true
|
||||||
|
}
|
||||||
|
|
||||||
// fullHashPatternProcessor renders SHA containing URLs
|
// fullHashPatternProcessor renders SHA containing URLs
|
||||||
func fullHashPatternProcessor(ctx *RenderContext, node *html.Node) {
|
func fullHashPatternProcessor(ctx *RenderContext, node *html.Node) {
|
||||||
if ctx.Metas == nil {
|
if ctx.Metas == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
nodeStop := node.NextSibling
|
||||||
next := node.NextSibling
|
for node != nodeStop {
|
||||||
for node != nil && node != next {
|
if node.Type != html.TextNode {
|
||||||
m := anyHashPattern.FindStringSubmatchIndex(node.Data)
|
node = node.NextSibling
|
||||||
if m == nil {
|
continue
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
ret, ok := anyHashPatternExtract(node.Data)
|
||||||
urlFull := node.Data[m[0]:m[1]]
|
if !ok {
|
||||||
text := base.ShortSha(node.Data[m[2]:m[3]])
|
node = node.NextSibling
|
||||||
|
continue
|
||||||
// 3rd capture group matches a optional path
|
|
||||||
subpath := ""
|
|
||||||
if m[5] > 0 {
|
|
||||||
subpath = node.Data[m[4]:m[5]]
|
|
||||||
}
|
}
|
||||||
|
text := base.ShortSha(ret.CommitID)
|
||||||
// 4th capture group matches a optional url hash
|
if ret.SubPath != "" {
|
||||||
hash := ""
|
text += ret.SubPath
|
||||||
if m[7] > 0 {
|
|
||||||
hash = node.Data[m[6]:m[7]][1:]
|
|
||||||
}
|
}
|
||||||
|
if ret.QueryHash != "" {
|
||||||
start := m[0]
|
text += " (" + ret.QueryHash + ")"
|
||||||
end := m[1]
|
|
||||||
|
|
||||||
// If url ends in '.', it's very likely that it is not part of the
|
|
||||||
// actual url but used to finish a sentence.
|
|
||||||
if strings.HasSuffix(urlFull, ".") {
|
|
||||||
end--
|
|
||||||
urlFull = urlFull[:len(urlFull)-1]
|
|
||||||
if hash != "" {
|
|
||||||
hash = hash[:len(hash)-1]
|
|
||||||
} else if subpath != "" {
|
|
||||||
subpath = subpath[:len(subpath)-1]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
replaceContent(node, ret.PosStart, ret.PosEnd, createCodeLink(ret.FullURL, text, "commit"))
|
||||||
if subpath != "" {
|
|
||||||
text += subpath
|
|
||||||
}
|
|
||||||
|
|
||||||
if hash != "" {
|
|
||||||
text += " (" + hash + ")"
|
|
||||||
}
|
|
||||||
replaceContent(node, start, end, createCodeLink(urlFull, text, "commit"))
|
|
||||||
node = node.NextSibling.NextSibling
|
node = node.NextSibling.NextSibling
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1021,19 +1034,16 @@ func comparePatternProcessor(ctx *RenderContext, node *html.Node) {
|
||||||
if ctx.Metas == nil {
|
if ctx.Metas == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
nodeStop := node.NextSibling
|
||||||
next := node.NextSibling
|
for node != nodeStop {
|
||||||
for node != nil && node != next {
|
if node.Type != html.TextNode {
|
||||||
m := comparePattern.FindStringSubmatchIndex(node.Data)
|
node = node.NextSibling
|
||||||
if m == nil {
|
continue
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
m := comparePattern.FindStringSubmatchIndex(node.Data)
|
||||||
// Ensure that every group (m[0]...m[7]) has a match
|
if m == nil || slices.Contains(m[:8], -1) { // ensure that every group (m[0]...m[7]) has a match
|
||||||
for i := 0; i < 8; i++ {
|
node = node.NextSibling
|
||||||
if m[i] == -1 {
|
continue
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
urlFull := node.Data[m[0]:m[1]]
|
urlFull := node.Data[m[0]:m[1]]
|
||||||
|
|
|
@ -60,7 +60,8 @@ func renderCodeBlock(ctx *RenderContext, node *html.Node) (urlPosStart, urlPosSt
|
||||||
}
|
}
|
||||||
|
|
||||||
func codePreviewPatternProcessor(ctx *RenderContext, node *html.Node) {
|
func codePreviewPatternProcessor(ctx *RenderContext, node *html.Node) {
|
||||||
for node != nil {
|
nodeStop := node.NextSibling
|
||||||
|
for node != nodeStop {
|
||||||
if node.Type != html.TextNode {
|
if node.Type != html.TextNode {
|
||||||
node = node.NextSibling
|
node = node.NextSibling
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -399,36 +399,61 @@ func TestRegExp_sha1CurrentPattern(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRegExp_anySHA1Pattern(t *testing.T) {
|
func TestRegExp_anySHA1Pattern(t *testing.T) {
|
||||||
testCases := map[string][]string{
|
testCases := map[string]anyHashPatternResult{
|
||||||
"https://github.com/jquery/jquery/blob/a644101ed04d0beacea864ce805e0c4f86ba1cd1/test/unit/event.js#L2703": {
|
"https://github.com/jquery/jquery/blob/a644101ed04d0beacea864ce805e0c4f86ba1cd1/test/unit/event.js#L2703": {
|
||||||
"a644101ed04d0beacea864ce805e0c4f86ba1cd1",
|
CommitID: "a644101ed04d0beacea864ce805e0c4f86ba1cd1",
|
||||||
"/test/unit/event.js",
|
SubPath: "/test/unit/event.js",
|
||||||
"#L2703",
|
QueryHash: "L2703",
|
||||||
},
|
},
|
||||||
"https://github.com/jquery/jquery/blob/a644101ed04d0beacea864ce805e0c4f86ba1cd1/test/unit/event.js": {
|
"https://github.com/jquery/jquery/blob/a644101ed04d0beacea864ce805e0c4f86ba1cd1/test/unit/event.js": {
|
||||||
"a644101ed04d0beacea864ce805e0c4f86ba1cd1",
|
CommitID: "a644101ed04d0beacea864ce805e0c4f86ba1cd1",
|
||||||
"/test/unit/event.js",
|
SubPath: "/test/unit/event.js",
|
||||||
"",
|
|
||||||
},
|
},
|
||||||
"https://github.com/jquery/jquery/commit/0705be475092aede1eddae01319ec931fb9c65fc": {
|
"https://github.com/jquery/jquery/commit/0705be475092aede1eddae01319ec931fb9c65fc": {
|
||||||
"0705be475092aede1eddae01319ec931fb9c65fc",
|
CommitID: "0705be475092aede1eddae01319ec931fb9c65fc",
|
||||||
"",
|
|
||||||
"",
|
|
||||||
},
|
},
|
||||||
"https://github.com/jquery/jquery/tree/0705be475092aede1eddae01319ec931fb9c65fc/src": {
|
"https://github.com/jquery/jquery/tree/0705be475092aede1eddae01319ec931fb9c65fc/src": {
|
||||||
"0705be475092aede1eddae01319ec931fb9c65fc",
|
CommitID: "0705be475092aede1eddae01319ec931fb9c65fc",
|
||||||
"/src",
|
SubPath: "/src",
|
||||||
"",
|
|
||||||
},
|
},
|
||||||
"https://try.gogs.io/gogs/gogs/commit/d8a994ef243349f321568f9e36d5c3f444b99cae#diff-2": {
|
"https://try.gogs.io/gogs/gogs/commit/d8a994ef243349f321568f9e36d5c3f444b99cae#diff-2": {
|
||||||
"d8a994ef243349f321568f9e36d5c3f444b99cae",
|
CommitID: "d8a994ef243349f321568f9e36d5c3f444b99cae",
|
||||||
"",
|
QueryHash: "diff-2",
|
||||||
"#diff-2",
|
},
|
||||||
|
"non-url": {},
|
||||||
|
"http://a/b/c/d/e/1234567812345678123456781234567812345678123456781234567812345678?a=b#L1-L2": {
|
||||||
|
CommitID: "1234567812345678123456781234567812345678123456781234567812345678",
|
||||||
|
QueryHash: "L1-L2",
|
||||||
|
},
|
||||||
|
"http://a/b/c/d/e/1234567812345678123456781234567812345678123456781234567812345678.": {
|
||||||
|
CommitID: "1234567812345678123456781234567812345678123456781234567812345678",
|
||||||
|
},
|
||||||
|
"http://a/b/c/d/e/1234567812345678123456781234567812345678123456781234567812345678/sub.": {
|
||||||
|
CommitID: "1234567812345678123456781234567812345678123456781234567812345678",
|
||||||
|
SubPath: "/sub",
|
||||||
|
},
|
||||||
|
"http://a/b/c/d/e/1234567812345678123456781234567812345678123456781234567812345678?a=b.": {
|
||||||
|
CommitID: "1234567812345678123456781234567812345678123456781234567812345678",
|
||||||
|
},
|
||||||
|
"http://a/b/c/d/e/1234567812345678123456781234567812345678123456781234567812345678?a=b&c=d": {
|
||||||
|
CommitID: "1234567812345678123456781234567812345678123456781234567812345678",
|
||||||
|
},
|
||||||
|
"http://a/b/c/d/e/1234567812345678123456781234567812345678123456781234567812345678#hash.": {
|
||||||
|
CommitID: "1234567812345678123456781234567812345678123456781234567812345678",
|
||||||
|
QueryHash: "hash",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range testCases {
|
for k, v := range testCases {
|
||||||
assert.Equal(t, anyHashPattern.FindStringSubmatch(k)[1:], v)
|
ret, ok := anyHashPatternExtract(k)
|
||||||
|
if v.CommitID == "" {
|
||||||
|
assert.False(t, ok)
|
||||||
|
} else {
|
||||||
|
assert.EqualValues(t, strings.TrimSuffix(k, "."), ret.FullURL)
|
||||||
|
assert.EqualValues(t, v.CommitID, ret.CommitID)
|
||||||
|
assert.EqualValues(t, v.SubPath, ret.SubPath)
|
||||||
|
assert.EqualValues(t, v.QueryHash, ret.QueryHash)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -124,6 +124,11 @@ func TestRender_CrossReferences(t *testing.T) {
|
||||||
test(
|
test(
|
||||||
util.URLJoin(markup.TestAppURL, "gogitea", "some-repo-name", "issues", "12345"),
|
util.URLJoin(markup.TestAppURL, "gogitea", "some-repo-name", "issues", "12345"),
|
||||||
`<p><a href="`+util.URLJoin(markup.TestAppURL, "gogitea", "some-repo-name", "issues", "12345")+`" class="ref-issue" rel="nofollow">gogitea/some-repo-name#12345</a></p>`)
|
`<p><a href="`+util.URLJoin(markup.TestAppURL, "gogitea", "some-repo-name", "issues", "12345")+`" class="ref-issue" rel="nofollow">gogitea/some-repo-name#12345</a></p>`)
|
||||||
|
|
||||||
|
inputURL := "https://host/a/b/commit/0123456789012345678901234567890123456789/foo.txt?a=b#L2-L3"
|
||||||
|
test(
|
||||||
|
inputURL,
|
||||||
|
`<p><a href="`+inputURL+`" rel="nofollow"><code>0123456789/foo.txt (L2-L3)</code></a></p>`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMisc_IsSameDomain(t *testing.T) {
|
func TestMisc_IsSameDomain(t *testing.T) {
|
||||||
|
@ -695,7 +700,7 @@ func TestIssue18471(t *testing.T) {
|
||||||
}, strings.NewReader(data), &res)
|
}, strings.NewReader(data), &res)
|
||||||
|
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "<a href=\"http://domain/org/repo/compare/783b039...da951ce\" class=\"compare\"><code class=\"nohighlight\">783b039...da951ce</code></a>", res.String())
|
assert.Equal(t, `<a href="http://domain/org/repo/compare/783b039...da951ce" class="compare"><code class="nohighlight">783b039...da951ce</code></a>`, res.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIsFullURL(t *testing.T) {
|
func TestIsFullURL(t *testing.T) {
|
||||||
|
|
|
@ -471,7 +471,7 @@ func UpdateIssueProject(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := issues_model.ChangeProjectAssign(ctx, issue, ctx.Doer, projectID, dstColumnID); err != nil {
|
if err := issues_model.IssueAssignOrRemoveProject(ctx, issue, ctx.Doer, projectID, dstColumnID); err != nil {
|
||||||
ctx.ServerError("ChangeProjectAssign", err)
|
ctx.ServerError("ChangeProjectAssign", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -417,7 +417,7 @@ func UpdateIssueProject(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := issues_model.ChangeProjectAssign(ctx, issue, ctx.Doer, projectID, dstColumnID); err != nil {
|
if err := issues_model.IssueAssignOrRemoveProject(ctx, issue, ctx.Doer, projectID, dstColumnID); err != nil {
|
||||||
ctx.ServerError("ChangeProjectAssign", err)
|
ctx.ServerError("ChangeProjectAssign", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -1348,7 +1348,7 @@ func CompareAndPullRequestPost(ctx *context.Context) {
|
||||||
ctx.ServerError("GetDefaultBoard", err)
|
ctx.ServerError("GetDefaultBoard", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := issues_model.ChangeProjectAssign(ctx, pullIssue, ctx.Doer, projectID, dstDefaultColumn.ID); err != nil {
|
if err := issues_model.IssueAssignOrRemoveProject(ctx, pullIssue, ctx.Doer, projectID, dstDefaultColumn.ID); err != nil {
|
||||||
ctx.ServerError("ChangeProjectAssign", err)
|
ctx.ServerError("ChangeProjectAssign", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ func NewIssue(ctx context.Context, repo *repo_model.Repository, issue *issues_mo
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := issues_model.ChangeProjectAssign(ctx, issue, issue.Poster, projectID, defaultBoard.ID); err != nil {
|
if err := issues_model.IssueAssignOrRemoveProject(ctx, issue, issue.Poster, projectID, defaultBoard.ID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,4 +58,14 @@ func TestMoveRepoProjectColumns(t *testing.T) {
|
||||||
assert.EqualValues(t, columns[1].ID, columnsAfter[0].ID)
|
assert.EqualValues(t, columns[1].ID, columnsAfter[0].ID)
|
||||||
assert.EqualValues(t, columns[2].ID, columnsAfter[1].ID)
|
assert.EqualValues(t, columns[2].ID, columnsAfter[1].ID)
|
||||||
assert.EqualValues(t, columns[0].ID, columnsAfter[2].ID)
|
assert.EqualValues(t, columns[0].ID, columnsAfter[2].ID)
|
||||||
|
|
||||||
|
// update the sorting back
|
||||||
|
req = NewRequestWithJSON(t, "POST", "/user2/repo1/projects/1/move?_csrf="+htmlDoc.GetCSRF(), map[string]any{
|
||||||
|
"columns": []map[string]any{
|
||||||
|
{"columnID": columns[0].ID, "sorting": 0},
|
||||||
|
{"columnID": columns[1].ID, "sorting": 1},
|
||||||
|
{"columnID": columns[2].ID, "sorting": 2},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
sess.MakeRequest(t, req, http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user