Skip to content

Commit dd1ca6c

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: (23 commits) Fix wrong test usage of `AppSubURL` (go-gitea#29459) Improve contrast on blame timestamp, fix double border (go-gitea#29482) Fix/Improve `processWindowErrorEvent` (go-gitea#29407) Apply compact padding to small buttons with svg icons (go-gitea#29471) Fix counter display number incorrectly displayed on the page (go-gitea#29448) Fix incorrect user location link on profile page (go-gitea#29474) Fix workflow trigger event bugs (go-gitea#29467) Fix URL calculation in clone input box (go-gitea#29470) Remove jQuery from the "find file" page (go-gitea#29456) Move generate from module to service (go-gitea#29465) The job should always run when `if` is `always()` (go-gitea#29464) Recolor dark theme to blue shade (go-gitea#29283) Let ctx.FormOptionalBool() return optional.Option[bool] (go-gitea#29461) Implement actions badge svgs (go-gitea#28102) Fix missed return (go-gitea#29450) Use tailwind instead of `gt-[wh]-` helper classes (go-gitea#29423) Lock issues and pulls faster (go-gitea#29436) Allow to change primary email before account activation (go-gitea#29412) Update docs about `DEFAULT_ACTIONS_URL` (go-gitea#29442) Only use supported sort order for "explore/users" page (go-gitea#29430) ...
2 parents ddef710 + a6fd017 commit dd1ca6c

File tree

405 files changed

+1249
-754
lines changed

Some content is hidden

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

405 files changed

+1249
-754
lines changed

.github/workflows/cron-lock.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,9 @@ jobs:
1919
steps:
2020
- uses: dessant/lock-threads@v5
2121
with:
22-
issue-inactive-days: 45
22+
issue-inactive-days: 10
23+
issue-comment: |
24+
Automatically locked because of our [CONTRIBUTING guidelines](https://github.com/go-gitea/gitea/blob/main/CONTRIBUTING.md#issue-locking)
25+
pr-inactive-days: 7
26+
pr-comment: |
27+
Automatically locked because of our [CONTRIBUTING guidelines](https://github.com/go-gitea/gitea/blob/main/CONTRIBUTING.md#issue-locking)

docs/content/usage/actions/faq.en-us.md

+7-8
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,24 @@ It is technically possible to implement, but we need to discuss whether it is ne
4545

4646
## Where will the runner download scripts when using actions such as `actions/checkout@v4`?
4747

48-
You may be aware that there are tens of thousands of [marketplace actions](https://github.com/marketplace?type=actions) in GitHub.
49-
However, when you write `uses: actions/checkout@v4`, it actually downloads the scripts from [gitea.com/actions/checkout](http://gitea.com/actions/checkout) by default (not GitHub).
50-
This is a mirror of [github.com/actions/checkout](http://github.com/actions/checkout), but it's impossible to mirror all of them.
51-
That's why you may encounter failures when trying to use some actions that haven't been mirrored.
48+
There are tens of thousands of [actions scripts](https://github.com/marketplace?type=actions) in GitHub, and when you write `uses: actions/checkout@v4`, it downloads the scripts from [github.com/actions/checkout](http://github.com/actions/checkout) by default.
49+
But what if you want to use actions from other places such as gitea.com instead of GitHub?
5250

5351
The good news is that you can specify the URL prefix to use actions from anywhere.
5452
This is an extra syntax in Gitea Actions.
5553
For example:
5654

57-
- `uses: https://github.com/xxx/xxx@xxx`
5855
- `uses: https://gitea.com/xxx/xxx@xxx`
56+
- `uses: https://github.com/xxx/xxx@xxx`
5957
- `uses: http://your_gitea_instance.com/xxx@xxx`
6058

6159
Be careful, the `https://` or `http://` prefix is necessary!
6260

63-
Alternatively, if you want your runners to download actions from GitHub or your own Gitea instance by default, you can configure it by setting `[actions].DEFAULT_ACTIONS_URL`.
64-
See [Configuration Cheat Sheet](administration/config-cheat-sheet.md#actions-actions).
61+
This is one of the differences from GitHub Actions which supports actions scripts only from GitHub.
62+
But it should allow users much more flexibility in how they run Actions.
6563

66-
This is one of the differences from GitHub Actions, but it should allow users much more flexibility in how they run Actions.
64+
Alternatively, if you want your runners to download actions from your own Gitea instance by default, you can configure it by setting `[actions].DEFAULT_ACTIONS_URL`.
65+
See [Configuration Cheat Sheet](administration/config-cheat-sheet.md#actions-actions).
6766

6867
## How to limit the permission of the runners?
6968

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,25 @@ DEFAULT_REPO_UNITS = ...,repo.actions
4545

4646
## 使用`actions/checkout@v4`等Actions时,Job容器会从何处下载脚本?
4747

48-
您可能知道GitHub上有成千上万个[Actions市场](https://github.com/marketplace?type=actions)
49-
然而,当您编写`uses: actions/checkout@v4`时,它实际上默认从[gitea.com/actions/checkout](http://gitea.com/actions/checkout)下载脚本(而不是从GitHub下载)。
50-
这是[github.com/actions/checkout](http://github.com/actions/checkout)的镜像,但无法将它们全部镜像。
51-
这就是为什么在尝试使用尚未镜像的某些Actions时可能会遇到失败的原因。
48+
GitHub 上有成千上万个 [Actions 脚本](https://github.com/marketplace?type=actions)
49+
当您编写 `uses: actions/checkout@v4` 时,它默认会从 [github.com/actions/checkout](https://github.com/actions/checkout) 下载脚本。
50+
那如果您想使用一些托管在其它平台上的脚本呢,比如在 gitea.com 上的?
5251

5352
好消息是,您可以指定要从任何位置使用Actions的URL前缀。
5453
这是Gitea Actions中的额外语法。
5554
例如:
5655

57-
- `uses: https://github.com/xxx/xxx@xxx`
5856
- `uses: https://gitea.com/xxx/xxx@xxx`
57+
- `uses: https://github.com/xxx/xxx@xxx`
5958
- `uses: http://your_gitea_instance.com/xxx@xxx`
6059

6160
注意,`https://``http://`前缀是必需的!
6261

63-
另外,如果您希望您的Runner默认从GitHub或您自己的Gitea实例下载Actions,可以通过设置 `[actions].DEFAULT_ACTIONS_URL`进行配置
64-
参见[配置速查表](administration/config-cheat-sheet.md#actions-actions)
62+
这是与 GitHub Actions 的一个区别,GitHub Actions 只允许使用托管在 GitHub 上的 actions 脚本
63+
但用户理应拥有权利去灵活决定如何运行 Actions
6564

66-
这是与GitHub Actions的一个区别,但它应该允许用户以更灵活的方式运行Actions。
65+
另外,如果您希望您的 Runner 默认从您自己的 Gitea 实例下载 Actions,可以通过设置 `[actions].DEFAULT_ACTIONS_URL`进行配置。
66+
参见[配置速查表](administration/config-cheat-sheet.md#actions-actions)
6767

6868
## 如何限制Runner的权限?
6969

docs/content/usage/badge.en-us.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
date: "2023-02-25T00:00:00+00:00"
3+
title: "Badge"
4+
slug: "badge"
5+
sidebar_position: 11
6+
toc: false
7+
draft: false
8+
aliases:
9+
- /en-us/badge
10+
menu:
11+
sidebar:
12+
parent: "usage"
13+
name: "Badge"
14+
sidebar_position: 11
15+
identifier: "Badge"
16+
---
17+
18+
# Badge
19+
20+
Gitea has its builtin Badge system which allows you to display the status of your repository in other places. You can use the following badges:
21+
22+
## Workflow Badge
23+
24+
The Gitea Actions workflow badge is a badge that shows the status of the latest workflow run.
25+
It is designed to be compatible with [GitHub Actions workflow badge](https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/adding-a-workflow-status-badge).
26+
27+
You can use the following URL to get the badge:
28+
29+
```
30+
https://your-gitea-instance.com/{owner}/{repo}/actions/workflows/{workflow_file}?branch={branch}&event={event}
31+
```
32+
33+
- `{owner}`: The owner of the repository.
34+
- `{repo}`: The name of the repository.
35+
- `{workflow_file}`: The name of the workflow file.
36+
- `{branch}`: Optional. The branch of the workflow. Default to your repository's default branch.
37+
- `{event}`: Optional. The event of the workflow. Default to none.

models/actions/run.go

+17
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,23 @@ func GetRunByIndex(ctx context.Context, repoID, index int64) (*ActionRun, error)
339339
return run, nil
340340
}
341341

342+
func GetWorkflowLatestRun(ctx context.Context, repoID int64, workflowFile, branch, event string) (*ActionRun, error) {
343+
var run ActionRun
344+
q := db.GetEngine(ctx).Where("repo_id=?", repoID).
345+
And("ref = ?", branch).
346+
And("workflow_id = ?", workflowFile)
347+
if event != "" {
348+
q.And("event = ?", event)
349+
}
350+
has, err := q.Desc("id").Get(&run)
351+
if err != nil {
352+
return nil, err
353+
} else if !has {
354+
return nil, util.NewNotExistErrorf("run with repo_id %d, ref %s, workflow_id %s", repoID, branch, workflowFile)
355+
}
356+
return &run, nil
357+
}
358+
342359
// UpdateRun updates a run.
343360
// It requires the inputted run has Version set.
344361
// It will return error if the version is not matched (it means the run has been changed after loaded).

models/repo/release.go

+11-10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"code.gitea.io/gitea/models/db"
1616
user_model "code.gitea.io/gitea/models/user"
1717
"code.gitea.io/gitea/modules/container"
18+
"code.gitea.io/gitea/modules/optional"
1819
"code.gitea.io/gitea/modules/structs"
1920
"code.gitea.io/gitea/modules/timeutil"
2021
"code.gitea.io/gitea/modules/util"
@@ -228,10 +229,10 @@ type FindReleasesOptions struct {
228229
RepoID int64
229230
IncludeDrafts bool
230231
IncludeTags bool
231-
IsPreRelease util.OptionalBool
232-
IsDraft util.OptionalBool
232+
IsPreRelease optional.Option[bool]
233+
IsDraft optional.Option[bool]
233234
TagNames []string
234-
HasSha1 util.OptionalBool // useful to find draft releases which are created with existing tags
235+
HasSha1 optional.Option[bool] // useful to find draft releases which are created with existing tags
235236
}
236237

237238
func (opts FindReleasesOptions) ToConds() builder.Cond {
@@ -246,14 +247,14 @@ func (opts FindReleasesOptions) ToConds() builder.Cond {
246247
if len(opts.TagNames) > 0 {
247248
cond = cond.And(builder.In("tag_name", opts.TagNames))
248249
}
249-
if !opts.IsPreRelease.IsNone() {
250-
cond = cond.And(builder.Eq{"is_prerelease": opts.IsPreRelease.IsTrue()})
250+
if opts.IsPreRelease.Has() {
251+
cond = cond.And(builder.Eq{"is_prerelease": opts.IsPreRelease.Value()})
251252
}
252-
if !opts.IsDraft.IsNone() {
253-
cond = cond.And(builder.Eq{"is_draft": opts.IsDraft.IsTrue()})
253+
if opts.IsDraft.Has() {
254+
cond = cond.And(builder.Eq{"is_draft": opts.IsDraft.Value()})
254255
}
255-
if !opts.HasSha1.IsNone() {
256-
if opts.HasSha1.IsTrue() {
256+
if opts.HasSha1.Has() {
257+
if opts.HasSha1.Value() {
257258
cond = cond.And(builder.Neq{"sha1": ""})
258259
} else {
259260
cond = cond.And(builder.Eq{"sha1": ""})
@@ -275,7 +276,7 @@ func GetTagNamesByRepoID(ctx context.Context, repoID int64) ([]string, error) {
275276
ListOptions: listOptions,
276277
IncludeDrafts: true,
277278
IncludeTags: true,
278-
HasSha1: util.OptionalBoolTrue,
279+
HasSha1: optional.Some(true),
279280
RepoID: repoID,
280281
}
281282

models/user/email_address.go

+29-17
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ import (
2121
"xorm.io/builder"
2222
)
2323

24-
// ErrEmailNotActivated e-mail address has not been activated error
25-
var ErrEmailNotActivated = util.NewInvalidArgumentErrorf("e-mail address has not been activated")
26-
2724
// ErrEmailCharIsNotSupported e-mail address contains unsupported character
2825
type ErrEmailCharIsNotSupported struct {
2926
Email string
@@ -313,27 +310,27 @@ func updateActivation(ctx context.Context, email *EmailAddress, activate bool) e
313310
return UpdateUserCols(ctx, user, "rands")
314311
}
315312

316-
// MakeEmailPrimary sets primary email address of given user.
317-
func MakeEmailPrimary(ctx context.Context, email *EmailAddress) error {
318-
has, err := db.GetEngine(ctx).Get(email)
319-
if err != nil {
313+
func MakeActiveEmailPrimary(ctx context.Context, emailID int64) error {
314+
return makeEmailPrimaryInternal(ctx, emailID, true)
315+
}
316+
317+
func MakeInactiveEmailPrimary(ctx context.Context, emailID int64) error {
318+
return makeEmailPrimaryInternal(ctx, emailID, false)
319+
}
320+
321+
func makeEmailPrimaryInternal(ctx context.Context, emailID int64, isActive bool) error {
322+
email := &EmailAddress{}
323+
if has, err := db.GetEngine(ctx).ID(emailID).Where(builder.Eq{"is_activated": isActive}).Get(email); err != nil {
320324
return err
321325
} else if !has {
322-
return ErrEmailAddressNotExist{Email: email.Email}
323-
}
324-
325-
if !email.IsActivated {
326-
return ErrEmailNotActivated
326+
return ErrEmailAddressNotExist{}
327327
}
328328

329329
user := &User{}
330-
has, err = db.GetEngine(ctx).ID(email.UID).Get(user)
331-
if err != nil {
330+
if has, err := db.GetEngine(ctx).ID(email.UID).Get(user); err != nil {
332331
return err
333332
} else if !has {
334-
return ErrUserNotExist{
335-
UID: email.UID,
336-
}
333+
return ErrUserNotExist{UID: email.UID}
337334
}
338335

339336
ctx, committer, err := db.TxContext(ctx)
@@ -365,6 +362,21 @@ func MakeEmailPrimary(ctx context.Context, email *EmailAddress) error {
365362
return committer.Commit()
366363
}
367364

365+
// ChangeInactivePrimaryEmail replaces the inactive primary email of a given user
366+
func ChangeInactivePrimaryEmail(ctx context.Context, uid int64, oldEmailAddr, newEmailAddr string) error {
367+
return db.WithTx(ctx, func(ctx context.Context) error {
368+
_, err := db.GetEngine(ctx).Where(builder.Eq{"uid": uid, "lower_email": strings.ToLower(oldEmailAddr)}).Delete(&EmailAddress{})
369+
if err != nil {
370+
return err
371+
}
372+
newEmail, err := InsertEmailAddress(ctx, &EmailAddress{UID: uid, Email: newEmailAddr})
373+
if err != nil {
374+
return err
375+
}
376+
return MakeInactiveEmailPrimary(ctx, newEmail.ID)
377+
})
378+
}
379+
368380
// VerifyActiveEmailCode verifies active email code when active account
369381
func VerifyActiveEmailCode(ctx context.Context, code, email string) *EmailAddress {
370382
minutes := setting.Service.ActiveCodeLives

models/user/email_address_test.go

+9-18
Original file line numberDiff line numberDiff line change
@@ -45,31 +45,22 @@ func TestIsEmailUsed(t *testing.T) {
4545
func TestMakeEmailPrimary(t *testing.T) {
4646
assert.NoError(t, unittest.PrepareTestDatabase())
4747

48-
email := &user_model.EmailAddress{
49-
Email: "user567890@example.com",
50-
}
51-
err := user_model.MakeEmailPrimary(db.DefaultContext, email)
48+
err := user_model.MakeActiveEmailPrimary(db.DefaultContext, 9999999)
5249
assert.Error(t, err)
53-
assert.EqualError(t, err, user_model.ErrEmailAddressNotExist{Email: email.Email}.Error())
50+
assert.ErrorIs(t, err, user_model.ErrEmailAddressNotExist{})
5451

55-
email = &user_model.EmailAddress{
56-
Email: "user11@example.com",
57-
}
58-
err = user_model.MakeEmailPrimary(db.DefaultContext, email)
52+
email := unittest.AssertExistsAndLoadBean(t, &user_model.EmailAddress{Email: "user11@example.com"})
53+
err = user_model.MakeActiveEmailPrimary(db.DefaultContext, email.ID)
5954
assert.Error(t, err)
60-
assert.EqualError(t, err, user_model.ErrEmailNotActivated.Error())
55+
assert.ErrorIs(t, err, user_model.ErrEmailAddressNotExist{}) // inactive email is considered as not exist for "MakeActiveEmailPrimary"
6156

62-
email = &user_model.EmailAddress{
63-
Email: "user9999999@example.com",
64-
}
65-
err = user_model.MakeEmailPrimary(db.DefaultContext, email)
57+
email = unittest.AssertExistsAndLoadBean(t, &user_model.EmailAddress{Email: "user9999999@example.com"})
58+
err = user_model.MakeActiveEmailPrimary(db.DefaultContext, email.ID)
6659
assert.Error(t, err)
6760
assert.True(t, user_model.IsErrUserNotExist(err))
6861

69-
email = &user_model.EmailAddress{
70-
Email: "user101@example.com",
71-
}
72-
err = user_model.MakeEmailPrimary(db.DefaultContext, email)
62+
email = unittest.AssertExistsAndLoadBean(t, &user_model.EmailAddress{Email: "user101@example.com"})
63+
err = user_model.MakeActiveEmailPrimary(db.DefaultContext, email.ID)
7364
assert.NoError(t, err)
7465

7566
user, _ := user_model.GetUserByID(db.DefaultContext, int64(10))

models/user/search.go

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strings"
1010

1111
"code.gitea.io/gitea/models/db"
12+
"code.gitea.io/gitea/modules/container"
1213
"code.gitea.io/gitea/modules/structs"
1314
"code.gitea.io/gitea/modules/util"
1415

@@ -30,6 +31,8 @@ type SearchUserOptions struct {
3031
Actor *User // The user doing the search
3132
SearchByEmail bool // Search by email as well as username/full name
3233

34+
SupportedSortOrders container.Set[string] // if not nil, only allow to use the sort orders in this set
35+
3336
IsActive util.OptionalBool
3437
IsAdmin util.OptionalBool
3538
IsRestricted util.OptionalBool

modules/actions/workflows.go

+3
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,9 @@ func matchPullRequestEvent(gitRepo *git.Repository, commit *git.Commit, prPayloa
441441
// all acts conditions should be satisfied
442442
for cond, vals := range acts {
443443
switch cond {
444+
case "types":
445+
// types have been checked
446+
continue
444447
case "branches":
445448
refName := git.RefName(prPayload.PullRequest.Base.Ref)
446449
patterns, err := workflowpattern.CompilePatterns(vals...)

0 commit comments

Comments
 (0)