Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
* upstream/main:
  Fix typo (go-gitea#21201)
  Remove unnecessary length check for repo's Description & Website (go-gitea#21194)
  Treat git object mode 40755 as directory (go-gitea#21195)
  Fix reaction of issues (go-gitea#21185)
  Fix CSV diff for added/deleted files (go-gitea#21189)
  Show label description in comments section (go-gitea#21156)
  Limit length of repo description and repo url input fields (go-gitea#21119)
  • Loading branch information
zjjhot committed Sep 19, 2022
2 parents f729e8e + c87e6a8 commit 15d11c1
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 51 deletions.
2 changes: 1 addition & 1 deletion cmd/serv.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const (
var CmdServ = cli.Command{
Name: "serv",
Usage: "This command should only be called by SSH shell",
Description: `Serv provide access auth for repositories`,
Description: "Serv provides access auth for repositories",
Action: runServ,
Flags: []cli.Flag{
cli.BoolFlag{
Expand Down
19 changes: 15 additions & 4 deletions models/issues/reaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ func createReaction(ctx context.Context, opts *ReactionOptions) (*Reaction, erro
Reaction: opts.Type,
UserID: opts.DoerID,
}
if findOpts.CommentID == 0 {
// explicit search of Issue Reactions where CommentID = 0
findOpts.CommentID = -1
}

existingR, _, err := FindReactions(ctx, findOpts)
if err != nil {
Expand Down Expand Up @@ -256,16 +260,23 @@ func DeleteReaction(ctx context.Context, opts *ReactionOptions) error {
CommentID: opts.CommentID,
}

_, err := db.GetEngine(ctx).Where("original_author_id = 0").Delete(reaction)
sess := db.GetEngine(ctx).Where("original_author_id = 0")
if opts.CommentID == -1 {
reaction.CommentID = 0
sess.MustCols("comment_id")
}

_, err := sess.Delete(reaction)
return err
}

// DeleteIssueReaction deletes a reaction on issue.
func DeleteIssueReaction(doerID, issueID int64, content string) error {
return DeleteReaction(db.DefaultContext, &ReactionOptions{
Type: content,
DoerID: doerID,
IssueID: issueID,
Type: content,
DoerID: doerID,
IssueID: issueID,
CommentID: -1,
})
}

Expand Down
4 changes: 2 additions & 2 deletions modules/git/parse_nogogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func parseTreeEntries(data []byte, ptree *Tree) ([]*TreeEntry, error) {
case "160000":
entry.entryMode = EntryModeCommit
pos += 14 // skip over "160000 object "
case "040000":
case "040000", "040755": // git uses 040000 for tree object, but some users may get 040755 for unknown reasons
entry.entryMode = EntryModeTree
pos += 12 // skip over "040000 tree "
default:
Expand Down Expand Up @@ -119,7 +119,7 @@ loop:
entry.entryMode = EntryModeSymlink
case "160000":
entry.entryMode = EntryModeCommit
case "40000":
case "40000", "40755": // git uses 40000 for tree object, but some users may get 40755 for unknown reasons
entry.entryMode = EntryModeTree
default:
log.Debug("Unknown mode: %v", string(mode))
Expand Down
8 changes: 0 additions & 8 deletions modules/repository/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"os"
"path"
"strings"
"unicode/utf8"

"code.gitea.io/gitea/models"
activities_model "code.gitea.io/gitea/models/activities"
Expand Down Expand Up @@ -337,13 +336,6 @@ func CheckDaemonExportOK(ctx context.Context, repo *repo_model.Repository) error
func UpdateRepository(ctx context.Context, repo *repo_model.Repository, visibilityChanged bool) (err error) {
repo.LowerName = strings.ToLower(repo.Name)

if utf8.RuneCountInString(repo.Description) > 255 {
repo.Description = string([]rune(repo.Description)[:255])
}
if utf8.RuneCountInString(repo.Website) > 255 {
repo.Website = string([]rune(repo.Website)[:255])
}

e := db.GetEngine(ctx)

if _, err = e.ID(repo.ID).AllCols().Update(repo); err != nil {
Expand Down
10 changes: 5 additions & 5 deletions modules/structs/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ type CreateRepoOption struct {
// unique: true
Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(100)"`
// Description of the repository to create
Description string `json:"description" binding:"MaxSize(255)"`
Description string `json:"description" binding:"MaxSize(2048)"`
// Whether the repository is private
Private bool `json:"private"`
// Label-Set to use
Expand Down Expand Up @@ -140,9 +140,9 @@ type EditRepoOption struct {
// unique: true
Name *string `json:"name,omitempty" binding:"OmitEmpty;AlphaDashDot;MaxSize(100);"`
// a short description of the repository.
Description *string `json:"description,omitempty" binding:"MaxSize(255)"`
Description *string `json:"description,omitempty" binding:"MaxSize(2048)"`
// a URL with more information about the repository.
Website *string `json:"website,omitempty" binding:"MaxSize(255)"`
Website *string `json:"website,omitempty" binding:"MaxSize(1024)"`
// either `true` to make the repository private or `false` to make it public.
// Note: you will get a 422 error if the organization restricts changing repository visibility to organization
// owners and a non-owner tries to change the value of private.
Expand Down Expand Up @@ -208,7 +208,7 @@ type GenerateRepoOption struct {
// Default branch of the new repository
DefaultBranch string `json:"default_branch"`
// Description of the repository to create
Description string `json:"description" binding:"MaxSize(255)"`
Description string `json:"description" binding:"MaxSize(2048)"`
// Whether the repository is private
Private bool `json:"private"`
// include git content of default branch in template repo
Expand Down Expand Up @@ -316,7 +316,7 @@ type MigrateRepoOptions struct {
LFS bool `json:"lfs"`
LFSEndpoint string `json:"lfs_endpoint"`
Private bool `json:"private"`
Description string `json:"description" binding:"MaxSize(255)"`
Description string `json:"description" binding:"MaxSize(2048)"`
Wiki bool `json:"wiki"`
Milestones bool `json:"milestones"`
Labels bool `json:"labels"`
Expand Down
10 changes: 5 additions & 5 deletions modules/templates/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,17 +377,17 @@ func NewFuncMap() []template.FuncMap {
return ""
},
"RenderLabels": func(labels []*issues_model.Label, repoLink string) template.HTML {
html := `<span class="labels-list">`
htmlCode := `<span class="labels-list">`
for _, label := range labels {
// Protect against nil value in labels - shouldn't happen but would cause a panic if so
if label == nil {
continue
}
html += fmt.Sprintf("<a href='%s/issues?labels=%d' class='ui label' style='color: %s !important; background-color: %s !important'>%s</a> ",
repoLink, label.ID, label.ForegroundColor(), label.Color, RenderEmoji(label.Name))
htmlCode += fmt.Sprintf("<a href='%s/issues?labels=%d' class='ui label' style='color: %s !important; background-color: %s !important' title='%s'>%s</a> ",
repoLink, label.ID, label.ForegroundColor(), label.Color, html.EscapeString(label.Description), RenderEmoji(label.Name))
}
html += "</span>"
return template.HTML(html)
htmlCode += "</span>"
return template.HTML(htmlCode)
},
"MermaidMaxSourceCharacters": func() int {
return setting.MermaidMaxSourceCharacters
Expand Down
36 changes: 18 additions & 18 deletions routers/web/repo/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,17 @@ func setCsvCompareContext(ctx *context.Context) {
Error string
}

ctx.Data["CreateCsvDiff"] = func(diffFile *gitdiff.DiffFile, baseCommit, headCommit *git.Commit) CsvDiffResult {
if diffFile == nil || baseCommit == nil || headCommit == nil {
ctx.Data["CreateCsvDiff"] = func(diffFile *gitdiff.DiffFile, baseBlob, headBlob *git.Blob) CsvDiffResult {
if diffFile == nil {
return CsvDiffResult{nil, ""}
}

errTooLarge := errors.New(ctx.Locale.Tr("repo.error.csv.too_large"))

csvReaderFromCommit := func(ctx *markup.RenderContext, c *git.Commit) (*csv.Reader, io.Closer, error) {
blob, err := c.GetBlobByPath(diffFile.Name)
if err != nil {
return nil, nil, err
csvReaderFromCommit := func(ctx *markup.RenderContext, blob *git.Blob) (*csv.Reader, io.Closer, error) {
if blob == nil {
// It's ok for blob to be nil (file added or deleted)
return nil, nil, nil
}

if setting.UI.CSV.MaxFileSize != 0 && setting.UI.CSV.MaxFileSize < blob.Size() {
Expand All @@ -138,28 +138,28 @@ func setCsvCompareContext(ctx *context.Context) {
return csvReader, reader, err
}

baseReader, baseBlobCloser, err := csvReaderFromCommit(&markup.RenderContext{Ctx: ctx, RelativePath: diffFile.OldName}, baseCommit)
baseReader, baseBlobCloser, err := csvReaderFromCommit(&markup.RenderContext{Ctx: ctx, RelativePath: diffFile.OldName}, baseBlob)
if baseBlobCloser != nil {
defer baseBlobCloser.Close()
}
if err == errTooLarge {
return CsvDiffResult{nil, err.Error()}
}
if err != nil {
log.Error("CreateCsvDiff error whilst creating baseReader from file %s in commit %s in %s: %v", diffFile.Name, baseCommit.ID.String(), ctx.Repo.Repository.Name, err)
return CsvDiffResult{nil, "unable to load file from base commit"}
if err == errTooLarge {
return CsvDiffResult{nil, err.Error()}
}
log.Error("error whilst creating csv.Reader from file %s in base commit %s in %s: %v", diffFile.Name, baseBlob.ID.String(), ctx.Repo.Repository.Name, err)
return CsvDiffResult{nil, "unable to load file"}
}

headReader, headBlobCloser, err := csvReaderFromCommit(&markup.RenderContext{Ctx: ctx, RelativePath: diffFile.Name}, headCommit)
headReader, headBlobCloser, err := csvReaderFromCommit(&markup.RenderContext{Ctx: ctx, RelativePath: diffFile.Name}, headBlob)
if headBlobCloser != nil {
defer headBlobCloser.Close()
}
if err == errTooLarge {
return CsvDiffResult{nil, err.Error()}
}
if err != nil {
log.Error("CreateCsvDiff error whilst creating headReader from file %s in commit %s in %s: %v", diffFile.Name, headCommit.ID.String(), ctx.Repo.Repository.Name, err)
return CsvDiffResult{nil, "unable to load file from head commit"}
if err == errTooLarge {
return CsvDiffResult{nil, err.Error()}
}
log.Error("error whilst creating csv.Reader from file %s in head commit %s in %s: %v", diffFile.Name, headBlob.ID.String(), ctx.Repo.Repository.Name, err)
return CsvDiffResult{nil, "unable to load file"}
}

sections, err := gitdiff.CreateCsvDiff(diffFile, baseReader, headReader)
Expand Down
8 changes: 4 additions & 4 deletions services/forms/repo_form.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type CreateRepoForm struct {
UID int64 `binding:"Required"`
RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"`
Private bool
Description string `binding:"MaxSize(255)"`
Description string `binding:"MaxSize(2048)"`
DefaultBranch string `binding:"GitRefName;MaxSize(100)"`
AutoInit bool
Gitignores string
Expand Down Expand Up @@ -76,7 +76,7 @@ type MigrateRepoForm struct {
LFS bool `json:"lfs"`
LFSEndpoint string `json:"lfs_endpoint"`
Private bool `json:"private"`
Description string `json:"description" binding:"MaxSize(255)"`
Description string `json:"description" binding:"MaxSize(2048)"`
Wiki bool `json:"wiki"`
Milestones bool `json:"milestones"`
Labels bool `json:"labels"`
Expand Down Expand Up @@ -116,8 +116,8 @@ func ParseRemoteAddr(remoteAddr, authUsername, authPassword string) (string, err
// RepoSettingForm form for changing repository settings
type RepoSettingForm struct {
RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"`
Description string `binding:"MaxSize(255)"`
Website string `binding:"ValidUrl;MaxSize(255)"`
Description string `binding:"MaxSize(2048)"`
Website string `binding:"ValidUrl;MaxSize(1024)"`
Interval string
MirrorAddress string
MirrorUsername string
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/diff/box.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
{{if $isImage}}
{{template "repo/diff/image_diff" dict "file" . "root" $ "blobBase" $blobBase "blobHead" $blobHead}}
{{else}}
{{template "repo/diff/csv_diff" dict "file" . "root" $}}
{{template "repo/diff/csv_diff" dict "file" . "root" $ "blobBase" $blobBase "blobHead" $blobHead}}
{{end}}
</table>
</div>
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/diff/csv_diff.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<tr>
<td>
{{$result := call .root.CreateCsvDiff .file .root.BaseCommit .root.HeadCommit}}
{{$result := call .root.CreateCsvDiff .file .blobBase .blobHead}}
{{if $result.Error}}
<div class="ui center">{{$result.Error}}</div>
{{else if $result.Sections}}
Expand Down
4 changes: 2 additions & 2 deletions templates/repo/settings/options.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
{{end}}
<div class="field {{if .Err_Description}}error{{end}}">
<label for="description">{{$.locale.Tr "repo.repo_desc"}}</label>
<textarea id="description" name="description" rows="2">{{.Repository.Description}}</textarea>
<textarea id="description" name="description" rows="2" maxlength="2048">{{.Repository.Description}}</textarea>
</div>
<div class="field {{if .Err_Website}}error{{end}}">
<label for="website">{{.locale.Tr "repo.settings.site"}}</label>
<input id="website" name="website" type="url" value="{{.Repository.Website}}">
<input id="website" name="website" type="url" maxlength="1024" value="{{.Repository.Website}}">
</div>

<div class="field">
Expand Down

0 comments on commit 15d11c1

Please sign in to comment.