in pkg/gitprovider/github.go [46:98]
func (c *GitHubClient) CreateWebHook(
ctx context.Context,
githubURL,
token,
projectID,
webHookSecret,
webHookURL string,
skipTLS bool,
) (*WebHook, error) {
owner, repo, err := parseProjectID(projectID)
if err != nil {
return nil, err
}
c.restyClient.HostURL = githubURL
webHook := &gitHubWebHook{}
insecure := 0
if skipTLS {
insecure = 1
}
resp, err := c.restyClient.
R().
SetContext(ctx).
SetAuthToken(token).
SetBody(map[string]interface{}{
"name": "web",
"active": true,
"events": []string{"pull_request", "push", "issue_comment"},
"config": map[string]string{
"url": webHookURL,
"content_type": "json",
"insecure_ssl": strconv.Itoa(insecure),
"secret": webHookSecret,
},
}).
SetPathParams(map[string]string{
ownerPathParam: owner,
repoPathParam: repo,
}).
SetResult(webHook).
Post("/repos/{owner}/{repo}/hooks")
if err != nil {
return nil, fmt.Errorf("failed to create GitHub web hook: %w", err)
}
if resp.IsError() {
return nil, fmt.Errorf("failed to create GitHub web hook: %s", resp.String())
}
return convertWebhook(webHook), nil
}