Skip to content

Commit 530f74f

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: (28 commits) Improve TrHTML and add more tests (go-gitea#29228) Convert visibility to number (go-gitea#29226) Implement some action notifier functions (go-gitea#29173) Artifact deletion in actions ui (go-gitea#27172) Update docs for actions variables (go-gitea#29239) Refactor more code in templates (go-gitea#29236) Use "Safe" modifier for manually constructed safe HTML strings in templates (go-gitea#29227) Remove jQuery from the repo release form (go-gitea#29225) Make submit event code work with both jQuery event and native event (go-gitea#29223) Remove jQuery from repo migrate page (go-gitea#29219) Remove unneccesary `initUserAuthLinkAccountView` from "link account" page (go-gitea#29217) Fix labels referencing the wrong ID in the user profile settings (go-gitea#29199) Fix label `for` pointing to a `name` instead of `id` in webhook settings (go-gitea#29209) Load outdated comments when (un)resolving conversation on PR timeline (go-gitea#29203) Fix missing template for follow button in organization (go-gitea#29215) Enable markdownlint `no-trailing-punctuation` and `no-blanks-blockquote` (go-gitea#29214) Remove jQuery from the webhook editor (go-gitea#29211) Remove jQuery from issue reference context popup attach (go-gitea#29216) fix typo (go-gitea#29212) Fix debian InRelease Acquire-By-Hash newline (go-gitea#29204) ...
2 parents 95d81c6 + 4345cac commit 530f74f

File tree

86 files changed

+1646
-317
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+1646
-317
lines changed

.eslintrc.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ plugins:
1212
- "@eslint-community/eslint-plugin-eslint-comments"
1313
- "@stylistic/eslint-plugin-js"
1414
- eslint-plugin-array-func
15+
- eslint-plugin-github
1516
- eslint-plugin-i
1617
- eslint-plugin-jquery
1718
- eslint-plugin-no-jquery
@@ -209,6 +210,29 @@ rules:
209210
func-names: [0]
210211
func-style: [0]
211212
getter-return: [2]
213+
github/a11y-aria-label-is-well-formatted: [0]
214+
github/a11y-no-title-attribute: [0]
215+
github/a11y-no-visually-hidden-interactive-element: [0]
216+
github/a11y-role-supports-aria-props: [0]
217+
github/a11y-svg-has-accessible-name: [0]
218+
github/array-foreach: [0]
219+
github/async-currenttarget: [2]
220+
github/async-preventdefault: [2]
221+
github/authenticity-token: [0]
222+
github/get-attribute: [0]
223+
github/js-class-name: [0]
224+
github/no-blur: [0]
225+
github/no-d-none: [0]
226+
github/no-dataset: [2]
227+
github/no-dynamic-script-tag: [2]
228+
github/no-implicit-buggy-globals: [2]
229+
github/no-inner-html: [0]
230+
github/no-innerText: [2]
231+
github/no-then: [2]
232+
github/no-useless-passive: [2]
233+
github/prefer-observers: [2]
234+
github/require-passive-events: [2]
235+
github/unescaped-html-literal: [0]
212236
grouped-accessor-pairs: [2]
213237
guard-for-in: [0]
214238
id-blacklist: [0]

.markdownlint.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ heading-increment: false
55
line-length: {code_blocks: false, tables: false, stern: true, line_length: -1}
66
no-alt-text: false
77
no-bare-urls: false
8-
no-blanks-blockquote: false
98
no-emphasis-as-heading: false
109
no-empty-links: false
1110
no-hard-tabs: {code_blocks: false}
1211
no-inline-html: false
1312
no-space-in-code: false
1413
no-space-in-emphasis: false
15-
no-trailing-punctuation: false
1614
no-trailing-spaces: {br_spaces: 0}
1715
single-h1: false

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ ifdef DEPS_PLAYWRIGHT
164164
endif
165165

166166
SWAGGER_SPEC := templates/swagger/v1_json.tmpl
167-
SWAGGER_SPEC_S_TMPL := s|"basePath": *"/api/v1"|"basePath": "{{AppSubUrl \| JSEscape \| Safe}}/api/v1"|g
168-
SWAGGER_SPEC_S_JSON := s|"basePath": *"{{AppSubUrl \| JSEscape \| Safe}}/api/v1"|"basePath": "/api/v1"|g
167+
SWAGGER_SPEC_S_TMPL := s|"basePath": *"/api/v1"|"basePath": "{{AppSubUrl \| JSEscape}}/api/v1"|g
168+
SWAGGER_SPEC_S_JSON := s|"basePath": *"{{AppSubUrl \| JSEscape}}/api/v1"|"basePath": "/api/v1"|g
169169
SWAGGER_EXCLUDE := code.gitea.io/sdk
170170
SWAGGER_NEWLINE_COMMAND := -e '$$a\'
171171

build/generate-images.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,8 @@ async function main() {
7979
]);
8080
}
8181

82-
main().then(exit).catch(exit);
82+
try {
83+
exit(await main());
84+
} catch (err) {
85+
exit(err);
86+
}

build/generate-svg.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,8 @@ async function main() {
6363
]);
6464
}
6565

66-
main().then(exit).catch(exit);
66+
try {
67+
exit(await main());
68+
} catch (err) {
69+
exit(err);
70+
}

cmd/generate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func runGenerateInternalToken(c *cli.Context) error {
7070
}
7171

7272
func runGenerateLfsJwtSecret(c *cli.Context) error {
73-
_, jwtSecretBase64, err := generate.NewJwtSecretBase64()
73+
_, jwtSecretBase64, err := generate.NewJwtSecretWithBase64()
7474
if err != nil {
7575
return err
7676
}

docs/content/administration/customizing-gitea.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ syntax and shouldn't be touched without fully understanding these components.
284284

285285
Google Analytics, Matomo (previously Piwik), and other analytics services can be added to Gitea. To add the tracking code, refer to the `Other additions to the page` section of this document, and add the JavaScript to the `$GITEA_CUSTOM/templates/custom/header.tmpl` file.
286286

287-
## Customizing gitignores, labels, licenses, locales, and readmes.
287+
## Customizing gitignores, labels, licenses, locales, and readmes
288288

289289
Place custom files in corresponding sub-folder under `custom/options`.
290290

docs/content/administration/https-support.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ CERT_FILE = cert.pem
3535
KEY_FILE = key.pem
3636
```
3737

38-
Note that if your certificate is signed by a third party certificate authority (i.e. not self-signed), then cert.pem should contain the certificate chain. The server certificate must be the first entry in cert.pem, followed by the intermediaries in order (if any). The root certificate does not have to be included because the connecting client must already have it in order to estalbish the trust relationship.
38+
Note that if your certificate is signed by a third party certificate authority (i.e. not self-signed), then cert.pem should contain the certificate chain. The server certificate must be the first entry in cert.pem, followed by the intermediaries in order (if any). The root certificate does not have to be included because the connecting client must already have it in order to establish the trust relationship.
3939
To learn more about the config values, please checkout the [Config Cheat Sheet](administration/config-cheat-sheet.md#server-server).
4040

4141
For the `CERT_FILE` or `KEY_FILE` field, the file path is relative to the `GITEA_CUSTOM` environment variable when it is a relative path. It can be an absolute path as well.

docs/content/administration/mail-templates.en-us.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ Please check [Gitea's logs](administration/logging-config.md) for error messages
222222
<a href="{{.Link}}">{{.Repo}}#{{.Issue.Index}}</a>.
223223
</p>
224224
{{if not (eq .Body "")}}
225-
<h3>Message content:</h3>
225+
<h3>Message content</h3>
226226
<hr>
227227
{{.Body | Str2html}}
228228
{{end}}
@@ -245,7 +245,7 @@ This template produces something along these lines:
245245

246246
> [@rhonda](#) (Rhonda Myers) updated [mike/stuff#38](#).
247247
>
248-
> #### Message content:
248+
> #### Message content
249249
>
250250
> \_********************************\_********************************
251251
>

docs/content/administration/mail-templates.zh-cn.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ _主题_ 和 _邮件正文_ 由 [Golang的模板引擎](https://go.dev/pkg/text/
228228

229229
> [@rhonda](#)(Rhonda Myers)更新了 [mike/stuff#38](#)
230230
>
231-
> #### 消息内容
231+
> #### 消息内容
232232
>
233233
> \_********************************\_********************************
234234
>

docs/content/contributing/guidelines-frontend.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ The source files can be found in the following directories:
3434

3535
We recommend [Google HTML/CSS Style Guide](https://google.github.io/styleguide/htmlcssguide.html) and [Google JavaScript Style Guide](https://google.github.io/styleguide/jsguide.html)
3636

37-
### Gitea specific guidelines:
37+
### Gitea specific guidelines
3838

3939
1. Every feature (Fomantic-UI/jQuery module) should be put in separate files/directories.
4040
2. HTML ids and classes should use kebab-case, it's preferred to contain 2-3 feature related keywords.

docs/content/contributing/guidelines-frontend.zh-cn.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ HTML 页面由[Go HTML Template](https://pkg.go.dev/html/template)渲染。
3434

3535
我们推荐使用[Google HTML/CSS Style Guide](https://google.github.io/styleguide/htmlcssguide.html)[Google JavaScript Style Guide](https://google.github.io/styleguide/jsguide.html)
3636

37-
## Gitea 特定准则
37+
## Gitea 特定准则
3838

3939
1. 每个功能(Fomantic-UI/jQuery 模块)应放在单独的文件/目录中。
4040
2. HTML 的 id 和 class 应使用 kebab-case,最好包含2-3个与功能相关的关键词。

docs/content/development/api-usage.zh-cn.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ curl "http://localhost:4000/api/v1/repos/test1/test1/issues" \
6060
`/users/:name/tokens` 是一个特殊的接口,需要您使用 basic authentication 进行认证,具体原因在 issue 中
6161
[#3842](https://github.com/go-gitea/gitea/issues/3842#issuecomment-397743346) 有所提及,使用方法如下所示:
6262

63-
### 使用 Basic authentication 认证
63+
### 使用 Basic authentication 认证
6464

6565
```
6666
$ curl --url https://yourusername:[email protected]/api/v1/users/yourusername/tokens

docs/content/usage/actions/comparison.zh-cn.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,6 @@ Gitea Actions目前不支持此功能,如果使用它,结果将始终为空
9595

9696
## 缺失的功能
9797

98-
### 变量
99-
100-
请参阅[变量](https://docs.github.com/zh/actions/learn-github-actions/variables)
101-
102-
目前变量功能正在开发中。
103-
10498
### 问题匹配器
10599

106100
问题匹配器是一种扫描Actions输出以查找指定正则表达式模式并在用户界面中突出显示该信息的方法。

models/actions/artifact.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ const (
2626
ArtifactStatusUploadConfirmed // 2, ArtifactStatusUploadConfirmed is the status of an artifact upload that is confirmed
2727
ArtifactStatusUploadError // 3, ArtifactStatusUploadError is the status of an artifact upload that is errored
2828
ArtifactStatusExpired // 4, ArtifactStatusExpired is the status of an artifact that is expired
29+
ArtifactStatusPendingDeletion // 5, ArtifactStatusPendingDeletion is the status of an artifact that is pending deletion
30+
ArtifactStatusDeleted // 6, ArtifactStatusDeleted is the status of an artifact that is deleted
2931
)
3032

3133
func init() {
@@ -147,8 +149,28 @@ func ListNeedExpiredArtifacts(ctx context.Context) ([]*ActionArtifact, error) {
147149
Where("expired_unix < ? AND status = ?", timeutil.TimeStamp(time.Now().Unix()), ArtifactStatusUploadConfirmed).Find(&arts)
148150
}
149151

152+
// ListPendingDeleteArtifacts returns all artifacts in pending-delete status.
153+
// limit is the max number of artifacts to return.
154+
func ListPendingDeleteArtifacts(ctx context.Context, limit int) ([]*ActionArtifact, error) {
155+
arts := make([]*ActionArtifact, 0, limit)
156+
return arts, db.GetEngine(ctx).
157+
Where("status = ?", ArtifactStatusPendingDeletion).Limit(limit).Find(&arts)
158+
}
159+
150160
// SetArtifactExpired sets an artifact to expired
151161
func SetArtifactExpired(ctx context.Context, artifactID int64) error {
152162
_, err := db.GetEngine(ctx).Where("id=? AND status = ?", artifactID, ArtifactStatusUploadConfirmed).Cols("status").Update(&ActionArtifact{Status: int64(ArtifactStatusExpired)})
153163
return err
154164
}
165+
166+
// SetArtifactNeedDelete sets an artifact to need-delete, cron job will delete it
167+
func SetArtifactNeedDelete(ctx context.Context, runID int64, name string) error {
168+
_, err := db.GetEngine(ctx).Where("run_id=? AND artifact_name=? AND status = ?", runID, name, ArtifactStatusUploadConfirmed).Cols("status").Update(&ActionArtifact{Status: int64(ArtifactStatusPendingDeletion)})
169+
return err
170+
}
171+
172+
// SetArtifactDeleted sets an artifact to deleted
173+
func SetArtifactDeleted(ctx context.Context, artifactID int64) error {
174+
_, err := db.GetEngine(ctx).ID(artifactID).Cols("status").Update(&ActionArtifact{Status: int64(ArtifactStatusDeleted)})
175+
return err
176+
}

modules/actions/github.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ func canGithubEventMatch(eventName string, triggedEvent webhook_module.HookEvent
5252
case webhook_module.HookEventPullRequest,
5353
webhook_module.HookEventPullRequestSync,
5454
webhook_module.HookEventPullRequestAssign,
55-
webhook_module.HookEventPullRequestLabel:
55+
webhook_module.HookEventPullRequestLabel,
56+
webhook_module.HookEventPullRequestReviewRequest,
57+
webhook_module.HookEventPullRequestMilestone:
5658
return true
5759

5860
default:

modules/actions/workflows.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,9 @@ func detectMatched(gitRepo *git.Repository, commit *git.Commit, triggedEvent web
221221
webhook_module.HookEventPullRequest,
222222
webhook_module.HookEventPullRequestSync,
223223
webhook_module.HookEventPullRequestAssign,
224-
webhook_module.HookEventPullRequestLabel:
224+
webhook_module.HookEventPullRequestLabel,
225+
webhook_module.HookEventPullRequestReviewRequest,
226+
webhook_module.HookEventPullRequestMilestone:
225227
return matchPullRequestEvent(gitRepo, commit, payload.(*api.PullRequestPayload), evt)
226228

227229
case // pull_request_review
@@ -397,13 +399,13 @@ func matchPullRequestEvent(gitRepo *git.Repository, commit *git.Commit, prPayloa
397399
} else {
398400
// See https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request
399401
// Actions with the same name:
400-
// opened, edited, closed, reopened, assigned, unassigned
402+
// opened, edited, closed, reopened, assigned, unassigned, review_requested, review_request_removed, milestoned, demilestoned
401403
// Actions need to be converted:
402404
// synchronized -> synchronize
403405
// label_updated -> labeled
404406
// label_cleared -> unlabeled
405407
// Unsupported activity types:
406-
// converted_to_draft, ready_for_review, locked, unlocked, review_requested, review_request_removed, auto_merge_enabled, auto_merge_disabled
408+
// converted_to_draft, ready_for_review, locked, unlocked, auto_merge_enabled, auto_merge_disabled, enqueued, dequeued
407409

408410
action := prPayload.Action
409411
switch action {

modules/context/context_response.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,20 @@ func (ctx *Context) HTML(status int, name base.TplName) {
9090
}
9191
}
9292

93+
// JSONTemplate renders the template as JSON response
94+
// keep in mind that the template is processed in HTML context, so JSON-things should be handled carefully, eg: by JSEscape
95+
func (ctx *Context) JSONTemplate(tmpl base.TplName) {
96+
t, err := ctx.Render.TemplateLookup(string(tmpl), nil)
97+
if err != nil {
98+
ctx.ServerError("unable to find template", err)
99+
return
100+
}
101+
ctx.Resp.Header().Set("Content-Type", "application/json")
102+
if err = t.Execute(ctx.Resp, ctx.Data); err != nil {
103+
ctx.ServerError("unable to execute template", err)
104+
}
105+
}
106+
93107
// RenderToString renders the template content to a string
94108
func (ctx *Context) RenderToString(name base.TplName, data map[string]any) (string, error) {
95109
var buf strings.Builder

modules/generate/generate.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package generate
77
import (
88
"crypto/rand"
99
"encoding/base64"
10+
"fmt"
1011
"io"
1112
"time"
1213

@@ -38,19 +39,24 @@ func NewInternalToken() (string, error) {
3839
return internalToken, nil
3940
}
4041

41-
// NewJwtSecret generates a new value intended to be used for JWT secrets.
42-
func NewJwtSecret() ([]byte, error) {
43-
bytes := make([]byte, 32)
44-
_, err := io.ReadFull(rand.Reader, bytes)
45-
if err != nil {
42+
const defaultJwtSecretLen = 32
43+
44+
// DecodeJwtSecretBase64 decodes a base64 encoded jwt secret into bytes, and check its length
45+
func DecodeJwtSecretBase64(src string) ([]byte, error) {
46+
encoding := base64.RawURLEncoding
47+
decoded := make([]byte, encoding.DecodedLen(len(src))+3)
48+
if n, err := encoding.Decode(decoded, []byte(src)); err != nil {
4649
return nil, err
50+
} else if n != defaultJwtSecretLen {
51+
return nil, fmt.Errorf("invalid base64 decoded length: %d, expects: %d", n, defaultJwtSecretLen)
4752
}
48-
return bytes, nil
53+
return decoded[:defaultJwtSecretLen], nil
4954
}
5055

51-
// NewJwtSecretBase64 generates a new base64 encoded value intended to be used for JWT secrets.
52-
func NewJwtSecretBase64() ([]byte, string, error) {
53-
bytes, err := NewJwtSecret()
56+
// NewJwtSecretWithBase64 generates a jwt secret with its base64 encoded value intended to be used for saving into config file
57+
func NewJwtSecretWithBase64() ([]byte, string, error) {
58+
bytes := make([]byte, defaultJwtSecretLen)
59+
_, err := io.ReadFull(rand.Reader, bytes)
5460
if err != nil {
5561
return nil, "", err
5662
}

modules/generate/generate_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2024 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package generate
5+
6+
import (
7+
"encoding/base64"
8+
"strings"
9+
"testing"
10+
11+
"github.com/stretchr/testify/assert"
12+
)
13+
14+
func TestDecodeJwtSecretBase64(t *testing.T) {
15+
_, err := DecodeJwtSecretBase64("abcd")
16+
assert.ErrorContains(t, err, "invalid base64 decoded length")
17+
_, err = DecodeJwtSecretBase64(strings.Repeat("a", 64))
18+
assert.ErrorContains(t, err, "invalid base64 decoded length")
19+
20+
str32 := strings.Repeat("x", 32)
21+
encoded32 := base64.RawURLEncoding.EncodeToString([]byte(str32))
22+
decoded32, err := DecodeJwtSecretBase64(encoded32)
23+
assert.NoError(t, err)
24+
assert.Equal(t, str32, string(decoded32))
25+
}
26+
27+
func TestNewJwtSecretWithBase64(t *testing.T) {
28+
secret, encoded, err := NewJwtSecretWithBase64()
29+
assert.NoError(t, err)
30+
assert.Len(t, secret, 32)
31+
decoded, err := DecodeJwtSecretBase64(encoded)
32+
assert.NoError(t, err)
33+
assert.Equal(t, secret, decoded)
34+
}

modules/setting/lfs.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
package setting
55

66
import (
7-
"encoding/base64"
87
"fmt"
98
"time"
109

1110
"code.gitea.io/gitea/modules/generate"
12-
"code.gitea.io/gitea/modules/util"
1311
)
1412

1513
// LFS represents the configuration for Git LFS
@@ -62,9 +60,9 @@ func loadLFSFrom(rootCfg ConfigProvider) error {
6260
}
6361

6462
LFS.JWTSecretBase64 = loadSecret(rootCfg.Section("server"), "LFS_JWT_SECRET_URI", "LFS_JWT_SECRET")
65-
LFS.JWTSecretBytes, err = util.Base64FixedDecode(base64.RawURLEncoding, []byte(LFS.JWTSecretBase64), 32)
63+
LFS.JWTSecretBytes, err = generate.DecodeJwtSecretBase64(LFS.JWTSecretBase64)
6664
if err != nil {
67-
LFS.JWTSecretBytes, LFS.JWTSecretBase64, err = generate.NewJwtSecretBase64()
65+
LFS.JWTSecretBytes, LFS.JWTSecretBase64, err = generate.NewJwtSecretWithBase64()
6866
if err != nil {
6967
return fmt.Errorf("error generating JWT Secret for custom config: %v", err)
7068
}

0 commit comments

Comments
 (0)