Skip to content

Commit

Permalink
Merge branch 'master' into fix-12440-prevent-panic-on-git-blame
Browse files Browse the repository at this point in the history
  • Loading branch information
zeripath authored Nov 10, 2020
2 parents c3602de + 77e5081 commit eea6584
Show file tree
Hide file tree
Showing 24 changed files with 348 additions and 92 deletions.
2 changes: 1 addition & 1 deletion docs/content/doc/features/comparison.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ _Symbols used in table:_
| Built-in Container Registry | [](https://github.com/go-gitea/gitea/issues/2316) |||||||
| External git mirroring ||||||||
| FIDO U2F (2FA) ||||||||
| Built-in CI/CD ||| |||||
| Built-in CI/CD ||| |||||
| Subgroups: groups within groups ||||||||

#### Code management
Expand Down
27 changes: 27 additions & 0 deletions docs/content/doc/installation/on-kubernetes.en-us.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
date: "2020-03-19T19:27:00+02:00"
title: "Install on Kubernetes"
slug: "install-on-kubernetes"
weight: 10
toc: true
draft: false
menu:
sidebar:
parent: "installation"
name: "Kubernetes"
weight: 50
identifier: "install-on-kubernetes"
---

# Installation with Helm (on Kubernetes)

Gitea provides a Helm Chart to allow for installation on kubernetes.

A non-customized install can be done with:

```
helm repo add gitea-charts https://dl.gitea.io/charts/
helm install gitea gitea-charts/gitea
```

If you would like to customize your install, which includes kubernetes ingress, please refer to the complete [Gitea helm chart configuration details](https://gitea.com/gitea/helm-chart/)
4 changes: 4 additions & 0 deletions integrations/api_helper_for_declarative_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ func doAPIMergePullRequest(ctx APITestContext, owner, repo string, index int64)
DecodeJSON(t, resp, &err)
assert.EqualValues(t, "Please try again later", err.Message)
queue.GetManager().FlushAll(context.Background(), 5*time.Second)
req = NewRequestWithJSON(t, http.MethodPost, urlStr, &auth.MergePullRequestForm{
MergeMessageField: "doAPIMergePullRequest Merge",
Do: string(models.MergeStyleMerge),
})
resp = ctx.Session.MakeRequest(t, req, NoExpectedStatus)
}

Expand Down
3 changes: 1 addition & 2 deletions integrations/repo_branch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,12 @@ func testCreateBranches(t *testing.T, giteaURL *url.URL) {
{
OldRefSubURL: "tag/v1.0.0",
NewBranch: "feature/test4",
CreateRelease: "v1.0.0",
CreateRelease: "v1.0.1",
ExpectedStatus: http.StatusFound,
FlashMessage: i18n.Tr("en", "repo.branch.create_success", "feature/test4"),
},
}
for _, test := range tests {
defer prepareTestEnv(t)()
session := loginUser(t, "user2")
if test.CreateRelease != "" {
createNewRelease(t, session, "/user2/repo1", test.CreateRelease, test.CreateRelease, false, false)
Expand Down
3 changes: 1 addition & 2 deletions integrations/repo_commits_search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (
)

func testRepoCommitsSearch(t *testing.T, query, commit string) {
defer prepareTestEnv(t)()

session := loginUser(t, "user2")

// Request repository commits page
Expand All @@ -28,6 +26,7 @@ func testRepoCommitsSearch(t *testing.T, query, commit string) {
}

func TestRepoCommitsSearch(t *testing.T) {
defer prepareTestEnv(t)()
testRepoCommitsSearch(t, "e8eabd", "")
testRepoCommitsSearch(t, "38a9cb", "")
testRepoCommitsSearch(t, "6e8e", "6e8eabd9a7")
Expand Down
12 changes: 12 additions & 0 deletions models/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err
RefAction: opts.RefAction,
RefIsPull: opts.RefIsPull,
IsForcePush: opts.IsForcePush,
Invalidated: opts.Invalidated,
}
if _, err = e.Insert(comment); err != nil {
return nil, err
Expand Down Expand Up @@ -878,6 +879,7 @@ type CreateCommentOptions struct {
RefAction references.XRefAction
RefIsPull bool
IsForcePush bool
Invalidated bool
}

// CreateComment creates comment of issue or commit.
Expand Down Expand Up @@ -953,6 +955,8 @@ type FindCommentsOptions struct {
ReviewID int64
Since int64
Before int64
Line int64
TreePath string
Type CommentType
}

Expand All @@ -976,6 +980,12 @@ func (opts *FindCommentsOptions) toConds() builder.Cond {
if opts.Type != CommentTypeUnknown {
cond = cond.And(builder.Eq{"comment.type": opts.Type})
}
if opts.Line > 0 {
cond = cond.And(builder.Eq{"comment.line": opts.Line})
}
if len(opts.TreePath) > 0 {
cond = cond.And(builder.Eq{"comment.tree_path": opts.TreePath})
}
return cond
}

Expand All @@ -990,6 +1000,8 @@ func findComments(e Engine, opts FindCommentsOptions) ([]*Comment, error) {
sess = opts.setSessionPagination(sess)
}

// WARNING: If you change this order you will need to fix createCodeComment

return comments, sess.
Asc("comment.created_unix").
Asc("comment.id").
Expand Down
2 changes: 2 additions & 0 deletions models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ var migrations = []Migration{
NewMigration("fix publisher ID for tag releases", fixPublisherIDforTagReleases),
// v157 -> v158
NewMigration("ensure repo topics are up-to-date", fixRepoTopics),
// v158 -> v159
NewMigration("code comment replies should have the commitID of the review they are replying to", updateCodeCommentReplies),
}

// GetCurrentDBVersion returns the current db version
Expand Down
110 changes: 110 additions & 0 deletions models/migrations/v158.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// Copyright 2020 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package migrations

import (
"fmt"
"strconv"

"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"

"xorm.io/xorm"
)

func updateCodeCommentReplies(x *xorm.Engine) error {
type Comment struct {
ID int64 `xorm:"pk autoincr"`
CommitSHA string `xorm:"VARCHAR(40)"`
Patch string `xorm:"TEXT patch"`
Invalidated bool

// Not extracted but used in the below query
Type int `xorm:"INDEX"`
Line int64 // - previous line / + proposed line
TreePath string
ReviewID int64 `xorm:"index"`
}

if err := x.Sync2(new(Comment)); err != nil {
return err
}

sqlSelect := `SELECT comment.id as id, first.commit_sha as commit_sha, first.patch as patch, first.invalidated as invalidated`
sqlTail := ` FROM comment INNER JOIN (
SELECT C.id, C.review_id, C.line, C.tree_path, C.patch, C.commit_sha, C.invalidated
FROM comment AS C
WHERE C.type = 21
AND C.created_unix =
(SELECT MIN(comment.created_unix)
FROM comment
WHERE comment.review_id = C.review_id
AND comment.type = 21
AND comment.line = C.line
AND comment.tree_path = C.tree_path)
) AS first
ON comment.review_id = first.review_id
AND comment.tree_path = first.tree_path AND comment.line = first.line
WHERE comment.type = 21
AND comment.id != first.id
AND comment.commit_sha != first.commit_sha`

var sqlCmd string
var start = 0
var batchSize = 100
sess := x.NewSession()
defer sess.Close()
for {
if err := sess.Begin(); err != nil {
return err
}

if setting.Database.UseMSSQL {
if _, err := sess.Exec(sqlSelect + " INTO #temp_comments" + sqlTail); err != nil {
log.Error("unable to create temporary table")
return err
}
}

var comments = make([]*Comment, 0, batchSize)

switch {
case setting.Database.UseMySQL:
sqlCmd = sqlSelect + sqlTail + " LIMIT " + strconv.Itoa(batchSize) + ", " + strconv.Itoa(start)
case setting.Database.UsePostgreSQL:
fallthrough
case setting.Database.UseSQLite3:
sqlCmd = sqlSelect + sqlTail + " LIMIT " + strconv.Itoa(batchSize) + " OFFSET " + strconv.Itoa(start)
case setting.Database.UseMSSQL:
sqlCmd = "SELECT TOP " + strconv.Itoa(batchSize) + " * FROM #temp_comments WHERE " +
"(id NOT IN ( SELECT TOP " + strconv.Itoa(start) + " id FROM #temp_comments ORDER BY id )) ORDER BY id"
default:
return fmt.Errorf("Unsupported database type")
}

if err := sess.SQL(sqlCmd).Find(&comments); err != nil {
log.Error("failed to select: %v", err)
return err
}

for _, comment := range comments {
if _, err := sess.Table("comment").ID(comment.ID).Cols("commit_sha", "patch", "invalidated").Update(comment); err != nil {
log.Error("failed to update comment[%d]: %v %v", comment.ID, comment, err)
return err
}
}

start += len(comments)

if err := sess.Commit(); err != nil {
return err
}
if len(comments) < batchSize {
break
}
}

return nil
}
96 changes: 67 additions & 29 deletions modules/references/references.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,40 +235,78 @@ func findAllIssueReferencesMarkdown(content string) []*rawReference {
return findAllIssueReferencesBytes(bcontent, links)
}

func convertFullHTMLReferencesToShortRefs(re *regexp.Regexp, contentBytes *[]byte) {
// We will iterate through the content, rewrite and simplify full references.
//
// We want to transform something like:
//
// this is a https://ourgitea.com/git/owner/repo/issues/123456789, foo
// https://ourgitea.com/git/owner/repo/pulls/123456789
//
// Into something like:
//
// this is a #123456789, foo
// !123456789

pos := 0
for {
// re looks for something like: (\s|^|\(|\[)https://ourgitea.com/git/(owner/repo)/(issues)/(123456789)(?:\s|$|\)|\]|[:;,.?!]\s|[:;,.?!]$)
match := re.FindSubmatchIndex((*contentBytes)[pos:])
if match == nil {
break
}
// match is a bunch of indices into the content from pos onwards so
// to simplify things let's just add pos to all of the indices in match
for i := range match {
match[i] += pos
}

// match[0]-match[1] is whole string
// match[2]-match[3] is preamble

// move the position to the end of the preamble
pos = match[3]

// match[4]-match[5] is owner/repo
// now copy the owner/repo to end of the preamble
endPos := pos + match[5] - match[4]
copy((*contentBytes)[pos:endPos], (*contentBytes)[match[4]:match[5]])

// move the current position to the end of the newly copied owner/repo
pos = endPos

// Now set the issue/pull marker:
//
// match[6]-match[7] == 'issues'
(*contentBytes)[pos] = '#'
if string((*contentBytes)[match[6]:match[7]]) == "pulls" {
(*contentBytes)[pos] = '!'
}
pos++

// Then add the issue/pull number
//
// match[8]-match[9] is the number
endPos = pos + match[9] - match[8]
copy((*contentBytes)[pos:endPos], (*contentBytes)[match[8]:match[9]])

// Now copy what's left at the end of the string to the new end position
copy((*contentBytes)[endPos:], (*contentBytes)[match[9]:])
// now we reset the length

// our new section has length endPos - match[3]
// our old section has length match[9] - match[3]
(*contentBytes) = (*contentBytes)[:len((*contentBytes))-match[9]+endPos]
pos = endPos
}
}

// FindAllIssueReferences returns a list of unvalidated references found in a string.
func FindAllIssueReferences(content string) []IssueReference {
// Need to convert fully qualified html references to local system to #/! short codes
contentBytes := []byte(content)
if re := getGiteaIssuePullPattern(); re != nil {
pos := 0
for {
match := re.FindSubmatchIndex(contentBytes[pos:])
if match == nil {
break
}
// match[0]-match[1] is whole string
// match[2]-match[3] is preamble
pos += match[3]
// match[4]-match[5] is owner/repo
endPos := pos + match[5] - match[4]
copy(contentBytes[pos:endPos], contentBytes[match[4]:match[5]])
pos = endPos
// match[6]-match[7] == 'issues'
contentBytes[pos] = '#'
if string(contentBytes[match[6]:match[7]]) == "pulls" {
contentBytes[pos] = '!'
}
pos++
// match[8]-match[9] is the number
endPos = pos + match[9] - match[8]
copy(contentBytes[pos:endPos], contentBytes[match[8]:match[9]])
copy(contentBytes[endPos:], contentBytes[match[9]:])
// now we reset the length
// our new section has length endPos - match[3]
// our old section has length match[9] - match[3]
contentBytes = contentBytes[:len(contentBytes)-match[9]+endPos]
pos = endPos
}
convertFullHTMLReferencesToShortRefs(re, &contentBytes)
} else {
log.Debug("No GiteaIssuePullPattern pattern")
}
Expand Down
Loading

0 comments on commit eea6584

Please sign in to comment.