Skip to content

Commit b29d031

Browse files
committed
Merge remote-tracking branch 'upstream/main'
* upstream/main: Improve show role (go-gitea#26621) Improve some flex layouts (go-gitea#26649) feat: implement organization secret creation API (go-gitea#26566) Check disabled workflow when rerun jobs (go-gitea#26535)
2 parents 0202a36 + bd8a253 commit b29d031

File tree

21 files changed

+356
-231
lines changed

21 files changed

+356
-231
lines changed

modules/structs/secret.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,23 @@ package structs
55

66
import "time"
77

8-
// User represents a secret
8+
// Secret represents a secret
99
// swagger:model
1010
type Secret struct {
1111
// the secret's name
1212
Name string `json:"name"`
1313
// swagger:strfmt date-time
1414
Created time.Time `json:"created_at"`
1515
}
16+
17+
// CreateSecretOption options when creating secret
18+
// swagger:model
19+
type CreateSecretOption struct {
20+
// Name of the secret to create
21+
//
22+
// required: true
23+
// unique: true
24+
Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(100)"`
25+
// Data of the secret to create
26+
Data string `json:"data" binding:"Required"`
27+
}

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3503,6 +3503,7 @@ workflow.disable = Disable Workflow
35033503
workflow.disable_success = Workflow '%s' disabled successfully.
35043504
workflow.enable = Enable Workflow
35053505
workflow.enable_success = Workflow '%s' enabled successfully.
3506+
workflow.disabled = Workflow is disabled.
35063507
35073508
need_approval_desc = Need approval to run workflows for fork pull request.
35083509

routers/api/v1/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,6 +1300,7 @@ func Routes() *web.Route {
13001300
})
13011301
m.Group("/actions/secrets", func() {
13021302
m.Get("", reqToken(), reqOrgOwnership(), org.ListActionsSecrets)
1303+
m.Post("", reqToken(), reqOrgOwnership(), bind(api.CreateSecretOption{}), org.CreateOrgSecret)
13031304
})
13041305
m.Group("/public_members", func() {
13051306
m.Get("", org.ListPublicMembers)

routers/api/v1/org/action.go

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ package org
66
import (
77
"net/http"
88

9-
"code.gitea.io/gitea/models/secret"
9+
secret_model "code.gitea.io/gitea/models/secret"
1010
"code.gitea.io/gitea/modules/context"
1111
api "code.gitea.io/gitea/modules/structs"
12+
"code.gitea.io/gitea/modules/web"
1213
"code.gitea.io/gitea/routers/api/v1/utils"
14+
"code.gitea.io/gitea/routers/web/shared/actions"
15+
"code.gitea.io/gitea/services/convert"
1316
)
1417

1518
// ListActionsSecrets list an organization's actions secrets
@@ -42,18 +45,18 @@ func ListActionsSecrets(ctx *context.APIContext) {
4245

4346
// listActionsSecrets list an organization's actions secrets
4447
func listActionsSecrets(ctx *context.APIContext) {
45-
opts := &secret.FindSecretsOptions{
48+
opts := &secret_model.FindSecretsOptions{
4649
OwnerID: ctx.Org.Organization.ID,
4750
ListOptions: utils.GetListOptions(ctx),
4851
}
4952

50-
count, err := secret.CountSecrets(ctx, opts)
53+
count, err := secret_model.CountSecrets(ctx, opts)
5154
if err != nil {
5255
ctx.InternalServerError(err)
5356
return
5457
}
5558

56-
secrets, err := secret.FindSecrets(ctx, *opts)
59+
secrets, err := secret_model.FindSecrets(ctx, *opts)
5760
if err != nil {
5861
ctx.InternalServerError(err)
5962
return
@@ -70,3 +73,43 @@ func listActionsSecrets(ctx *context.APIContext) {
7073
ctx.SetTotalCountHeader(count)
7174
ctx.JSON(http.StatusOK, apiSecrets)
7275
}
76+
77+
// CreateOrgSecret create one secret of the organization
78+
func CreateOrgSecret(ctx *context.APIContext) {
79+
// swagger:operation POST /orgs/{org}/actions/secrets organization createOrgSecret
80+
// ---
81+
// summary: Create a secret in an organization
82+
// consumes:
83+
// - application/json
84+
// produces:
85+
// - application/json
86+
// parameters:
87+
// - name: org
88+
// in: path
89+
// description: name of organization
90+
// type: string
91+
// required: true
92+
// - name: body
93+
// in: body
94+
// schema:
95+
// "$ref": "#/definitions/CreateSecretOption"
96+
// responses:
97+
// "201":
98+
// "$ref": "#/responses/Secret"
99+
// "400":
100+
// "$ref": "#/responses/error"
101+
// "404":
102+
// "$ref": "#/responses/notFound"
103+
// "403":
104+
// "$ref": "#/responses/forbidden"
105+
opt := web.GetForm(ctx).(*api.CreateSecretOption)
106+
s, err := secret_model.InsertEncryptedSecret(
107+
ctx, ctx.Org.Organization.ID, 0, opt.Name, actions.ReserveLineBreakForTextarea(opt.Data),
108+
)
109+
if err != nil {
110+
ctx.Error(http.StatusInternalServerError, "InsertEncryptedSecret", err)
111+
return
112+
}
113+
114+
ctx.JSON(http.StatusCreated, convert.ToSecret(s))
115+
}

routers/api/v1/swagger/action.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,10 @@ type swaggerResponseSecretList struct {
1111
// in:body
1212
Body []api.Secret `json:"body"`
1313
}
14+
15+
// Secret
16+
// swagger:response Secret
17+
type swaggerResponseSecret struct {
18+
// in:body
19+
Body api.Secret `json:"body"`
20+
}

routers/api/v1/swagger/options.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,7 @@ type swaggerParameterBodies struct {
187187

188188
// in:body
189189
UpdateRepoAvatarOptions api.UpdateRepoAvatarOption
190+
191+
// in:body
192+
CreateSecretOption api.CreateSecretOption
190193
}

routers/web/repo/actions/view.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -259,31 +259,35 @@ func ViewPost(ctx *context_module.Context) {
259259
ctx.JSON(http.StatusOK, resp)
260260
}
261261

262-
func RerunOne(ctx *context_module.Context) {
262+
// Rerun will rerun jobs in the given run
263+
// jobIndex = 0 means rerun all jobs
264+
func Rerun(ctx *context_module.Context) {
263265
runIndex := ctx.ParamsInt64("run")
264266
jobIndex := ctx.ParamsInt64("job")
265267

266-
job, _ := getRunJobs(ctx, runIndex, jobIndex)
267-
if ctx.Written() {
268+
run, err := actions_model.GetRunByIndex(ctx, ctx.Repo.Repository.ID, runIndex)
269+
if err != nil {
270+
ctx.Error(http.StatusInternalServerError, err.Error())
268271
return
269272
}
270273

271-
if err := rerunJob(ctx, job); err != nil {
272-
ctx.Error(http.StatusInternalServerError, err.Error())
274+
// can not rerun job when workflow is disabled
275+
cfgUnit := ctx.Repo.Repository.MustGetUnit(ctx, unit.TypeActions)
276+
cfg := cfgUnit.ActionsConfig()
277+
if cfg.IsWorkflowDisabled(run.WorkflowID) {
278+
ctx.JSONError(ctx.Locale.Tr("actions.workflow.disabled"))
273279
return
274280
}
275281

276-
ctx.JSON(http.StatusOK, struct{}{})
277-
}
278-
279-
func RerunAll(ctx *context_module.Context) {
280-
runIndex := ctx.ParamsInt64("run")
281-
282-
_, jobs := getRunJobs(ctx, runIndex, 0)
282+
job, jobs := getRunJobs(ctx, runIndex, jobIndex)
283283
if ctx.Written() {
284284
return
285285
}
286286

287+
if jobIndex != 0 {
288+
jobs = []*actions_model.ActionRunJob{job}
289+
}
290+
287291
for _, j := range jobs {
288292
if err := rerunJob(ctx, j); err != nil {
289293
ctx.Error(http.StatusInternalServerError, err.Error())

routers/web/web.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,14 +1211,14 @@ func registerRoutes(m *web.Route) {
12111211
m.Combo("").
12121212
Get(actions.View).
12131213
Post(web.Bind(actions.ViewRequest{}), actions.ViewPost)
1214-
m.Post("/rerun", reqRepoActionsWriter, actions.RerunOne)
1214+
m.Post("/rerun", reqRepoActionsWriter, actions.Rerun)
12151215
m.Get("/logs", actions.Logs)
12161216
})
12171217
m.Post("/cancel", reqRepoActionsWriter, actions.Cancel)
12181218
m.Post("/approve", reqRepoActionsWriter, actions.Approve)
12191219
m.Post("/artifacts", actions.ArtifactsView)
12201220
m.Get("/artifacts/{artifact_name}", actions.ArtifactsDownloadView)
1221-
m.Post("/rerun", reqRepoActionsWriter, actions.RerunAll)
1221+
m.Post("/rerun", reqRepoActionsWriter, actions.Rerun)
12221222
})
12231223
}, reqRepoActionsReader, actions.MustEnableActions)
12241224

services/convert/secret.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package convert
5+
6+
import (
7+
secret_model "code.gitea.io/gitea/models/secret"
8+
api "code.gitea.io/gitea/modules/structs"
9+
)
10+
11+
// ToSecret converts Secret to API format
12+
func ToSecret(secret *secret_model.Secret) *api.Secret {
13+
result := &api.Secret{
14+
Name: secret.Name,
15+
}
16+
17+
return result
18+
}

templates/base/head_script.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ If you are customizing Gitea, please do not change this file.
44
If you introduce mistakes in it, Gitea JavaScript code wouldn't run correctly.
55
*/}}
66
<script>
7+
{{/* before our JS code gets loaded, use arrays to store errors, then the arrays will be switched to our error handler later */}}
78
window.addEventListener('error', function(e) {window._globalHandlerErrors=window._globalHandlerErrors||[]; window._globalHandlerErrors.push(e);});
9+
window.addEventListener('unhandledrejection', function(e) {window._globalHandlerErrors=window._globalHandlerErrors||[]; window._globalHandlerErrors.push(e);});
810
window.config = {
911
appUrl: '{{AppUrl}}',
1012
appSubUrl: '{{AppSubUrl}}',

templates/devtest/flex-list.tmpl

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
{{template "base/head" .}}
2+
<link rel="stylesheet" href="{{AssetUrlPrefix}}/css/devtest.css?v={{AssetVersion}}">
3+
<div class="page-content devtest ui container">
4+
<div>
5+
<h1>Flex List</h1>
6+
<div class="flex-list">
7+
<div class="flex-item">
8+
<div class="flex-item-leading">
9+
{{svg "octicon-info" 32}}
10+
</div>
11+
<div class="flex-item-main">
12+
<div class="flex-item-title">
13+
Flex Item
14+
<span class="ui basic label">
15+
with label
16+
</span>
17+
</div>
18+
<div class="flex-item-body">
19+
consists of leading/main/trailing part
20+
</div>
21+
<div class="flex-item-body">
22+
main part contains title and (multiple) body lines
23+
</div>
24+
</div>
25+
<div class="flex-item-trailing">
26+
<button class="ui tiny red button">
27+
{{svg "octicon-warning" 14}} CJK文本测试
28+
</button>
29+
<button class="ui tiny green button">
30+
{{svg "octicon-info" 14}} Button
31+
</button>
32+
<button class="ui tiny green button">
33+
Button with long text
34+
</button>
35+
</div>
36+
</div>
37+
38+
<div class="flex-item">
39+
<div class="flex-item-leading">
40+
{{svg "octicon-info" 32}}
41+
</div>
42+
<div class="flex-item-main">
43+
<div class="flex-item-title">
44+
Very loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong title
45+
</div>
46+
<div class="flex-item-body">
47+
consists of leading/main/trailing part
48+
</div>
49+
<div class="flex-item-body">
50+
Very loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong content
51+
</div>
52+
</div>
53+
<div class="flex-item-trailing">
54+
<button class="ui tiny red button">
55+
{{svg "octicon-warning" 12}} CJK文本测试 <!-- single CJK text test, it shouldn't be horizontal -->
56+
</button>
57+
</div>
58+
</div>
59+
60+
<div class="flex-item">
61+
<div class="flex-item-leading">
62+
{{svg "octicon-repo" 32}}
63+
</div>
64+
<div class="flex-item-main">
65+
<div class="flex-item-header">
66+
<div class="flex-item-title">
67+
<a class="text primary" href="{{$.Link}}">
68+
gitea-org / gitea
69+
</a>
70+
<span data-tooltip-content="{{$.locale.Tr "repo.fork"}}">{{svg "octicon-repo-forked"}}</span>
71+
</div>
72+
<div class="flex-item-trailing">
73+
<a class="muted" href="{{$.Link}}">
74+
<span class="flex-text-inline"><i class="color-icon gt-mr-3" style="background-color: aqua"></i>Go</span>
75+
</a>
76+
<a class="text grey flex-text-inline" href="{{$.Link}}">{{svg "octicon-star" 16}}45000</a>
77+
<a class="text grey flex-text-inline" href="{{$.Link}}">{{svg "octicon-git-branch" 16}}1234</a>
78+
</div>
79+
</div>
80+
<div class="flex-item-body">
81+
when inside header, the trailing part will wrap below the title
82+
</div>
83+
</div>
84+
</div>
85+
</div>
86+
</div>
87+
</div>
88+
{{template "base/footer" .}}

0 commit comments

Comments
 (0)