Skip to content

Commit 90b20ce

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Change the default maxPerPage for gitbucket (go-gitea#30392) Fix the spacing issue in the Project view (go-gitea#30415) Add commit status summary table to reduce query from commit status table (go-gitea#30223) Split `issue edit` code from `repo-legacy.js` into its own file (go-gitea#30419) Check the token's owner and repository when registering a runner (go-gitea#30406) Avoid user does not exist error when detecting schedule actions when the commit author is an external user (go-gitea#30357) Update actions variables documents (go-gitea#30394) Fix author name alignment in commits table (go-gitea#30396)
2 parents 5b272f1 + 7af074d commit 90b20ce

File tree

26 files changed

+510
-329
lines changed

26 files changed

+510
-329
lines changed

docs/content/usage/actions/act-runner.en-us.md

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -303,34 +303,3 @@ sudo systemctl enable act_runner --now
303303
```
304304

305305
If using Docker, the `act_runner` user should also be added to the `docker` group before starting the service. Keep in mind that this effectively gives `act_runner` root access to the system [[1]](https://docs.docker.com/engine/security/#docker-daemon-attack-surface).
306-
307-
## Configuration variable
308-
309-
You can create configuration variables on the user, organization and repository level.
310-
The level of the variable depends on where you created it.
311-
312-
### Naming conventions
313-
314-
The following rules apply to variable names:
315-
316-
- Variable names can only contain alphanumeric characters (`[a-z]`, `[A-Z]`, `[0-9]`) or underscores (`_`). Spaces are not allowed.
317-
318-
- Variable names must not start with the `GITHUB_` and `GITEA_` prefix.
319-
320-
- Variable names must not start with a number.
321-
322-
- Variable names are case-insensitive.
323-
324-
- Variable names must be unique at the level they are created at.
325-
326-
- Variable names must not be `CI`.
327-
328-
### Using variable
329-
330-
After creating configuration variables, they will be automatically filled in the `vars` context.
331-
They can be accessed through expressions like `{{ vars.VARIABLE_NAME }}` in the workflow.
332-
333-
### Precedence
334-
335-
If a variable with the same name exists at multiple levels, the variable at the lowest level takes precedence:
336-
A repository variable will always be chosen over an organization/user variable.

docs/content/usage/actions/act-runner.zh-cn.md

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -258,32 +258,3 @@ Runner的标签用于确定Runner可以运行哪些Job以及如何运行它们
258258
Runner将从Gitea实例获取Job并自动运行它们。
259259

260260
由于Act Runner仍处于开发中,建议定期检查最新版本并进行升级。
261-
262-
## 变量
263-
264-
您可以创建用户、组织和仓库级别的变量。变量的级别取决于创建它的位置。
265-
266-
### 命名规则
267-
268-
以下规则适用于变量名:
269-
270-
- 变量名称只能包含字母数字字符 (`[a-z]`, `[A-Z]`, `[0-9]`) 或下划线 (`_`)。不允许使用空格。
271-
272-
- 变量名称不能以 `GITHUB_` 和 `GITEA_` 前缀开头。
273-
274-
- 变量名称不能以数字开头。
275-
276-
- 变量名称不区分大小写。
277-
278-
- 变量名称在创建它们的级别上必须是唯一的。
279-
280-
- 变量名称不能为 “CI”。
281-
282-
### 使用
283-
284-
创建配置变量后,它们将自动填充到 `vars` 上下文中。您可以在工作流中使用类似 `{{ vars.VARIABLE_NAME }}` 这样的表达式来使用它们。
285-
286-
### 优先级
287-
288-
如果同名变量存在于多个级别,则级别最低的变量优先。
289-
仓库级别的变量总是比组织或者用户级别的变量优先被选中。
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
date: "2024-04-10T22:21:00+08:00"
3+
title: "Variables"
4+
slug: "actions-variables"
5+
sidebar_position: 25
6+
draft: false
7+
toc: false
8+
menu:
9+
sidebar:
10+
parent: "actions"
11+
name: "Variables"
12+
sidebar_position: 25
13+
identifier: "actions-variables"
14+
---
15+
16+
## Variables
17+
18+
You can create configuration variables on the user, organization and repository level.
19+
The level of the variable depends on where you created it. When creating a variable, the
20+
key will be converted to uppercase. You need use uppercase on the yaml file.
21+
22+
### Naming conventions
23+
24+
The following rules apply to variable names:
25+
26+
- Variable names can only contain alphanumeric characters (`[a-z]`, `[A-Z]`, `[0-9]`) or underscores (`_`). Spaces are not allowed.
27+
- Variable names must not start with the `GITHUB_` and `GITEA_` prefix.
28+
- Variable names must not start with a number.
29+
- Variable names are case-insensitive.
30+
- Variable names must be unique at the level they are created at.
31+
- Variable names must not be `CI`.
32+
33+
### Using variable
34+
35+
After creating configuration variables, they will be automatically filled in the `vars` context.
36+
They can be accessed through expressions like `${{ vars.VARIABLE_NAME }}` in the workflow.
37+
38+
### Precedence
39+
40+
If a variable with the same name exists at multiple levels, the variable at the lowest level takes precedence:
41+
A repository variable will always be chosen over an organization/user variable.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
date: "2024-04-10T22:21:00+08:00"
3+
title: "变量"
4+
slug: "actions-variables"
5+
sidebar_position: 25
6+
draft: false
7+
toc: false
8+
menu:
9+
sidebar:
10+
parent: "actions"
11+
name: "变量"
12+
sidebar_position: 25
13+
identifier: "actions-variables"
14+
---
15+
16+
## 变量
17+
18+
您可以创建用户、组织和仓库级别的变量。变量的级别取决于创建它的位置。当创建变量时,变量的名称会被
19+
转换为大写,在yaml文件中引用时需要使用大写。
20+
21+
### 命名规则
22+
23+
以下规则适用于变量名:
24+
25+
- 变量名称只能包含字母数字字符 (`[a-z]`, `[A-Z]`, `[0-9]`) 或下划线 (`_`)。不允许使用空格。
26+
- 变量名称不能以 `GITHUB_``GITEA_` 前缀开头。
27+
- 变量名称不能以数字开头。
28+
- 变量名称不区分大小写。
29+
- 变量名称在创建它们的级别上必须是唯一的。
30+
- 变量名称不能为 `CI`
31+
32+
### 使用
33+
34+
创建配置变量后,它们将自动填充到 `vars` 上下文中。您可以在工作流中使用类似 `${{ vars.VARIABLE_NAME }}` 这样的表达式来使用它们。
35+
36+
### 优先级
37+
38+
如果同名变量存在于多个级别,则级别最低的变量优先。
39+
仓库级别的变量总是比组织或者用户级别的变量优先被选中。

models/actions/schedule_list.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ func (schedules ScheduleList) LoadTriggerUser(ctx context.Context) error {
4040
schedule.TriggerUser = user_model.NewActionsUser()
4141
} else {
4242
schedule.TriggerUser = users[schedule.TriggerUserID]
43+
if schedule.TriggerUser == nil {
44+
schedule.TriggerUser = user_model.NewGhostUser()
45+
}
4346
}
4447
}
4548
return nil

models/git/commit_status.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -292,30 +292,27 @@ func GetLatestCommitStatus(ctx context.Context, repoID int64, sha string, listOp
292292
}
293293

294294
// GetLatestCommitStatusForPairs returns all statuses with a unique context for a given list of repo-sha pairs
295-
func GetLatestCommitStatusForPairs(ctx context.Context, repoIDsToLatestCommitSHAs map[int64]string, listOptions db.ListOptions) (map[int64][]*CommitStatus, error) {
295+
func GetLatestCommitStatusForPairs(ctx context.Context, repoSHAs []RepoSHA) (map[int64][]*CommitStatus, error) {
296296
type result struct {
297297
Index int64
298298
RepoID int64
299+
SHA string
299300
}
300301

301-
results := make([]result, 0, len(repoIDsToLatestCommitSHAs))
302+
results := make([]result, 0, len(repoSHAs))
302303

303304
getBase := func() *xorm.Session {
304305
return db.GetEngine(ctx).Table(&CommitStatus{})
305306
}
306307

307308
// Create a disjunction of conditions for each repoID and SHA pair
308-
conds := make([]builder.Cond, 0, len(repoIDsToLatestCommitSHAs))
309-
for repoID, sha := range repoIDsToLatestCommitSHAs {
310-
conds = append(conds, builder.Eq{"repo_id": repoID, "sha": sha})
309+
conds := make([]builder.Cond, 0, len(repoSHAs))
310+
for _, repoSHA := range repoSHAs {
311+
conds = append(conds, builder.Eq{"repo_id": repoSHA.RepoID, "sha": repoSHA.SHA})
311312
}
312313
sess := getBase().Where(builder.Or(conds...)).
313-
Select("max( `index` ) as `index`, repo_id").
314-
GroupBy("context_hash, repo_id").OrderBy("max( `index` ) desc")
315-
316-
if !listOptions.IsListAll() {
317-
sess = db.SetSessionPagination(sess, &listOptions)
318-
}
314+
Select("max( `index` ) as `index`, repo_id, sha").
315+
GroupBy("context_hash, repo_id, sha").OrderBy("max( `index` ) desc")
319316

320317
err := sess.Find(&results)
321318
if err != nil {
@@ -332,7 +329,7 @@ func GetLatestCommitStatusForPairs(ctx context.Context, repoIDsToLatestCommitSHA
332329
cond := builder.Eq{
333330
"`index`": result.Index,
334331
"repo_id": result.RepoID,
335-
"sha": repoIDsToLatestCommitSHAs[result.RepoID],
332+
"sha": result.SHA,
336333
}
337334
conds = append(conds, cond)
338335
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Copyright 2024 Gitea. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package git
5+
6+
import (
7+
"context"
8+
9+
"code.gitea.io/gitea/models/db"
10+
"code.gitea.io/gitea/modules/setting"
11+
api "code.gitea.io/gitea/modules/structs"
12+
13+
"xorm.io/builder"
14+
)
15+
16+
// CommitStatusSummary holds the latest commit Status of a single Commit
17+
type CommitStatusSummary struct {
18+
ID int64 `xorm:"pk autoincr"`
19+
RepoID int64 `xorm:"INDEX UNIQUE(repo_id_sha)"`
20+
SHA string `xorm:"VARCHAR(64) NOT NULL INDEX UNIQUE(repo_id_sha)"`
21+
State api.CommitStatusState `xorm:"VARCHAR(7) NOT NULL"`
22+
}
23+
24+
func init() {
25+
db.RegisterModel(new(CommitStatusSummary))
26+
}
27+
28+
type RepoSHA struct {
29+
RepoID int64
30+
SHA string
31+
}
32+
33+
func GetLatestCommitStatusForRepoAndSHAs(ctx context.Context, repoSHAs []RepoSHA) ([]*CommitStatus, error) {
34+
cond := builder.NewCond()
35+
for _, rs := range repoSHAs {
36+
cond = cond.Or(builder.Eq{"repo_id": rs.RepoID, "sha": rs.SHA})
37+
}
38+
39+
var summaries []CommitStatusSummary
40+
if err := db.GetEngine(ctx).Where(cond).Find(&summaries); err != nil {
41+
return nil, err
42+
}
43+
44+
commitStatuses := make([]*CommitStatus, 0, len(repoSHAs))
45+
for _, summary := range summaries {
46+
commitStatuses = append(commitStatuses, &CommitStatus{
47+
RepoID: summary.RepoID,
48+
SHA: summary.SHA,
49+
State: summary.State,
50+
})
51+
}
52+
return commitStatuses, nil
53+
}
54+
55+
func UpdateCommitStatusSummary(ctx context.Context, repoID int64, sha string) error {
56+
commitStatuses, _, err := GetLatestCommitStatus(ctx, repoID, sha, db.ListOptionsAll)
57+
if err != nil {
58+
return err
59+
}
60+
state := CalcCommitStatus(commitStatuses)
61+
// mysql will return 0 when update a record which state hasn't been changed which behaviour is different from other database,
62+
// so we need to use insert in on duplicate
63+
if setting.Database.Type.IsMySQL() {
64+
_, err := db.GetEngine(ctx).Exec("INSERT INTO commit_status_summary (repo_id,sha,state) VALUES (?,?,?) ON DUPLICATE KEY UPDATE state=?",
65+
repoID, sha, state.State, state.State)
66+
return err
67+
}
68+
69+
if cnt, err := db.GetEngine(ctx).Where("repo_id=? AND sha=?", repoID, sha).
70+
Cols("state").
71+
Update(&CommitStatusSummary{
72+
State: state.State,
73+
}); err != nil {
74+
return err
75+
} else if cnt == 0 {
76+
_, err = db.GetEngine(ctx).Insert(&CommitStatusSummary{
77+
RepoID: repoID,
78+
SHA: sha,
79+
State: state.State,
80+
})
81+
return err
82+
}
83+
return nil
84+
}

models/migrations/migrations.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,10 @@ var migrations = []Migration{
576576

577577
// Gitea 1.22.0 ends at 294
578578

579+
// v294 -> v295
579580
NewMigration("Add unique index for project issue table", v1_23.AddUniqueIndexForProjectIssue),
581+
// v295 -> v296
582+
NewMigration("Add commit status summary table", v1_23.AddCommitStatusSummary),
580583
}
581584

582585
// GetCurrentDBVersion returns the current db version

models/migrations/v1_23/v295.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2024 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_23 //nolint
5+
6+
import "xorm.io/xorm"
7+
8+
func AddCommitStatusSummary(x *xorm.Engine) error {
9+
type CommitStatusSummary struct {
10+
ID int64 `xorm:"pk autoincr"`
11+
RepoID int64 `xorm:"INDEX UNIQUE(repo_id_sha)"`
12+
SHA string `xorm:"VARCHAR(64) NOT NULL INDEX UNIQUE(repo_id_sha)"`
13+
State string `xorm:"VARCHAR(7) NOT NULL"`
14+
}
15+
// there is no migrations because if there is no data on this table, it will fall back to get data
16+
// from commit status
17+
return x.Sync2(new(CommitStatusSummary))
18+
}

models/organization/org.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"strings"
1111

12+
actions_model "code.gitea.io/gitea/models/actions"
1213
"code.gitea.io/gitea/models/db"
1314
"code.gitea.io/gitea/models/perm"
1415
repo_model "code.gitea.io/gitea/models/repo"
@@ -402,6 +403,8 @@ func DeleteOrganization(ctx context.Context, org *Organization) error {
402403
&TeamInvite{OrgID: org.ID},
403404
&secret_model.Secret{OwnerID: org.ID},
404405
&user_model.Blocking{BlockerID: org.ID},
406+
&actions_model.ActionRunner{OwnerID: org.ID},
407+
&actions_model.ActionRunnerToken{OwnerID: org.ID},
405408
); err != nil {
406409
return fmt.Errorf("DeleteBeans: %w", err)
407410
}

0 commit comments

Comments
 (0)