Skip to content

Commit 2197282

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: feat(api): enhance Actions Secrets Management API for repository (go-gitea#30656) Fix code search input for different views (go-gitea#30678) Fix incorrect object id hash function (go-gitea#30708) Add route handler info for debugging purpose (go-gitea#30705) Bump htmx version to 1.9.12 (go-gitea#30711)
2 parents a31d1b3 + 852547d commit 2197282

File tree

20 files changed

+442
-320
lines changed

20 files changed

+442
-320
lines changed

modules/git/object_format.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ type ObjectFormat interface {
3333
ComputeHash(t ObjectType, content []byte) ObjectID
3434
}
3535

36-
/* SHA1 Type */
3736
type Sha1ObjectFormatImpl struct{}
3837

3938
var (
@@ -70,14 +69,10 @@ func (h Sha1ObjectFormatImpl) ComputeHash(t ObjectType, content []byte) ObjectID
7069
_, _ = hasher.Write([]byte(" "))
7170
_, _ = hasher.Write([]byte(strconv.FormatInt(int64(len(content)), 10)))
7271
_, _ = hasher.Write([]byte{0})
73-
74-
// HashSum generates a SHA1 for the provided hash
75-
var sha1 Sha1Hash
76-
copy(sha1[:], hasher.Sum(nil))
77-
return &sha1
72+
_, _ = hasher.Write(content)
73+
return h.MustID(hasher.Sum(nil))
7874
}
7975

80-
/* SHA256 Type */
8176
type Sha256ObjectFormatImpl struct{}
8277

8378
var (
@@ -116,11 +111,8 @@ func (h Sha256ObjectFormatImpl) ComputeHash(t ObjectType, content []byte) Object
116111
_, _ = hasher.Write([]byte(" "))
117112
_, _ = hasher.Write([]byte(strconv.FormatInt(int64(len(content)), 10)))
118113
_, _ = hasher.Write([]byte{0})
119-
120-
// HashSum generates a SHA256 for the provided hash
121-
var sha256 Sha1Hash
122-
copy(sha256[:], hasher.Sum(nil))
123-
return &sha256
114+
_, _ = hasher.Write(content)
115+
return h.MustID(hasher.Sum(nil))
124116
}
125117

126118
var (

modules/git/object_id.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ type ObjectID interface {
1616
Type() ObjectFormat
1717
}
1818

19-
/* SHA1 */
2019
type Sha1Hash [20]byte
2120

2221
func (h *Sha1Hash) String() string {
@@ -40,7 +39,6 @@ func MustIDFromString(hexHash string) ObjectID {
4039
return id
4140
}
4241

43-
/* SHA256 */
4442
type Sha256Hash [32]byte
4543

4644
func (h *Sha256Hash) String() string {
@@ -54,7 +52,6 @@ func (h *Sha256Hash) IsZero() bool {
5452
func (h *Sha256Hash) RawValue() []byte { return h[:] }
5553
func (*Sha256Hash) Type() ObjectFormat { return Sha256ObjectFormat }
5654

57-
/* utility */
5855
func NewIDFromString(hexHash string) (ObjectID, error) {
5956
var theObjectFormat ObjectFormat
6057
for _, objectFormat := range SupportedObjectFormats {

modules/git/object_id_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,8 @@ func TestIsValidSHAPattern(t *testing.T) {
1818
assert.False(t, h.IsValid("abc"))
1919
assert.False(t, h.IsValid("123g"))
2020
assert.False(t, h.IsValid("some random text"))
21+
assert.Equal(t, "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", ComputeBlobHash(Sha1ObjectFormat, nil).String())
22+
assert.Equal(t, "2e65efe2a145dda7ee51d1741299f848e5bf752e", ComputeBlobHash(Sha1ObjectFormat, []byte("a")).String())
23+
assert.Equal(t, "473a0f4c3be8a93681a267e3b1e9a7dcda1185436fe141f7749120a303721813", ComputeBlobHash(Sha256ObjectFormat, nil).String())
24+
assert.Equal(t, "eb337bcee2061c5313c9a1392116b6c76039e9e30d71467ae359b36277e17dc7", ComputeBlobHash(Sha256ObjectFormat, []byte("a")).String())
2125
}

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"esbuild-loader": "4.1.0",
2828
"escape-goat": "4.0.0",
2929
"fast-glob": "3.3.2",
30-
"htmx.org": "1.9.11",
30+
"htmx.org": "1.9.12",
3131
"idiomorph": "0.3.0",
3232
"jquery": "3.7.1",
3333
"katex": "0.16.10",

routers/api/v1/api.go

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ import (
9393
"code.gitea.io/gitea/routers/api/v1/settings"
9494
"code.gitea.io/gitea/routers/api/v1/user"
9595
"code.gitea.io/gitea/routers/common"
96+
"code.gitea.io/gitea/services/actions"
9697
"code.gitea.io/gitea/services/auth"
9798
"code.gitea.io/gitea/services/context"
9899
"code.gitea.io/gitea/services/forms"
@@ -835,6 +836,34 @@ func Routes() *web.Route {
835836
SignInRequired: setting.Service.RequireSignInView,
836837
}))
837838

839+
addActionsRoutes := func(
840+
m *web.Route,
841+
reqChecker func(ctx *context.APIContext),
842+
act actions.API,
843+
) {
844+
m.Group("/actions", func() {
845+
m.Group("/secrets", func() {
846+
m.Get("", reqToken(), reqChecker, act.ListActionsSecrets)
847+
m.Combo("/{secretname}").
848+
Put(reqToken(), reqChecker, bind(api.CreateOrUpdateSecretOption{}), act.CreateOrUpdateSecret).
849+
Delete(reqToken(), reqChecker, act.DeleteSecret)
850+
})
851+
852+
m.Group("/variables", func() {
853+
m.Get("", reqToken(), reqChecker, act.ListVariables)
854+
m.Combo("/{variablename}").
855+
Get(reqToken(), reqChecker, act.GetVariable).
856+
Delete(reqToken(), reqChecker, act.DeleteVariable).
857+
Post(reqToken(), reqChecker, bind(api.CreateVariableOption{}), act.CreateVariable).
858+
Put(reqToken(), reqChecker, bind(api.UpdateVariableOption{}), act.UpdateVariable)
859+
})
860+
861+
m.Group("/runners", func() {
862+
m.Get("/registration-token", reqToken(), reqChecker, act.GetRegistrationToken)
863+
})
864+
})
865+
}
866+
838867
m.Group("", func() {
839868
// Miscellaneous (no scope required)
840869
if setting.API.EnableSwagger {
@@ -1073,26 +1102,11 @@ func Routes() *web.Route {
10731102
m.Post("/accept", repo.AcceptTransfer)
10741103
m.Post("/reject", repo.RejectTransfer)
10751104
}, reqToken())
1076-
m.Group("/actions", func() {
1077-
m.Group("/secrets", func() {
1078-
m.Combo("/{secretname}").
1079-
Put(reqToken(), reqOwner(), bind(api.CreateOrUpdateSecretOption{}), repo.CreateOrUpdateSecret).
1080-
Delete(reqToken(), reqOwner(), repo.DeleteSecret)
1081-
})
1082-
1083-
m.Group("/variables", func() {
1084-
m.Get("", reqToken(), reqOwner(), repo.ListVariables)
1085-
m.Combo("/{variablename}").
1086-
Get(reqToken(), reqOwner(), repo.GetVariable).
1087-
Delete(reqToken(), reqOwner(), repo.DeleteVariable).
1088-
Post(reqToken(), reqOwner(), bind(api.CreateVariableOption{}), repo.CreateVariable).
1089-
Put(reqToken(), reqOwner(), bind(api.UpdateVariableOption{}), repo.UpdateVariable)
1090-
})
1091-
1092-
m.Group("/runners", func() {
1093-
m.Get("/registration-token", reqToken(), reqOwner(), repo.GetRegistrationToken)
1094-
})
1095-
})
1105+
addActionsRoutes(
1106+
m,
1107+
reqOwner(),
1108+
repo.NewAction(),
1109+
)
10961110
m.Group("/hooks/git", func() {
10971111
m.Combo("").Get(repo.ListGitHooks)
10981112
m.Group("/{id}", func() {
@@ -1460,27 +1474,11 @@ func Routes() *web.Route {
14601474
m.Combo("/{username}").Get(reqToken(), org.IsMember).
14611475
Delete(reqToken(), reqOrgOwnership(), org.DeleteMember)
14621476
})
1463-
m.Group("/actions", func() {
1464-
m.Group("/secrets", func() {
1465-
m.Get("", reqToken(), reqOrgOwnership(), org.ListActionsSecrets)
1466-
m.Combo("/{secretname}").
1467-
Put(reqToken(), reqOrgOwnership(), bind(api.CreateOrUpdateSecretOption{}), org.CreateOrUpdateSecret).
1468-
Delete(reqToken(), reqOrgOwnership(), org.DeleteSecret)
1469-
})
1470-
1471-
m.Group("/variables", func() {
1472-
m.Get("", reqToken(), reqOrgOwnership(), org.ListVariables)
1473-
m.Combo("/{variablename}").
1474-
Get(reqToken(), reqOrgOwnership(), org.GetVariable).
1475-
Delete(reqToken(), reqOrgOwnership(), org.DeleteVariable).
1476-
Post(reqToken(), reqOrgOwnership(), bind(api.CreateVariableOption{}), org.CreateVariable).
1477-
Put(reqToken(), reqOrgOwnership(), bind(api.UpdateVariableOption{}), org.UpdateVariable)
1478-
})
1479-
1480-
m.Group("/runners", func() {
1481-
m.Get("/registration-token", reqToken(), reqOrgOwnership(), org.GetRegistrationToken)
1482-
})
1483-
})
1477+
addActionsRoutes(
1478+
m,
1479+
reqOrgOwnership(),
1480+
org.NewAction(),
1481+
)
14841482
m.Group("/public_members", func() {
14851483
m.Get("", org.ListPublicMembers)
14861484
m.Combo("/{username}").Get(org.IsPublicMember).

0 commit comments

Comments
 (0)