fix: add toNormalizedJson to match github output
This commit is contained in:
parent
300b074f86
commit
865c639557
|
@ -10,6 +10,8 @@ import (
|
|||
"gorm.io/gorm"
|
||||
"io"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type WebhookManager struct {
|
||||
|
@ -63,6 +65,8 @@ func (whm *WebhookManager) sendWebhooks(request interface{}, r *http.Request) {
|
|||
}
|
||||
|
||||
payload := getWebhookData(r, whm.logger)
|
||||
payload = toNormalizedJson(payload)
|
||||
|
||||
signature := generatePayloadSignature(payload, app.WebhookSecret)
|
||||
req.Header.Add("X-Hub-Signature-256", signature)
|
||||
|
||||
|
@ -86,5 +90,27 @@ func (whm *WebhookManager) sendWebhooks(request interface{}, r *http.Request) {
|
|||
}
|
||||
}(app)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Ported from https://github.com/octokit/webhooks.js/blob/984f3f51e077dbc7637aa55406c3bb114dbb7f82/src/to-normalized-json-string.ts
|
||||
*/
|
||||
|
||||
func toNormalizedJson(payload []byte) []byte {
|
||||
jsonString := string(payload)
|
||||
|
||||
// Regex to find Unicode escape sequences
|
||||
re := regexp.MustCompile(`\\u([\da-fA-F]{4})`)
|
||||
|
||||
// Function to convert found sequences to uppercase
|
||||
replaceFunc := func(match string) string {
|
||||
parts := strings.Split(match, "\\u")
|
||||
// Convert the Unicode sequence part to uppercase
|
||||
return parts[0] + "\\u" + strings.ToUpper(parts[1])
|
||||
}
|
||||
|
||||
// Replace the matches in the jsonString
|
||||
normalizedString := re.ReplaceAllStringFunc(jsonString, replaceFunc)
|
||||
|
||||
return []byte(normalizedString)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue