Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
zjjhot committed Aug 22, 2023
2 parents 0202a36 + bd8a253 commit b29d031
Show file tree
Hide file tree
Showing 21 changed files with 356 additions and 231 deletions.
14 changes: 13 additions & 1 deletion modules/structs/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,23 @@ package structs

import "time"

// User represents a secret
// Secret represents a secret
// swagger:model
type Secret struct {
// the secret's name
Name string `json:"name"`
// swagger:strfmt date-time
Created time.Time `json:"created_at"`
}

// CreateSecretOption options when creating secret
// swagger:model
type CreateSecretOption struct {
// Name of the secret to create
//
// required: true
// unique: true
Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(100)"`
// Data of the secret to create
Data string `json:"data" binding:"Required"`
}
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3503,6 +3503,7 @@ workflow.disable = Disable Workflow
workflow.disable_success = Workflow '%s' disabled successfully.
workflow.enable = Enable Workflow
workflow.enable_success = Workflow '%s' enabled successfully.
workflow.disabled = Workflow is disabled.
need_approval_desc = Need approval to run workflows for fork pull request.
Expand Down
1 change: 1 addition & 0 deletions routers/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,7 @@ func Routes() *web.Route {
})
m.Group("/actions/secrets", func() {
m.Get("", reqToken(), reqOrgOwnership(), org.ListActionsSecrets)
m.Post("", reqToken(), reqOrgOwnership(), bind(api.CreateSecretOption{}), org.CreateOrgSecret)
})
m.Group("/public_members", func() {
m.Get("", org.ListPublicMembers)
Expand Down
51 changes: 47 additions & 4 deletions routers/api/v1/org/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ package org
import (
"net/http"

"code.gitea.io/gitea/models/secret"
secret_model "code.gitea.io/gitea/models/secret"
"code.gitea.io/gitea/modules/context"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/routers/api/v1/utils"
"code.gitea.io/gitea/routers/web/shared/actions"
"code.gitea.io/gitea/services/convert"
)

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

// listActionsSecrets list an organization's actions secrets
func listActionsSecrets(ctx *context.APIContext) {
opts := &secret.FindSecretsOptions{
opts := &secret_model.FindSecretsOptions{
OwnerID: ctx.Org.Organization.ID,
ListOptions: utils.GetListOptions(ctx),
}

count, err := secret.CountSecrets(ctx, opts)
count, err := secret_model.CountSecrets(ctx, opts)
if err != nil {
ctx.InternalServerError(err)
return
}

secrets, err := secret.FindSecrets(ctx, *opts)
secrets, err := secret_model.FindSecrets(ctx, *opts)
if err != nil {
ctx.InternalServerError(err)
return
Expand All @@ -70,3 +73,43 @@ func listActionsSecrets(ctx *context.APIContext) {
ctx.SetTotalCountHeader(count)
ctx.JSON(http.StatusOK, apiSecrets)
}

// CreateOrgSecret create one secret of the organization
func CreateOrgSecret(ctx *context.APIContext) {
// swagger:operation POST /orgs/{org}/actions/secrets organization createOrgSecret
// ---
// summary: Create a secret in an organization
// consumes:
// - application/json
// produces:
// - application/json
// parameters:
// - name: org
// in: path
// description: name of organization
// type: string
// required: true
// - name: body
// in: body
// schema:
// "$ref": "#/definitions/CreateSecretOption"
// responses:
// "201":
// "$ref": "#/responses/Secret"
// "400":
// "$ref": "#/responses/error"
// "404":
// "$ref": "#/responses/notFound"
// "403":
// "$ref": "#/responses/forbidden"
opt := web.GetForm(ctx).(*api.CreateSecretOption)
s, err := secret_model.InsertEncryptedSecret(
ctx, ctx.Org.Organization.ID, 0, opt.Name, actions.ReserveLineBreakForTextarea(opt.Data),
)
if err != nil {
ctx.Error(http.StatusInternalServerError, "InsertEncryptedSecret", err)
return
}

ctx.JSON(http.StatusCreated, convert.ToSecret(s))
}
7 changes: 7 additions & 0 deletions routers/api/v1/swagger/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ type swaggerResponseSecretList struct {
// in:body
Body []api.Secret `json:"body"`
}

// Secret
// swagger:response Secret
type swaggerResponseSecret struct {
// in:body
Body api.Secret `json:"body"`
}
3 changes: 3 additions & 0 deletions routers/api/v1/swagger/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,7 @@ type swaggerParameterBodies struct {

// in:body
UpdateRepoAvatarOptions api.UpdateRepoAvatarOption

// in:body
CreateSecretOption api.CreateSecretOption
}
28 changes: 16 additions & 12 deletions routers/web/repo/actions/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,31 +259,35 @@ func ViewPost(ctx *context_module.Context) {
ctx.JSON(http.StatusOK, resp)
}

func RerunOne(ctx *context_module.Context) {
// Rerun will rerun jobs in the given run
// jobIndex = 0 means rerun all jobs
func Rerun(ctx *context_module.Context) {
runIndex := ctx.ParamsInt64("run")
jobIndex := ctx.ParamsInt64("job")

job, _ := getRunJobs(ctx, runIndex, jobIndex)
if ctx.Written() {
run, err := actions_model.GetRunByIndex(ctx, ctx.Repo.Repository.ID, runIndex)
if err != nil {
ctx.Error(http.StatusInternalServerError, err.Error())
return
}

if err := rerunJob(ctx, job); err != nil {
ctx.Error(http.StatusInternalServerError, err.Error())
// can not rerun job when workflow is disabled
cfgUnit := ctx.Repo.Repository.MustGetUnit(ctx, unit.TypeActions)
cfg := cfgUnit.ActionsConfig()
if cfg.IsWorkflowDisabled(run.WorkflowID) {
ctx.JSONError(ctx.Locale.Tr("actions.workflow.disabled"))
return
}

ctx.JSON(http.StatusOK, struct{}{})
}

func RerunAll(ctx *context_module.Context) {
runIndex := ctx.ParamsInt64("run")

_, jobs := getRunJobs(ctx, runIndex, 0)
job, jobs := getRunJobs(ctx, runIndex, jobIndex)
if ctx.Written() {
return
}

if jobIndex != 0 {
jobs = []*actions_model.ActionRunJob{job}
}

for _, j := range jobs {
if err := rerunJob(ctx, j); err != nil {
ctx.Error(http.StatusInternalServerError, err.Error())
Expand Down
4 changes: 2 additions & 2 deletions routers/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -1211,14 +1211,14 @@ func registerRoutes(m *web.Route) {
m.Combo("").
Get(actions.View).
Post(web.Bind(actions.ViewRequest{}), actions.ViewPost)
m.Post("/rerun", reqRepoActionsWriter, actions.RerunOne)
m.Post("/rerun", reqRepoActionsWriter, actions.Rerun)
m.Get("/logs", actions.Logs)
})
m.Post("/cancel", reqRepoActionsWriter, actions.Cancel)
m.Post("/approve", reqRepoActionsWriter, actions.Approve)
m.Post("/artifacts", actions.ArtifactsView)
m.Get("/artifacts/{artifact_name}", actions.ArtifactsDownloadView)
m.Post("/rerun", reqRepoActionsWriter, actions.RerunAll)
m.Post("/rerun", reqRepoActionsWriter, actions.Rerun)
})
}, reqRepoActionsReader, actions.MustEnableActions)

Expand Down
18 changes: 18 additions & 0 deletions services/convert/secret.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package convert

import (
secret_model "code.gitea.io/gitea/models/secret"
api "code.gitea.io/gitea/modules/structs"
)

// ToSecret converts Secret to API format
func ToSecret(secret *secret_model.Secret) *api.Secret {
result := &api.Secret{
Name: secret.Name,
}

return result
}
2 changes: 2 additions & 0 deletions templates/base/head_script.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ If you are customizing Gitea, please do not change this file.
If you introduce mistakes in it, Gitea JavaScript code wouldn't run correctly.
*/}}
<script>
{{/* before our JS code gets loaded, use arrays to store errors, then the arrays will be switched to our error handler later */}}
window.addEventListener('error', function(e) {window._globalHandlerErrors=window._globalHandlerErrors||[]; window._globalHandlerErrors.push(e);});
window.addEventListener('unhandledrejection', function(e) {window._globalHandlerErrors=window._globalHandlerErrors||[]; window._globalHandlerErrors.push(e);});
window.config = {
appUrl: '{{AppUrl}}',
appSubUrl: '{{AppSubUrl}}',
Expand Down
88 changes: 88 additions & 0 deletions templates/devtest/flex-list.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{{template "base/head" .}}
<link rel="stylesheet" href="{{AssetUrlPrefix}}/css/devtest.css?v={{AssetVersion}}">
<div class="page-content devtest ui container">
<div>
<h1>Flex List</h1>
<div class="flex-list">
<div class="flex-item">
<div class="flex-item-leading">
{{svg "octicon-info" 32}}
</div>
<div class="flex-item-main">
<div class="flex-item-title">
Flex Item
<span class="ui basic label">
with label
</span>
</div>
<div class="flex-item-body">
consists of leading/main/trailing part
</div>
<div class="flex-item-body">
main part contains title and (multiple) body lines
</div>
</div>
<div class="flex-item-trailing">
<button class="ui tiny red button">
{{svg "octicon-warning" 14}} CJK文本测试
</button>
<button class="ui tiny green button">
{{svg "octicon-info" 14}} Button
</button>
<button class="ui tiny green button">
Button with long text
</button>
</div>
</div>

<div class="flex-item">
<div class="flex-item-leading">
{{svg "octicon-info" 32}}
</div>
<div class="flex-item-main">
<div class="flex-item-title">
Very loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong title
</div>
<div class="flex-item-body">
consists of leading/main/trailing part
</div>
<div class="flex-item-body">
Very loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong content
</div>
</div>
<div class="flex-item-trailing">
<button class="ui tiny red button">
{{svg "octicon-warning" 12}} CJK文本测试 <!-- single CJK text test, it shouldn't be horizontal -->
</button>
</div>
</div>

<div class="flex-item">
<div class="flex-item-leading">
{{svg "octicon-repo" 32}}
</div>
<div class="flex-item-main">
<div class="flex-item-header">
<div class="flex-item-title">
<a class="text primary" href="{{$.Link}}">
gitea-org / gitea
</a>
<span data-tooltip-content="{{$.locale.Tr "repo.fork"}}">{{svg "octicon-repo-forked"}}</span>
</div>
<div class="flex-item-trailing">
<a class="muted" href="{{$.Link}}">
<span class="flex-text-inline"><i class="color-icon gt-mr-3" style="background-color: aqua"></i>Go</span>
</a>
<a class="text grey flex-text-inline" href="{{$.Link}}">{{svg "octicon-star" 16}}45000</a>
<a class="text grey flex-text-inline" href="{{$.Link}}">{{svg "octicon-git-branch" 16}}1234</a>
</div>
</div>
<div class="flex-item-body">
when inside header, the trailing part will wrap below the title
</div>
</div>
</div>
</div>
</div>
</div>
{{template "base/footer" .}}
Loading

0 comments on commit b29d031

Please sign in to comment.