Skip to content

Commit 6ab6d4e

Browse files
authored
Support base64-encoded agit push options (#35037)
1 parent 32152a0 commit 6ab6d4e

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

services/agit/agit.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package agit
55

66
import (
77
"context"
8+
"encoding/base64"
89
"fmt"
910
"os"
1011
"strings"
@@ -18,17 +19,30 @@ import (
1819
"code.gitea.io/gitea/modules/log"
1920
"code.gitea.io/gitea/modules/private"
2021
"code.gitea.io/gitea/modules/setting"
22+
"code.gitea.io/gitea/modules/util"
2123
notify_service "code.gitea.io/gitea/services/notify"
2224
pull_service "code.gitea.io/gitea/services/pull"
2325
)
2426

27+
func parseAgitPushOptionValue(s string) string {
28+
if base64Value, ok := strings.CutPrefix(s, "{base64}"); ok {
29+
decoded, err := base64.StdEncoding.DecodeString(base64Value)
30+
return util.Iif(err == nil, string(decoded), s)
31+
}
32+
return s
33+
}
34+
2535
// ProcReceive handle proc receive work
2636
func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, opts *private.HookOptions) ([]private.HookProcReceiveRefResult, error) {
2737
results := make([]private.HookProcReceiveRefResult, 0, len(opts.OldCommitIDs))
2838
forcePush := opts.GitPushOptions.Bool(private.GitPushOptionForcePush)
2939
topicBranch := opts.GitPushOptions["topic"]
30-
title := strings.TrimSpace(opts.GitPushOptions["title"])
31-
description := strings.TrimSpace(opts.GitPushOptions["description"])
40+
41+
// some options are base64-encoded with "{base64}" prefix if they contain new lines
42+
// other agit push options like "issue", "reviewer" and "cc" are not supported
43+
title := parseAgitPushOptionValue(opts.GitPushOptions["title"])
44+
description := parseAgitPushOptionValue(opts.GitPushOptions["description"])
45+
3246
objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName)
3347
userName := strings.ToLower(opts.UserName)
3448

services/agit/agit_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2025 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package agit
5+
6+
import (
7+
"testing"
8+
9+
"github.com/stretchr/testify/assert"
10+
)
11+
12+
func TestParseAgitPushOptionValue(t *testing.T) {
13+
assert.Equal(t, "a", parseAgitPushOptionValue("a"))
14+
assert.Equal(t, "a", parseAgitPushOptionValue("{base64}YQ=="))
15+
assert.Equal(t, "{base64}invalid value", parseAgitPushOptionValue("{base64}invalid value"))
16+
}

0 commit comments

Comments
 (0)