mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
2978 files. The fork is 2026-07-15 (rebrand: gitea.dev -> github.com/hanzoai/git), so 2026 is the year, and "Copyright 2026 Hanzo AI, Inc." was already the form used by the handful of files that had ours. Shape is now: // Copyright 2026 Hanzo AI, Inc. All rights reserved. // Copyright 2015 The Gogs Authors. All rights reserved. // Copyright 2019 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT Ours on top, theirs retained verbatim. Retained because MIT requires it, and separately because they are true — those authors did write that code. Not renamed to "The Git Authors": Git is a different project under a different license, and putting its name here would attribute this code to people who have nothing to do with it. Adding our line is the fix; overwriting theirs would have been both a licence violation and a false statement. gofmt still reports import-order drift in some of these files. It predates this change (verified against a stash) and is left alone rather than burying a one-line-per-file legal change under 3000 files of unrelated reordering. Build clean. Co-authored-by: Hanzo Dev <[email protected]>
128 lines
3.0 KiB
Go
128 lines
3.0 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package setting
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
|
|
"github.com/hanzoai/git/modules/setting"
|
|
"github.com/hanzoai/git/modules/templates"
|
|
shared "github.com/hanzoai/git/routers/web/shared/secrets"
|
|
shared_user "github.com/hanzoai/git/routers/web/shared/user"
|
|
"github.com/hanzoai/git/services/context"
|
|
)
|
|
|
|
const (
|
|
// TODO: Separate secrets from runners when layout is ready
|
|
tplRepoSecrets templates.TplName = "repo/settings/actions"
|
|
tplOrgSecrets templates.TplName = "org/settings/actions"
|
|
tplUserSecrets templates.TplName = "user/settings/actions"
|
|
)
|
|
|
|
type secretsCtx struct {
|
|
OwnerID int64
|
|
RepoID int64
|
|
IsRepo bool
|
|
IsOrg bool
|
|
IsUser bool
|
|
SecretsTemplate templates.TplName
|
|
RedirectLink string
|
|
}
|
|
|
|
func getSecretsCtx(ctx *context.Context) (*secretsCtx, error) {
|
|
if ctx.Data["PageIsRepoSettings"] == true {
|
|
return &secretsCtx{
|
|
OwnerID: 0,
|
|
RepoID: ctx.Repo.Repository.ID,
|
|
IsRepo: true,
|
|
SecretsTemplate: tplRepoSecrets,
|
|
RedirectLink: ctx.Repo.RepoLink + "/settings/actions/secrets",
|
|
}, nil
|
|
}
|
|
|
|
if ctx.Data["PageIsOrgSettings"] == true {
|
|
if _, err := shared_user.RenderUserOrgHeader(ctx); err != nil {
|
|
ctx.ServerError("RenderUserOrgHeader", err)
|
|
return nil, nil //nolint:nilnil // error is already handled by ctx.ServerError
|
|
}
|
|
return &secretsCtx{
|
|
OwnerID: ctx.ContextUser.ID,
|
|
RepoID: 0,
|
|
IsOrg: true,
|
|
SecretsTemplate: tplOrgSecrets,
|
|
RedirectLink: ctx.Org.OrgLink + "/settings/actions/secrets",
|
|
}, nil
|
|
}
|
|
|
|
if ctx.Data["PageIsUserSettings"] == true {
|
|
return &secretsCtx{
|
|
OwnerID: ctx.Doer.ID,
|
|
RepoID: 0,
|
|
IsUser: true,
|
|
SecretsTemplate: tplUserSecrets,
|
|
RedirectLink: setting.AppSubURL + "/user/settings/actions/secrets",
|
|
}, nil
|
|
}
|
|
|
|
return nil, errors.New("unable to set Secrets context")
|
|
}
|
|
|
|
func Secrets(ctx *context.Context) {
|
|
ctx.Data["Title"] = ctx.Tr("actions.actions")
|
|
ctx.Data["PageType"] = "secrets"
|
|
ctx.Data["PageIsSharedSettingsSecrets"] = true
|
|
|
|
sCtx, err := getSecretsCtx(ctx)
|
|
if err != nil {
|
|
ctx.ServerError("getSecretsCtx", err)
|
|
return
|
|
}
|
|
|
|
if sCtx.IsRepo {
|
|
ctx.Data["DisableSSH"] = setting.SSH.Disabled
|
|
}
|
|
|
|
shared.SetSecretsContext(ctx, sCtx.OwnerID, sCtx.RepoID)
|
|
if ctx.Written() {
|
|
return
|
|
}
|
|
ctx.HTML(http.StatusOK, sCtx.SecretsTemplate)
|
|
}
|
|
|
|
func SecretsPost(ctx *context.Context) {
|
|
sCtx, err := getSecretsCtx(ctx)
|
|
if err != nil {
|
|
ctx.ServerError("getSecretsCtx", err)
|
|
return
|
|
}
|
|
|
|
if ctx.HasError() {
|
|
ctx.JSONError(ctx.GetErrMsg())
|
|
return
|
|
}
|
|
|
|
shared.PerformSecretsPost(
|
|
ctx,
|
|
sCtx.OwnerID,
|
|
sCtx.RepoID,
|
|
sCtx.RedirectLink,
|
|
)
|
|
}
|
|
|
|
func SecretsDelete(ctx *context.Context) {
|
|
sCtx, err := getSecretsCtx(ctx)
|
|
if err != nil {
|
|
ctx.ServerError("getSecretsCtx", err)
|
|
return
|
|
}
|
|
shared.PerformSecretsDelete(
|
|
ctx,
|
|
sCtx.OwnerID,
|
|
sCtx.RepoID,
|
|
sCtx.RedirectLink,
|
|
)
|
|
}
|