Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
RedCocoon committed Nov 3, 2024
2 parents 3327b83 + f2a6df0 commit 2ba22a8
Show file tree
Hide file tree
Showing 136 changed files with 3,998 additions and 3,574 deletions.
6 changes: 4 additions & 2 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ plugins:
- "@stylistic/eslint-plugin-js"
- "@typescript-eslint/eslint-plugin"
- eslint-plugin-array-func
- eslint-plugin-deprecation
- eslint-plugin-github
- eslint-plugin-i
- eslint-plugin-no-jquery
Expand Down Expand Up @@ -248,6 +247,7 @@ rules:
"@typescript-eslint/no-base-to-string": [0]
"@typescript-eslint/no-confusing-non-null-assertion": [2]
"@typescript-eslint/no-confusing-void-expression": [0]
"@typescript-eslint/no-deprecated": [2]
"@typescript-eslint/no-dupe-class-members": [0]
"@typescript-eslint/no-duplicate-enum-values": [2]
"@typescript-eslint/no-duplicate-type-constituents": [2, {ignoreUnions: true}]
Expand Down Expand Up @@ -359,7 +359,6 @@ rules:
default-case-last: [2]
default-case: [0]
default-param-last: [0]
deprecation/deprecation: [2]
dot-notation: [0]
eqeqeq: [2]
for-direction: [2]
Expand Down Expand Up @@ -816,6 +815,7 @@ rules:
unicorn/catch-error-name: [0]
unicorn/consistent-destructuring: [2]
unicorn/consistent-empty-array-spread: [2]
unicorn/consistent-existence-index-check: [0]
unicorn/consistent-function-scoping: [2]
unicorn/custom-error-definition: [0]
unicorn/empty-brace-spaces: [2]
Expand Down Expand Up @@ -892,10 +892,12 @@ rules:
unicorn/prefer-dom-node-text-content: [2]
unicorn/prefer-event-target: [2]
unicorn/prefer-export-from: [0]
unicorn/prefer-global-this: [0]
unicorn/prefer-includes: [2]
unicorn/prefer-json-parse-buffer: [0]
unicorn/prefer-keyboard-event-key: [2]
unicorn/prefer-logical-operator-over-ternary: [2]
unicorn/prefer-math-min-max: [2]
unicorn/prefer-math-trunc: [2]
unicorn/prefer-modern-dom-apis: [0]
unicorn/prefer-modern-math-apis: [2]
Expand Down
27 changes: 11 additions & 16 deletions assets/go-licenses.json

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions build/generate-emoji.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ func (e Emoji) MarshalJSON() ([]byte, error) {
}

func main() {
var err error

flag.Parse()

// generate data
Expand Down Expand Up @@ -83,8 +81,6 @@ var replacer = strings.NewReplacer(
var emojiRE = regexp.MustCompile(`\{Emoji:"([^"]*)"`)

func generate() ([]byte, error) {
var err error

// load gemoji data
res, err := http.Get(gemojiURL)
if err != nil {
Expand Down
191 changes: 94 additions & 97 deletions go.mod

Large diffs are not rendered by default.

462 changes: 226 additions & 236 deletions go.sum

Large diffs are not rendered by default.

71 changes: 71 additions & 0 deletions models/fixtures/action_artifact.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
-
id: 1
run_id: 791
runner_id: 1
repo_id: 4
owner_id: 1
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
storage_path: "26/1/1712166500347189545.chunk"
file_size: 1024
file_compressed_size: 1024
content_encoding: ""
artifact_path: "abc.txt"
artifact_name: "artifact-download"
status: 1
created_unix: 1712338649
updated_unix: 1712338649
expired_unix: 1720114649

-
id: 19
run_id: 791
runner_id: 1
repo_id: 4
owner_id: 1
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
storage_path: "26/19/1712348022422036662.chunk"
file_size: 1024
file_compressed_size: 1024
content_encoding: ""
artifact_path: "abc.txt"
artifact_name: "multi-file-download"
status: 2
created_unix: 1712348022
updated_unix: 1712348022
expired_unix: 1720124022

-
id: 20
run_id: 791
runner_id: 1
repo_id: 4
owner_id: 1
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
storage_path: "26/20/1712348022423431524.chunk"
file_size: 1024
file_compressed_size: 1024
content_encoding: ""
artifact_path: "xyz/def.txt"
artifact_name: "multi-file-download"
status: 2
created_unix: 1712348022
updated_unix: 1712348022
expired_unix: 1720124022

-
id: 22
run_id: 792
runner_id: 1
repo_id: 4
owner_id: 1
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
storage_path: "27/5/1730330775594233150.chunk"
file_size: 1024
file_compressed_size: 1024
content_encoding: "application/zip"
artifact_path: "artifact-v4-download.zip"
artifact_name: "artifact-v4-download"
status: 2
created_unix: 1730330775
updated_unix: 1730330775
expired_unix: 1738106775
2 changes: 0 additions & 2 deletions models/git/lfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ var ErrLFSObjectNotExist = db.ErrNotExist{Resource: "LFS Meta object"}
// NewLFSMetaObject stores a given populated LFSMetaObject structure in the database
// if it is not already present.
func NewLFSMetaObject(ctx context.Context, repoID int64, p lfs.Pointer) (*LFSMetaObject, error) {
var err error

ctx, committer, err := db.TxContext(ctx)
if err != nil {
return nil, err
Expand Down
3 changes: 1 addition & 2 deletions models/issues/label_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,7 @@ func TestGetLabelsByOrgID(t *testing.T) {
testSuccess(3, "reversealphabetically", []int64{4, 3})
testSuccess(3, "default", []int64{3, 4})

var err error
_, err = issues_model.GetLabelsByOrgID(db.DefaultContext, 0, "leastissues", db.ListOptions{})
_, err := issues_model.GetLabelsByOrgID(db.DefaultContext, 0, "leastissues", db.ListOptions{})
assert.True(t, issues_model.IsErrOrgLabelNotExist(err))

_, err = issues_model.GetLabelsByOrgID(db.DefaultContext, -1, "leastissues", db.ListOptions{})
Expand Down
4 changes: 1 addition & 3 deletions modules/charset/charset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,12 @@ func TestMaybeRemoveBOM(t *testing.T) {

func TestToUTF8(t *testing.T) {
resetDefaultCharsetsOrder()
var res string
var err error

// Note: golang compiler seems so behave differently depending on the current
// locale, so some conversions might behave differently. For that reason, we don't
// depend on particular conversions but in expected behaviors.

res, err = ToUTF8([]byte{0x41, 0x42, 0x43}, ConvertOpts{})
res, err := ToUTF8([]byte{0x41, 0x42, 0x43}, ConvertOpts{})
assert.NoError(t, err)
assert.Equal(t, "ABC", res)

Expand Down
40 changes: 9 additions & 31 deletions modules/git/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,14 @@
package git

import (
"context"
"errors"
"fmt"
"strings"
"time"

"code.gitea.io/gitea/modules/util"
)

// ErrExecTimeout error when exec timed out
type ErrExecTimeout struct {
Duration time.Duration
}

// IsErrExecTimeout if some error is ErrExecTimeout
func IsErrExecTimeout(err error) bool {
_, ok := err.(ErrExecTimeout)
return ok
}

func (err ErrExecTimeout) Error() string {
return fmt.Sprintf("execution is timeout [duration: %v]", err.Duration)
}

// ErrNotExist commit not exist error
type ErrNotExist struct {
ID string
Expand Down Expand Up @@ -62,21 +48,6 @@ func IsErrBadLink(err error) bool {
return ok
}

// ErrUnsupportedVersion error when required git version not matched
type ErrUnsupportedVersion struct {
Required string
}

// IsErrUnsupportedVersion if some error is ErrUnsupportedVersion
func IsErrUnsupportedVersion(err error) bool {
_, ok := err.(ErrUnsupportedVersion)
return ok
}

func (err ErrUnsupportedVersion) Error() string {
return fmt.Sprintf("Operation requires higher version [required: %s]", err.Required)
}

// ErrBranchNotExist represents a "BranchNotExist" kind of error.
type ErrBranchNotExist struct {
Name string
Expand Down Expand Up @@ -185,3 +156,10 @@ func IsErrMoreThanOne(err error) bool {
func (err *ErrMoreThanOne) Error() string {
return fmt.Sprintf("ErrMoreThanOne Error: %v: %s\n%s", err.Err, err.StdErr, err.StdOut)
}

func IsErrCanceledOrKilled(err error) bool {
// When "cancel()" a git command's context, the returned error of "Run()" could be one of them:
// - context.Canceled
// - *exec.ExitError: "signal: killed"
return err != nil && (errors.Is(err, context.Canceled) || err.Error() == "signal: killed")
}
4 changes: 1 addition & 3 deletions modules/git/repo_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,7 @@ func (c *CheckAttributeReader) Run() error {
Stdout: c.stdOut,
Stderr: stdErr,
})
if err != nil && // If there is an error we need to return but:
c.ctx.Err() != err && // 1. Ignore the context error if the context is cancelled or exceeds the deadline (RunWithContext could return c.ctx.Err() which is Canceled or DeadlineExceeded)
err.Error() != "signal: killed" { // 2. We should not pass up errors due to the program being killed
if err != nil && !IsErrCanceledOrKilled(err) {
return fmt.Errorf("failed to run attr-check. Error: %w\nStderr: %s", err, stdErr.String())
}
return nil
Expand Down
8 changes: 2 additions & 6 deletions modules/indexer/internal/meilisearch/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

// Indexer represents a basic meilisearch indexer implementation
type Indexer struct {
Client *meilisearch.Client
Client meilisearch.ServiceManager

url, apiKey string
indexName string
Expand Down Expand Up @@ -40,11 +40,7 @@ func (i *Indexer) Init(_ context.Context) (bool, error) {
return false, fmt.Errorf("indexer is already initialized")
}

i.Client = meilisearch.NewClient(meilisearch.ClientConfig{
Host: i.url,
APIKey: i.apiKey,
})

i.Client = meilisearch.New(i.url, meilisearch.WithAPIKey(i.apiKey))
_, err := i.Client.GetIndex(i.VersionedIndexName())
if err == nil {
return true, nil
Expand Down
3 changes: 1 addition & 2 deletions modules/markup/markdown/goldmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,7 @@ func (r *HTMLRenderer) renderIcon(w util.BufWriter, source []byte, node ast.Node
return ast.WalkContinue, nil
}

var err error
_, err = w.WriteString(fmt.Sprintf(`<i class="icon %s"></i>`, name))
_, err := w.WriteString(fmt.Sprintf(`<i class="icon %s"></i>`, name))
if err != nil {
return ast.WalkStop, err
}
Expand Down
2 changes: 1 addition & 1 deletion modules/markup/markdown/transform_blockquote.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (g *ASTTransformer) extractBlockquoteAttentionEmphasis(firstParagraph ast.N
if !ok {
return "", nil
}
val1 := string(node1.Text(reader.Source()))
val1 := string(node1.Text(reader.Source())) //nolint:staticcheck
attentionType := strings.ToLower(val1)
if g.attentionTypes.Contains(attentionType) {
return attentionType, []ast.Node{node1}
Expand Down
2 changes: 1 addition & 1 deletion modules/markup/markdown/transform_codespan.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func cssColorHandler(value string) bool {
}

func (g *ASTTransformer) transformCodeSpan(_ *markup.RenderContext, v *ast.CodeSpan, reader text.Reader) {
colorContent := v.Text(reader.Source())
colorContent := v.Text(reader.Source()) //nolint:staticcheck
if cssColorHandler(string(colorContent)) {
v.AppendChild(v, NewColorPreview(colorContent))
}
Expand Down
2 changes: 1 addition & 1 deletion modules/markup/markdown/transform_heading.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (g *ASTTransformer) transformHeading(_ *markup.RenderContext, v *ast.Headin
v.SetAttribute(attr.Name, []byte(fmt.Sprintf("%v", attr.Value)))
}
}
txt := v.Text(reader.Source())
txt := v.Text(reader.Source()) //nolint:staticcheck
header := markup.Header{
Text: util.UnsafeBytesToString(txt),
Level: v.Level,
Expand Down
2 changes: 1 addition & 1 deletion modules/markup/mdstripper/mdstripper.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (r *stripRenderer) Render(w io.Writer, source []byte, doc ast.Node) error {
coalesce := prevSibIsText
r.processString(
w,
v.Text(source),
v.Text(source), //nolint:staticcheck
coalesce)
if v.SoftLineBreak() {
r.doubleSpace(w)
Expand Down
4 changes: 2 additions & 2 deletions modules/packages/content_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func (s *ContentStore) ShouldServeDirect() bool {
return setting.Packages.Storage.ServeDirect()
}

func (s *ContentStore) GetServeDirectURL(key BlobHash256Key, filename string) (*url.URL, error) {
return s.store.URL(KeyToRelativePath(key), filename)
func (s *ContentStore) GetServeDirectURL(key BlobHash256Key, filename string, reqParams url.Values) (*url.URL, error) {
return s.store.URL(KeyToRelativePath(key), filename, reqParams)
}

// FIXME: Workaround to be removed in v1.20
Expand Down
5 changes: 3 additions & 2 deletions modules/repository/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,10 @@ func pullMirrorReleaseSync(ctx context.Context, repo *repo_model.Repository, git

for _, tag := range updates {
if _, err := db.GetEngine(ctx).Where("repo_id = ? AND lower_tag_name = ?", repo.ID, strings.ToLower(tag.Name)).
Cols("sha1").
Cols("sha1", "created_unix").
Update(&repo_model.Release{
Sha1: tag.Object.String(),
Sha1: tag.Object.String(),
CreatedUnix: timeutil.TimeStamp(tag.Tagger.When.Unix()),
}); err != nil {
return fmt.Errorf("unable to update tag %s for pull-mirror Repo[%d:%s/%s]: %w", tag.Name, repo.ID, repo.OwnerName, repo.Name, err)
}
Expand Down
2 changes: 1 addition & 1 deletion modules/storage/azureblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func (a *AzureBlobStorage) Delete(path string) error {
}

// URL gets the redirect URL to a file. The presigned link is valid for 5 minutes.
func (a *AzureBlobStorage) URL(path, name string) (*url.URL, error) {
func (a *AzureBlobStorage) URL(path, name string, reqParams url.Values) (*url.URL, error) {
blobClient := a.getBlobClient(path)

startTime := time.Now()
Expand Down
2 changes: 1 addition & 1 deletion modules/storage/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (s discardStorage) Delete(_ string) error {
return fmt.Errorf("%s", s)
}

func (s discardStorage) URL(_, _ string) (*url.URL, error) {
func (s discardStorage) URL(_, _ string, _ url.Values) (*url.URL, error) {
return nil, fmt.Errorf("%s", s)
}

Expand Down
2 changes: 1 addition & 1 deletion modules/storage/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func Test_discardStorage(t *testing.T) {
assert.Error(t, err, string(tt))
}
{
got, err := tt.URL("path", "name")
got, err := tt.URL("path", "name", nil)
assert.Nil(t, got)
assert.Errorf(t, err, string(tt))
}
Expand Down
2 changes: 1 addition & 1 deletion modules/storage/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (l *LocalStorage) Delete(path string) error {
}

// URL gets the redirect URL to a file
func (l *LocalStorage) URL(path, name string) (*url.URL, error) {
func (l *LocalStorage) URL(path, name string, reqParams url.Values) (*url.URL, error) {
return nil, ErrURLNotSupported
}

Expand Down
8 changes: 6 additions & 2 deletions modules/storage/minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,12 @@ func (m *MinioStorage) Delete(path string) error {
}

// URL gets the redirect URL to a file. The presigned link is valid for 5 minutes.
func (m *MinioStorage) URL(path, name string) (*url.URL, error) {
reqParams := make(url.Values)
func (m *MinioStorage) URL(path, name string, serveDirectReqParams url.Values) (*url.URL, error) {
// copy serveDirectReqParams
reqParams, err := url.ParseQuery(serveDirectReqParams.Encode())
if err != nil {
return nil, err
}
// TODO it may be good to embed images with 'inline' like ServeData does, but we don't want to have to read the file, do we?
reqParams.Set("response-content-disposition", "attachment; filename=\""+quoteEscaper.Replace(name)+"\"")
u, err := m.client.PresignedGetObject(m.ctx, m.bucket, m.buildMinioPath(path), 5*time.Minute, reqParams)
Expand Down
Loading

0 comments on commit 2ba22a8

Please sign in to comment.