Skip to content

Commit 75ae415

Browse files
committed
fix key is null
1 parent ab13efd commit 75ae415

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

routers/web/repo/issue_view.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -496,21 +496,23 @@ func preparePullViewSigning(ctx *context.Context, issue *issues_model.Issue) {
496496
if ctx.Doer != nil {
497497
sign, key, _, err := asymkey_service.SignMerge(ctx, pull, ctx.Doer, pull.BaseRepo.RepoPath(), pull.BaseBranch, pull.GetGitHeadRefName())
498498
ctx.Data["WillSign"] = sign
499-
switch key.Format {
500-
case git.SigningKeyFormatOpenPGP:
501-
ctx.Data["SigningKey"] = key.KeyID
502-
case git.SigningKeyFormatSSH:
503-
content, readErr := os.ReadFile(key.KeyID)
504-
if readErr != nil {
505-
log.Error("Error whilst reading public key of pr %d in repo %s. Error: %v", pull.ID, pull.BaseRepo.FullName(), readErr)
506-
ctx.Data["SigningKey"] = "Unknown"
507-
} else {
508-
var fingerprintErr error
509-
ctx.Data["SigningKey"], fingerprintErr = asymkey_model.CalcFingerprint(string(content))
510-
if fingerprintErr != nil {
511-
log.Error("Error whilst generating public key fingerprint of pr %d in repo %s. Error: %v", pull.ID, pull.BaseRepo.FullName(), fingerprintErr)
512-
} else {
499+
if key != nil {
500+
switch key.Format {
501+
case git.SigningKeyFormatOpenPGP:
502+
ctx.Data["SigningKey"] = key.KeyID
503+
case git.SigningKeyFormatSSH:
504+
content, readErr := os.ReadFile(key.KeyID)
505+
if readErr != nil {
506+
log.Error("Error whilst reading public key of pr %d in repo %s. Error: %v", pull.ID, pull.BaseRepo.FullName(), readErr)
513507
ctx.Data["SigningKey"] = "Unknown"
508+
} else {
509+
var fingerprintErr error
510+
ctx.Data["SigningKey"], fingerprintErr = asymkey_model.CalcFingerprint(string(content))
511+
if fingerprintErr != nil {
512+
log.Error("Error whilst generating public key fingerprint of pr %d in repo %s. Error: %v", pull.ID, pull.BaseRepo.FullName(), fingerprintErr)
513+
} else {
514+
ctx.Data["SigningKey"] = "Unknown"
515+
}
514516
}
515517
}
516518
}

0 commit comments

Comments
 (0)