Repository: go-gitea/gitea
File: services/asymkey/commit.go (Go)

Code before:
			committer = &user_model.User{
				Name:  c.Committer.Name,
				Email: c.Committer.Email,
			}
			// We can expect this to often be an ErrUserNotExist. in the case
			// it is not, however, it is important to log it.
			if !user_model.IsErrUserNotExist(err) {
				log.Error("GetUserByEmail: %v", err)
				return &asymkey_model.CommitVerification{
					CommittingUser: committer,
					Verified:       false,
					Reason:         "gpg.error.no_committer_account",
				}
			}
		}
	}

	return ParseCommitWithSignatureCommitter(ctx, c, committer)
}

const (
	cacheUserEmailAddressKey = "gpg_user_email_address"
	cacheUserKey             = "gpg_user"
	cacheGPGListKey          = "gpg_key_list"
)

func ParseCommitWithSignatureCommitter(ctx context.Context, c *git.Commit, committer *user_model.User) *asymkey_model.CommitVerification {
	// If no signature just report the committer
	if c.Signature == nil {
		return &asymkey_model.CommitVerification{
			CommittingUser: committer,
			Verified:       false,                         // Default value
			Reason:         "gpg.error.not_signed_commit", // Default value
		}
	}

	// If this a SSH signature handle it differently
	if strings.HasPrefix(c.Signature.Signature, "-----BEGIN SSH SIGNATURE-----") {
		return ParseCommitWithSSHSignature(ctx, c, committer)
	}

	// Parsing signature
	sig, err := asymkey_model.ExtractSignature(c.Signature.Signature)
	if err != nil { // Skipping failed to extract sign
		log.Error("SignatureRead err: %v", err)
		return &asymkey_model.CommitVerification{
			CommittingUser: committer,
			Verified:       false,
			Reason:         "gpg.error.extract_sign",
		}
	}

Review comment (performance):
My suggestion for naming the cache key is to use `:` to connect the parts, so that the keys can be displayed in the form of a conference directory in the Redis GUI. Of course, due to historical reasons, gitea's cache can all use underscores, so I don't object, I just want to say my thoughts.

![image](https://github.com/user-attachments/assets/6bc7295e-4731-47e3-9c2d-d84677da2cc4)


Code after:
		if err != nil {                                                    // Skipping not user for committer
			committer = &user_model.User{
				Name:  c.Committer.Name,
				Email: c.Committer.Email,
			}
			// We can expect this to often be an ErrUserNotExist. in the case
			// it is not, however, it is important to log it.
			if !user_model.IsErrUserNotExist(err) {
				log.Error("GetUserByEmail: %v", err)
				return &asymkey_model.CommitVerification{
					CommittingUser: committer,
					Verified:       false,
					Reason:         "gpg.error.no_committer_account",
				}
			}
		}
	}

	return ParseCommitWithSignatureCommitter(ctx, c, committer)
}

func ParseCommitWithSignatureCommitter(ctx context.Context, c *git.Commit, committer *user_model.User) *asymkey_model.CommitVerification {
	// If no signature just report the committer
	if c.Signature == nil {
		return &asymkey_model.CommitVerification{
			CommittingUser: committer,
			Verified:       false,                         // Default value
			Reason:         "gpg.error.not_signed_commit", // Default value
		}
	}

	// If this a SSH signature handle it differently
	if strings.HasPrefix(c.Signature.Signature, "-----BEGIN SSH SIGNATURE-----") {
		return ParseCommitWithSSHSignature(ctx, c, committer)
	}

	// Parsing signature
	sig, err := asymkey_model.ExtractSignature(c.Signature.Signature)
	if err != nil { // Skipping failed to extract sign
		log.Error("SignatureRead err: %v", err)
		return &asymkey_model.CommitVerification{
			CommittingUser: committer,
			Verified:       false,
			Reason:         "gpg.error.extract_sign",
		}
	}

	keyID := asymkey_model.TryGetKeyIDFromSignature(sig)
	defaultReason := asymkey_model.NoKeyFound

	// First check if the sig has a keyID and if so just look at that