Skip to content

Commit bcfe349

Browse files
authored
Merge branch 'main' into fix-markdown-render
2 parents 3c76c8e + ee6929d commit bcfe349

File tree

30 files changed

+167
-158
lines changed

30 files changed

+167
-158
lines changed

modules/git/repo_commit_nogogit.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ func (repo *Repository) getCommit(id ObjectID) (*Commit, error) {
8181

8282
_, _ = wr.Write([]byte(id.String() + "\n"))
8383

84-
return repo.getCommitFromBatchReader(rd, id)
84+
return repo.getCommitFromBatchReader(wr, rd, id)
8585
}
8686

87-
func (repo *Repository) getCommitFromBatchReader(rd *bufio.Reader, id ObjectID) (*Commit, error) {
87+
func (repo *Repository) getCommitFromBatchReader(wr WriteCloserError, rd *bufio.Reader, id ObjectID) (*Commit, error) {
8888
_, typ, size, err := ReadBatchLine(rd)
8989
if err != nil {
9090
if errors.Is(err, io.EOF) || IsErrNotExist(err) {
@@ -112,7 +112,11 @@ func (repo *Repository) getCommitFromBatchReader(rd *bufio.Reader, id ObjectID)
112112
return nil, err
113113
}
114114

115-
commit, err := tag.Commit(repo)
115+
if _, err := wr.Write([]byte(tag.Object.String() + "\n")); err != nil {
116+
return nil, err
117+
}
118+
119+
commit, err := repo.getCommitFromBatchReader(wr, rd, tag.Object)
116120
if err != nil {
117121
return nil, err
118122
}

modules/git/repo_tag_nogogit.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@ func (repo *Repository) GetTagType(id ObjectID) (string, error) {
4141
return "", err
4242
}
4343
_, typ, _, err := ReadBatchLine(rd)
44-
if IsErrNotExist(err) {
45-
return "", ErrNotExist{ID: id.String()}
44+
if err != nil {
45+
if IsErrNotExist(err) {
46+
return "", ErrNotExist{ID: id.String()}
47+
}
48+
return "", err
4649
}
4750
return typ, nil
4851
}

modules/git/repo_tree_nogogit.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ func (repo *Repository) getTree(id ObjectID) (*Tree, error) {
3535
if err != nil {
3636
return nil, err
3737
}
38-
commit, err := tag.Commit(repo)
38+
39+
if _, err := wr.Write([]byte(tag.Object.String() + "\n")); err != nil {
40+
return nil, err
41+
}
42+
commit, err := repo.getCommitFromBatchReader(wr, rd, tag.Object)
3943
if err != nil {
4044
return nil, err
4145
}

modules/git/tag.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ type Tag struct {
2121
Signature *CommitSignature
2222
}
2323

24-
// Commit return the commit of the tag reference
25-
func (tag *Tag) Commit(gitRepo *Repository) (*Commit, error) {
26-
return gitRepo.getCommit(tag.Object)
27-
}
28-
2924
func parsePayloadSignature(data []byte, messageStart int) (payload, msg, sign string) {
3025
pos := messageStart
3126
signStart, signEnd := -1, -1

modules/repository/repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func PushUpdateAddTag(ctx context.Context, repo *repo_model.Repository, gitRepo
126126
if err != nil {
127127
return fmt.Errorf("unable to GetTag: %w", err)
128128
}
129-
commit, err := tag.Commit(gitRepo)
129+
commit, err := gitRepo.GetTagCommit(tag.Name)
130130
if err != nil {
131131
return fmt.Errorf("unable to get tag Commit: %w", err)
132132
}

routers/api/v1/repo/tag.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func GetAnnotatedTag(ctx *context.APIContext) {
110110
if tag, err := ctx.Repo.GitRepo.GetAnnotatedTag(sha); err != nil {
111111
ctx.APIError(http.StatusBadRequest, err)
112112
} else {
113-
commit, err := tag.Commit(ctx.Repo.GitRepo)
113+
commit, err := ctx.Repo.GitRepo.GetTagCommit(tag.Name)
114114
if err != nil {
115115
ctx.APIError(http.StatusBadRequest, err)
116116
}

routers/web/repo/view_file.go

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,32 +30,31 @@ import (
3030
"github.com/nektos/act/pkg/model"
3131
)
3232

33+
func prepareLatestCommitInfo(ctx *context.Context) bool {
34+
commit, err := ctx.Repo.Commit.GetCommitByPath(ctx.Repo.TreePath)
35+
if err != nil {
36+
ctx.ServerError("GetCommitByPath", err)
37+
return false
38+
}
39+
40+
return loadLatestCommitData(ctx, commit)
41+
}
42+
3343
func prepareToRenderFile(ctx *context.Context, entry *git.TreeEntry) {
3444
ctx.Data["IsViewFile"] = true
3545
ctx.Data["HideRepoInfo"] = true
36-
blob := entry.Blob()
37-
buf, dataRc, fInfo, err := getFileReader(ctx, ctx.Repo.Repository.ID, blob)
38-
if err != nil {
39-
ctx.ServerError("getFileReader", err)
46+
47+
if !prepareLatestCommitInfo(ctx) {
4048
return
4149
}
42-
defer dataRc.Close()
50+
51+
blob := entry.Blob()
4352

4453
ctx.Data["Title"] = ctx.Tr("repo.file.title", ctx.Repo.Repository.Name+"/"+path.Base(ctx.Repo.TreePath), ctx.Repo.RefFullName.ShortName())
4554
ctx.Data["FileIsSymlink"] = entry.IsLink()
4655
ctx.Data["FileName"] = blob.Name()
4756
ctx.Data["RawFileLink"] = ctx.Repo.RepoLink + "/raw/" + ctx.Repo.RefTypeNameSubURL() + "/" + util.PathEscapeSegments(ctx.Repo.TreePath)
4857

49-
commit, err := ctx.Repo.Commit.GetCommitByPath(ctx.Repo.TreePath)
50-
if err != nil {
51-
ctx.ServerError("GetCommitByPath", err)
52-
return
53-
}
54-
55-
if !loadLatestCommitData(ctx, commit) {
56-
return
57-
}
58-
5958
if ctx.Repo.TreePath == ".editorconfig" {
6059
_, editorconfigWarning, editorconfigErr := ctx.Repo.GetEditorconfig(ctx.Repo.Commit)
6160
if editorconfigWarning != nil {
@@ -90,6 +89,15 @@ func prepareToRenderFile(ctx *context.Context, entry *git.TreeEntry) {
9089
isDisplayingSource := ctx.FormString("display") == "source"
9190
isDisplayingRendered := !isDisplayingSource
9291

92+
// Don't call any other repository functions depends on git.Repository until the dataRc closed to
93+
// avoid create unnecessary temporary cat file.
94+
buf, dataRc, fInfo, err := getFileReader(ctx, ctx.Repo.Repository.ID, blob)
95+
if err != nil {
96+
ctx.ServerError("getFileReader", err)
97+
return
98+
}
99+
defer dataRc.Close()
100+
93101
if fInfo.isLFSFile {
94102
ctx.Data["RawFileLink"] = ctx.Repo.RepoLink + "/media/" + ctx.Repo.RefTypeNameSubURL() + "/" + util.PathEscapeSegments(ctx.Repo.TreePath)
95103
}

services/repository/push.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ func pushUpdateAddTags(ctx context.Context, repo *repo_model.Repository, gitRepo
385385
if err != nil {
386386
return fmt.Errorf("GetTag: %w", err)
387387
}
388-
commit, err := tag.Commit(gitRepo)
388+
commit, err := gitRepo.GetTagCommit(tag.Name)
389389
if err != nil {
390390
return fmt.Errorf("Commit: %w", err)
391391
}

services/webhook/discord.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ var (
101101
redColor = color("ff3232")
102102
)
103103

104+
// https://discord.com/developers/docs/resources/message#embed-object-embed-limits
105+
// Discord has some limits in place for the embeds.
106+
// According to some tests, there is no consistent limit for different character sets.
107+
// For example: 4096 ASCII letters are allowed, but only 2490 emoji characters are allowed.
108+
// To keep it simple, we currently truncate at 2000.
109+
const discordDescriptionCharactersLimit = 2000
110+
104111
type discordConvertor struct {
105112
Username string
106113
AvatarURL string
@@ -313,7 +320,7 @@ func (d discordConvertor) createPayload(s *api.User, title, text, url string, co
313320
Embeds: []DiscordEmbed{
314321
{
315322
Title: title,
316-
Description: text,
323+
Description: util.TruncateRunes(text, discordDescriptionCharactersLimit),
317324
URL: url,
318325
Color: color,
319326
Author: DiscordEmbedAuthor{

templates/devtest/fomantic-dropdown.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@
7575
<h2>Selection</h2>
7676
<div>
7777
{{/* the "selection" class is optional, it will be added by JS automatically */}}
78-
<select class="ui dropdown selection ellipsis-items-nowrap">
78+
<select class="ui dropdown selection ellipsis-text-items">
7979
<option>a</option>
8080
<option>abcdefuvwxyz</option>
8181
<option>loooooooooooooooooooooooooooooooooooooooooooooooooooooooooong</option>
8282
</select>
83-
<select class="ui dropdown ellipsis-items-nowrap tw-max-w-[8em]">
83+
<select class="ui dropdown ellipsis-text-items tw-max-w-[8em]">
8484
<option>loooooooooooooooooooooooooooooooooooooooooooooooooooooooooong</option>
8585
<option>abcdefuvwxyz</option>
8686
<option>a</option>

0 commit comments

Comments
 (0)