Add push webhook support for mirrored repositories (#4127)
This commit is contained in:
parent
bf55276189
commit
fa4663e61e
8 changed files with 257 additions and 19 deletions
24
vendor/code.gitea.io/git/commit.go
generated
vendored
24
vendor/code.gitea.io/git/commit.go
generated
vendored
|
@ -34,14 +34,18 @@ type CommitGPGSignature struct {
|
|||
}
|
||||
|
||||
// similar to https://github.com/git/git/blob/3bc53220cb2dcf709f7a027a3f526befd021d858/commit.c#L1128
|
||||
func newGPGSignatureFromCommitline(data []byte, signatureStart int) (*CommitGPGSignature, error) {
|
||||
func newGPGSignatureFromCommitline(data []byte, signatureStart int, tag bool) (*CommitGPGSignature, error) {
|
||||
sig := new(CommitGPGSignature)
|
||||
signatureEnd := bytes.LastIndex(data, []byte("-----END PGP SIGNATURE-----"))
|
||||
if signatureEnd == -1 {
|
||||
return nil, fmt.Errorf("end of commit signature not found")
|
||||
}
|
||||
sig.Signature = strings.Replace(string(data[signatureStart:signatureEnd+27]), "\n ", "\n", -1)
|
||||
sig.Payload = string(data[:signatureStart-8]) + string(data[signatureEnd+27:])
|
||||
if tag {
|
||||
sig.Payload = string(data[:signatureStart-1])
|
||||
} else {
|
||||
sig.Payload = string(data[:signatureStart-8]) + string(data[signatureEnd+27:])
|
||||
}
|
||||
return sig, nil
|
||||
}
|
||||
|
||||
|
@ -274,3 +278,19 @@ func (c *Commit) GetSubModule(entryname string) (*SubModule, error) {
|
|||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// GetFullCommitID returns full length (40) of commit ID by given short SHA in a repository.
|
||||
func GetFullCommitID(repoPath, shortID string) (string, error) {
|
||||
if len(shortID) >= 40 {
|
||||
return shortID, nil
|
||||
}
|
||||
|
||||
commitID, err := NewCommand("rev-parse", shortID).RunInDir(repoPath)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "exit status 128") {
|
||||
return "", ErrNotExist{shortID, ""}
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
return strings.TrimSpace(commitID), nil
|
||||
}
|
||||
|
|
17
vendor/code.gitea.io/git/repo_commit.go
generated
vendored
17
vendor/code.gitea.io/git/repo_commit.go
generated
vendored
|
@ -78,7 +78,7 @@ l:
|
|||
}
|
||||
commit.Committer = sig
|
||||
case "gpgsig":
|
||||
sig, err := newGPGSignatureFromCommitline(data, nextline+spacepos+1)
|
||||
sig, err := newGPGSignatureFromCommitline(data, nextline+spacepos+1, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -86,7 +86,20 @@ l:
|
|||
}
|
||||
nextline += eol + 1
|
||||
case eol == 0:
|
||||
commit.CommitMessage = string(data[nextline+1:])
|
||||
cm := string(data[nextline+1:])
|
||||
|
||||
// Tag GPG signatures are stored below the commit message
|
||||
sigindex := strings.Index(cm, "-----BEGIN PGP SIGNATURE-----")
|
||||
if sigindex != -1 {
|
||||
sig, err := newGPGSignatureFromCommitline(data, (nextline+1)+sigindex, true)
|
||||
if err == nil && sig != nil {
|
||||
// remove signature from commit message
|
||||
cm = cm[:sigindex-1]
|
||||
commit.Signature = sig
|
||||
}
|
||||
}
|
||||
|
||||
commit.CommitMessage = cm
|
||||
break l
|
||||
default:
|
||||
break l
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue