Skip to content

Commit 00bb0b7

Browse files
committed
add context to GetDefaultPublicKey
1 parent e8f1fb3 commit 00bb0b7

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

modules/git/commit.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -468,11 +468,11 @@ func GetFullCommitID(ctx context.Context, repoPath, shortID string) (string, err
468468
}
469469

470470
// GetRepositoryDefaultPublicGPGKey returns the default public key for this commit
471-
func (c *Commit) GetRepositoryDefaultPublicGPGKey(forceUpdate bool) (*GPGSettings, error) {
471+
func (c *Commit) GetRepositoryDefaultPublicGPGKey(ctx context.Context, forceUpdate bool) (*GPGSettings, error) {
472472
if c.repo == nil {
473473
return nil, nil
474474
}
475-
return c.repo.GetDefaultPublicGPGKey(forceUpdate)
475+
return c.repo.GetDefaultPublicGPGKey(ctx, forceUpdate)
476476
}
477477

478478
func IsStringLikelyCommitID(objFmt ObjectFormat, s string, minLength ...int) bool {

modules/git/repo_gpg.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package git
66

77
import (
8+
"context"
89
"fmt"
910
"strings"
1011

@@ -24,7 +25,7 @@ func (gpgSettings *GPGSettings) LoadPublicKeyContent() error {
2425
}
2526

2627
// GetDefaultPublicGPGKey will return and cache the default public GPG settings for this repository
27-
func (repo *Repository) GetDefaultPublicGPGKey(forceUpdate bool) (*GPGSettings, error) {
28+
func (repo *Repository) GetDefaultPublicGPGKey(ctx context.Context, forceUpdate bool) (*GPGSettings, error) {
2829
if repo.gpgSettings != nil && !forceUpdate {
2930
return repo.gpgSettings, nil
3031
}
@@ -33,21 +34,21 @@ func (repo *Repository) GetDefaultPublicGPGKey(forceUpdate bool) (*GPGSettings,
3334
Sign: true,
3435
}
3536

36-
value, _, _ := NewCommand("config", "--get", "commit.gpgsign").RunStdString(repo.Ctx, &RunOpts{Dir: repo.Path})
37+
value, _, _ := NewCommand("config", "--get", "commit.gpgsign").RunStdString(ctx, &RunOpts{Dir: repo.Path})
3738
sign, valid := ParseBool(strings.TrimSpace(value))
3839
if !sign || !valid {
3940
gpgSettings.Sign = false
4041
repo.gpgSettings = gpgSettings
4142
return gpgSettings, nil
4243
}
4344

44-
signingKey, _, _ := NewCommand("config", "--get", "user.signingkey").RunStdString(repo.Ctx, &RunOpts{Dir: repo.Path})
45+
signingKey, _, _ := NewCommand("config", "--get", "user.signingkey").RunStdString(ctx, &RunOpts{Dir: repo.Path})
4546
gpgSettings.KeyID = strings.TrimSpace(signingKey)
4647

47-
defaultEmail, _, _ := NewCommand("config", "--get", "user.email").RunStdString(repo.Ctx, &RunOpts{Dir: repo.Path})
48+
defaultEmail, _, _ := NewCommand("config", "--get", "user.email").RunStdString(ctx, &RunOpts{Dir: repo.Path})
4849
gpgSettings.Email = strings.TrimSpace(defaultEmail)
4950

50-
defaultName, _, _ := NewCommand("config", "--get", "user.name").RunStdString(repo.Ctx, &RunOpts{Dir: repo.Path})
51+
defaultName, _, _ := NewCommand("config", "--get", "user.name").RunStdString(ctx, &RunOpts{Dir: repo.Path})
5152
gpgSettings.Name = strings.TrimSpace(defaultName)
5253

5354
if err := gpgSettings.LoadPublicKeyContent(); err != nil {

services/asymkey/commit.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func ParseCommitWithSignatureCommitter(ctx context.Context, c *git.Commit, commi
169169
}
170170
}
171171

172-
defaultGPGSettings, err := c.GetRepositoryDefaultPublicGPGKey(false)
172+
defaultGPGSettings, err := c.GetRepositoryDefaultPublicGPGKey(ctx, false)
173173
if err != nil {
174174
log.Error("Error getting default public gpg key: %v", err)
175175
} else if defaultGPGSettings == nil {

0 commit comments

Comments
 (0)