You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

verification.go 1.1KB

123456789101112131415161718192021222324252627282930313233
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package repofiles
  5. import (
  6. "code.gitea.io/gitea/models"
  7. "code.gitea.io/gitea/modules/git"
  8. "code.gitea.io/gitea/modules/structs"
  9. )
  10. // GetPayloadCommitVerification returns the verification information of a commit
  11. func GetPayloadCommitVerification(commit *git.Commit) *structs.PayloadCommitVerification {
  12. verification := &structs.PayloadCommitVerification{}
  13. commitVerification := models.ParseCommitWithSignature(commit)
  14. if commit.Signature != nil {
  15. verification.Signature = commit.Signature.Signature
  16. verification.Payload = commit.Signature.Payload
  17. }
  18. if commitVerification.SigningUser != nil {
  19. verification.Signer = &structs.PayloadUser{
  20. Name: commitVerification.SigningUser.Name,
  21. Email: commitVerification.SigningUser.Email,
  22. }
  23. }
  24. verification.Verified = commitVerification.Verified
  25. verification.Reason = commitVerification.Reason
  26. if verification.Reason == "" && !verification.Verified {
  27. verification.Reason = "gpg.error.not_signed_commit"
  28. }
  29. return verification
  30. }