Skip to content

Commit 7771ad9

Browse files
committed
Add migration for secrets and variables (#33484)
1 parent 2486df9 commit 7771ad9

File tree

5 files changed

+53
-2
lines changed

5 files changed

+53
-2
lines changed

models/migrations/migrations.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ func prepareMigrationTasks() []*migration {
373373

374374
// Gitea 1.23.0-rc0 ends at migration ID number 311 (database version 312)
375375
newMigration(312, "Add DeleteBranchAfterMerge to AutoMerge", v1_24.AddDeleteBranchAfterMergeForAutoMerge),
376+
newMigration(313, "Add description for secrets and variables", v1_24.AddDescriptionForSecretsAndVariables),
376377
}
377378
return preparedMigrations
378379
}

models/migrations/v1_24/v313.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2024 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_24 //nolint
5+
6+
import (
7+
"xorm.io/xorm"
8+
)
9+
10+
func AddDescriptionForSecretsAndVariables(x *xorm.Engine) error {
11+
type Secret struct {
12+
Description string `xorm:"TEXT"`
13+
}
14+
15+
type ActionVariable struct {
16+
Description string `xorm:"TEXT"`
17+
}
18+
19+
return x.Sync(new(Secret), new(ActionVariable))
20+
}

templates/shared/secrets/add_list.tmpl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@
2323
{{.Name}}
2424
</div>
2525
<div class="flex-item-body">
26-
{{.Description}}
26+
{{if .Description}} {{.Description}} {{else}} - {{end}}
2727
</div>
28+
<div class="flex-item-body">
29+
******
30+
</div>
2831
</div>
2932
<div class="flex-item-trailing">
3033
<span class="color-text-light-2">

templates/shared/variables/variable_list.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
{{.Name}}
2626
</div>
2727
<div class="flex-item-body">
28-
{{.Description}}
28+
{{if .Description}} {{.Description}} {{else}} - {{end}}
2929
</div>
3030
<div class="flex-item-body">
3131
{{.Data}}

tests/integration/api_repo_secrets_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,33 @@ func TestAPIRepoSecrets(t *testing.T) {
7373
}
7474
})
7575

76+
t.Run("CreateWithDescription", func(t *testing.T) {
77+
cases := []struct {
78+
Name string
79+
Description string
80+
ExpectedStatus int
81+
}{
82+
{
83+
Name: "no_description",
84+
Description: "",
85+
ExpectedStatus: http.StatusCreated,
86+
},
87+
{
88+
Name: "description",
89+
Description: "some description",
90+
ExpectedStatus: http.StatusCreated,
91+
},
92+
}
93+
94+
for _, c := range cases {
95+
req := NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/actions/secrets/%s", repo.FullName(), c.Name), api.CreateOrUpdateSecretOption{
96+
Data: "data",
97+
Description: c.Description,
98+
}).AddTokenAuth(token)
99+
MakeRequest(t, req, c.ExpectedStatus)
100+
}
101+
})
102+
76103
t.Run("Update", func(t *testing.T) {
77104
name := "update_secret"
78105
url := fmt.Sprintf("/api/v1/repos/%s/actions/secrets/%s", repo.FullName(), name)

0 commit comments

Comments
 (0)