Skip to content

Commit f878b14

Browse files
committed
Merge branch 'main' into api-lock-issue
2 parents 40e533c + 6d3c674 commit f878b14

File tree

86 files changed

+2007
-372
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

+2007
-372
lines changed

cmd/admin_user_create.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ var microcmdUserCreate = &cli.Command{
8181
Name: "restricted",
8282
Usage: "Make a restricted user account",
8383
},
84+
&cli.StringFlag{
85+
Name: "fullname",
86+
Usage: `The full, human-readable name of the user`,
87+
},
8488
},
8589
}
8690

@@ -191,6 +195,7 @@ func runCreateUser(c *cli.Context) error {
191195
Passwd: password,
192196
MustChangePassword: mustChangePassword,
193197
Visibility: visibility,
198+
FullName: c.String("fullname"),
194199
}
195200

196201
overwriteDefault := &user_model.CreateUserOverwriteOptions{

cmd/admin_user_create_test.go

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@ func TestAdminUserCreate(t *testing.T) {
5050
assert.Equal(t, check{IsAdmin: false, MustChangePassword: false}, createCheck("u5", "--must-change-password=false"))
5151
})
5252

53-
createUser := func(name, args string) error {
54-
return app.Run(strings.Fields(fmt.Sprintf("./gitea admin user create --username %s --email %s@gitea.local %s", name, name, args)))
53+
createUser := func(name string, args ...string) error {
54+
return app.Run(append([]string{"./gitea", "admin", "user", "create", "--username", name, "--email", name + "@gitea.local"}, args...))
5555
}
5656

5757
t.Run("UserType", func(t *testing.T) {
5858
reset()
59-
assert.ErrorContains(t, createUser("u", "--user-type invalid"), "invalid user type")
60-
assert.ErrorContains(t, createUser("u", "--user-type bot --password 123"), "can only be set for individual users")
61-
assert.ErrorContains(t, createUser("u", "--user-type bot --must-change-password"), "can only be set for individual users")
59+
assert.ErrorContains(t, createUser("u", "--user-type", "invalid"), "invalid user type")
60+
assert.ErrorContains(t, createUser("u", "--user-type", "bot", "--password", "123"), "can only be set for individual users")
61+
assert.ErrorContains(t, createUser("u", "--user-type", "bot", "--must-change-password"), "can only be set for individual users")
6262

63-
assert.NoError(t, createUser("u", "--user-type bot"))
63+
assert.NoError(t, createUser("u", "--user-type", "bot"))
6464
u := unittest.AssertExistsAndLoadBean(t, &user_model.User{LowerName: "u"})
6565
assert.Equal(t, user_model.UserTypeBot, u.Type)
6666
assert.Empty(t, u.Passwd)
@@ -75,7 +75,7 @@ func TestAdminUserCreate(t *testing.T) {
7575

7676
// using "--access-token" only means "all" access
7777
reset()
78-
assert.NoError(t, createUser("u", "--random-password --access-token"))
78+
assert.NoError(t, createUser("u", "--random-password", "--access-token"))
7979
assert.Equal(t, 1, unittest.GetCount(t, &user_model.User{}))
8080
assert.Equal(t, 1, unittest.GetCount(t, &auth_model.AccessToken{}))
8181
accessToken := unittest.AssertExistsAndLoadBean(t, &auth_model.AccessToken{Name: "gitea-admin"})
@@ -85,7 +85,7 @@ func TestAdminUserCreate(t *testing.T) {
8585

8686
// using "--access-token" with name & scopes
8787
reset()
88-
assert.NoError(t, createUser("u", "--random-password --access-token --access-token-name new-token-name --access-token-scopes read:issue,read:user"))
88+
assert.NoError(t, createUser("u", "--random-password", "--access-token", "--access-token-name", "new-token-name", "--access-token-scopes", "read:issue,read:user"))
8989
assert.Equal(t, 1, unittest.GetCount(t, &user_model.User{}))
9090
assert.Equal(t, 1, unittest.GetCount(t, &auth_model.AccessToken{}))
9191
accessToken = unittest.AssertExistsAndLoadBean(t, &auth_model.AccessToken{Name: "new-token-name"})
@@ -98,23 +98,38 @@ func TestAdminUserCreate(t *testing.T) {
9898

9999
// using "--access-token-name" without "--access-token"
100100
reset()
101-
err = createUser("u", "--random-password --access-token-name new-token-name")
101+
err = createUser("u", "--random-password", "--access-token-name", "new-token-name")
102102
assert.Equal(t, 0, unittest.GetCount(t, &user_model.User{}))
103103
assert.Equal(t, 0, unittest.GetCount(t, &auth_model.AccessToken{}))
104104
assert.ErrorContains(t, err, "access-token-name and access-token-scopes flags are only valid when access-token flag is set")
105105

106106
// using "--access-token-scopes" without "--access-token"
107107
reset()
108-
err = createUser("u", "--random-password --access-token-scopes read:issue")
108+
err = createUser("u", "--random-password", "--access-token-scopes", "read:issue")
109109
assert.Equal(t, 0, unittest.GetCount(t, &user_model.User{}))
110110
assert.Equal(t, 0, unittest.GetCount(t, &auth_model.AccessToken{}))
111111
assert.ErrorContains(t, err, "access-token-name and access-token-scopes flags are only valid when access-token flag is set")
112112

113113
// empty permission
114114
reset()
115-
err = createUser("u", "--random-password --access-token --access-token-scopes public-only")
115+
err = createUser("u", "--random-password", "--access-token", "--access-token-scopes", "public-only")
116116
assert.Equal(t, 0, unittest.GetCount(t, &user_model.User{}))
117117
assert.Equal(t, 0, unittest.GetCount(t, &auth_model.AccessToken{}))
118118
assert.ErrorContains(t, err, "access token does not have any permission")
119119
})
120+
121+
t.Run("UserFields", func(t *testing.T) {
122+
reset()
123+
assert.NoError(t, createUser("u-FullNameWithSpace", "--random-password", "--fullname", "First O'Middle Last"))
124+
unittest.AssertExistsAndLoadBean(t, &user_model.User{
125+
Name: "u-FullNameWithSpace",
126+
LowerName: "u-fullnamewithspace",
127+
FullName: "First O'Middle Last",
128+
129+
})
130+
131+
assert.NoError(t, createUser("u-FullNameEmpty", "--random-password", "--fullname", ""))
132+
u := unittest.AssertExistsAndLoadBean(t, &user_model.User{LowerName: "u-fullnameempty"})
133+
assert.Empty(t, u.FullName)
134+
})
120135
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ require (
120120
gitlab.com/gitlab-org/api/client-go v0.126.0
121121
golang.org/x/crypto v0.36.0
122122
golang.org/x/image v0.25.0
123-
golang.org/x/net v0.37.0
123+
golang.org/x/net v0.38.0
124124
golang.org/x/oauth2 v0.28.0
125125
golang.org/x/sync v0.12.0
126126
golang.org/x/sys v0.31.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -875,8 +875,8 @@ golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
875875
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
876876
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
877877
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
878-
golang.org/x/net v0.37.0 h1:1zLorHbz+LYj7MQlSf1+2tPIIgibq2eL5xkrGk6f+2c=
879-
golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
878+
golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8=
879+
golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
880880
golang.org/x/oauth2 v0.28.0 h1:CrgCKl8PPAVtLnU3c+EDw6x11699EWlsDeWNWKdIOkc=
881881
golang.org/x/oauth2 v0.28.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8=
882882
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=

models/actions/runner.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"code.gitea.io/gitea/models/shared/types"
1515
user_model "code.gitea.io/gitea/models/user"
1616
"code.gitea.io/gitea/modules/optional"
17+
"code.gitea.io/gitea/modules/setting"
1718
"code.gitea.io/gitea/modules/timeutil"
1819
"code.gitea.io/gitea/modules/translation"
1920
"code.gitea.io/gitea/modules/util"
@@ -123,8 +124,15 @@ func (r *ActionRunner) IsOnline() bool {
123124
return false
124125
}
125126

126-
// Editable checks if the runner is editable by the user
127-
func (r *ActionRunner) Editable(ownerID, repoID int64) bool {
127+
// EditableInContext checks if the runner is editable by the "context" owner/repo
128+
// ownerID == 0 and repoID == 0 means "admin" context, any runner including global runners could be edited
129+
// ownerID == 0 and repoID != 0 means "repo" context, any runner belonging to the given repo could be edited
130+
// ownerID != 0 and repoID == 0 means "owner(org/user)" context, any runner belonging to the given user/org could be edited
131+
// ownerID != 0 and repoID != 0 means "owner" OR "repo" context, legacy behavior, but we should forbid using it
132+
func (r *ActionRunner) EditableInContext(ownerID, repoID int64) bool {
133+
if ownerID != 0 && repoID != 0 {
134+
setting.PanicInDevOrTesting("ownerID and repoID should not be both set")
135+
}
128136
if ownerID == 0 && repoID == 0 {
129137
return true
130138
}
@@ -168,6 +176,12 @@ func init() {
168176
db.RegisterModel(&ActionRunner{})
169177
}
170178

179+
// FindRunnerOptions
180+
// ownerID == 0 and repoID == 0 means any runner including global runners
181+
// repoID != 0 and WithAvailable == false means any runner for the given repo
182+
// repoID != 0 and WithAvailable == true means any runner for the given repo, parent user/org, and global runners
183+
// ownerID != 0 and repoID == 0 and WithAvailable == false means any runner for the given user/org
184+
// ownerID != 0 and repoID == 0 and WithAvailable == true means any runner for the given user/org and global runners
171185
type FindRunnerOptions struct {
172186
db.ListOptions
173187
IDs []int64

models/fixtures/action_runner.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
-
2+
id: 34346
3+
name: runner_to_be_deleted-user
4+
uuid: 3EF231BD-FBB7-4E4B-9602-E6F28363EF18
5+
token_hash: 3EF231BD-FBB7-4E4B-9602-E6F28363EF18
6+
version: "1.0.0"
7+
owner_id: 1
8+
repo_id: 0
9+
description: "This runner is going to be deleted"
10+
agent_labels: '["runner_to_be_deleted","linux"]'
11+
-
12+
id: 34347
13+
name: runner_to_be_deleted-org
14+
uuid: 3EF231BD-FBB7-4E4B-9602-E6F28363EF19
15+
token_hash: 3EF231BD-FBB7-4E4B-9602-E6F28363EF19
16+
version: "1.0.0"
17+
owner_id: 3
18+
repo_id: 0
19+
description: "This runner is going to be deleted"
20+
agent_labels: '["runner_to_be_deleted","linux"]'
21+
-
22+
id: 34348
23+
name: runner_to_be_deleted-repo1
24+
uuid: 3EF231BD-FBB7-4E4B-9602-E6F28363EF20
25+
token_hash: 3EF231BD-FBB7-4E4B-9602-E6F28363EF20
26+
version: "1.0.0"
27+
owner_id: 0
28+
repo_id: 1
29+
description: "This runner is going to be deleted"
30+
agent_labels: '["runner_to_be_deleted","linux"]'
31+
-
32+
id: 34349
33+
name: runner_to_be_deleted
34+
uuid: 3EF231BD-FBB7-4E4B-9602-E6F28363EF17
35+
token_hash: 3EF231BD-FBB7-4E4B-9602-E6F28363EF17
36+
version: "1.0.0"
37+
owner_id: 0
38+
repo_id: 0
39+
description: "This runner is going to be deleted"
40+
agent_labels: '["runner_to_be_deleted","linux"]'

models/packages/package_version.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,7 @@ func (opts *PackageSearchOptions) configureOrderBy(e db.Engine) {
279279
default:
280280
e.Desc("package_version.created_unix")
281281
}
282-
283-
// Sort by id for stable order with duplicates in the other field
284-
e.Asc("package_version.id")
282+
e.Desc("package_version.id") // Sort by id for stable order with duplicates in the other field
285283
}
286284

287285
// SearchVersions gets all versions of packages matching the search options

modules/markup/markdown/markdown.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,15 @@ func (r *GlodmarkRender) highlightingRenderer(w util.BufWriter, c highlighting.C
8686
preClasses += " is-loading"
8787
}
8888

89-
err := r.ctx.RenderInternal.FormatWithSafeAttrs(w, `<pre class="%s">`, preClasses)
90-
if err != nil {
91-
return
92-
}
93-
9489
// include language-x class as part of commonmark spec, "chroma" class is used to highlight the code
9590
// the "display" class is used by "js/markup/math.ts" to render the code element as a block
9691
// the "math.ts" strictly depends on the structure: <pre class="code-block is-loading"><code class="language-math display">...</code></pre>
97-
err = r.ctx.RenderInternal.FormatWithSafeAttrs(w, `<code class="chroma language-%s display">`, languageStr)
92+
err := r.ctx.RenderInternal.FormatWithSafeAttrs(w, `<div class="code-block-container code-overflow-scroll"><pre class="%s"><code class="chroma language-%s display">`, preClasses, languageStr)
9893
if err != nil {
9994
return
10095
}
10196
} else {
102-
_, err := w.WriteString("</code></pre>")
97+
_, err := w.WriteString("</code></pre></div>")
10398
if err != nil {
10499
return
105100
}

modules/structs/repo_actions.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,26 @@ type ActionWorkflowJob struct {
133133
// swagger:strfmt date-time
134134
CompletedAt time.Time `json:"completed_at,omitempty"`
135135
}
136+
137+
// ActionRunnerLabel represents a Runner Label
138+
type ActionRunnerLabel struct {
139+
ID int64 `json:"id"`
140+
Name string `json:"name"`
141+
Type string `json:"type"`
142+
}
143+
144+
// ActionRunner represents a Runner
145+
type ActionRunner struct {
146+
ID int64 `json:"id"`
147+
Name string `json:"name"`
148+
Status string `json:"status"`
149+
Busy bool `json:"busy"`
150+
Ephemeral bool `json:"ephemeral"`
151+
Labels []*ActionRunnerLabel `json:"labels"`
152+
}
153+
154+
// ActionRunnersResponse returns Runners
155+
type ActionRunnersResponse struct {
156+
Entries []*ActionRunner `json:"runners"`
157+
TotalCount int64 `json:"total_count"`
158+
}

options/locale/locale_fr-FR.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ files=Fichiers
117117

118118
error=Erreur
119119
error404=La page que vous essayez d'atteindre <strong>n'existe pas</strong> ou <strong>vous n'êtes pas autorisé</strong> à la voir.
120+
error503=Le serveur n’a pas pu répondre à votre requête. Veuillez réessayer plus tard.
120121
go_back=Retour
121122
invalid_data=Données invalides : %v
122123

0 commit comments

Comments
 (0)