| 1 |
// Copyright 2023 The go-github AUTHORS. All rights reserved. |
| 2 |
// |
| 3 |
// Use of this source code is governed by a BSD-style |
| 4 |
// license that can be found in the LICENSE file. |
| 5 |
|
| 6 |
package github |
| 7 |
|
| 8 |
import ( |
| 9 |
"context" |
| 10 |
"fmt" |
| 11 |
) |
| 12 |
|
| 13 |
// HookConfig describes metadata about a webhook configuration. |
| 14 |
type HookConfig struct { |
| 15 |
// The media type used to serialize the payloads |
| 16 |
// Possible values are `json` and `form`, the field is not specified the default is `form` |
| 17 |
ContentType *string `json:"content_type,omitempty"` |
| 18 |
// The possible values are 0 and 1. |
| 19 |
// Setting it to 1 will allow skip certificate verification for the host, |
| 20 |
// potentially exposing to MitM attacks: https://en.wikipedia.org/wiki/Man-in-the-middle_attack |
| 21 |
InsecureSSL *string `json:"insecure_ssl,omitempty"` |
| 22 |
URL *string `json:"url,omitempty"` |
| 23 |
|
| 24 |
// Secret is returned obfuscated by GitHub, but it can be set for outgoing requests. |
| 25 |
Secret *string `json:"secret,omitempty"` |
| 26 |
} |
| 27 |
|
| 28 |
// GetHookConfiguration returns the configuration for the specified repository webhook. |
| 29 |
// |
| 30 |
// GitHub API docs: https://docs.github.com/rest/repos/webhooks#get-a-webhook-configuration-for-a-repository |
| 31 |
// |
| 32 |
//meta:operation GET /repos/{owner}/{repo}/hooks/{hook_id}/config |
| 33 |
func (s *RepositoriesService) GetHookConfiguration(ctx context.Context, owner, repo string, id int64) (*HookConfig, *Response, error) { |
| 34 |
u := fmt.Sprintf("repos/%v/%v/hooks/%v/config", owner, repo, id) |
| 35 |
req, err := s.client.NewRequest("GET", u, nil) |
| 36 |
if err != nil { |
| 37 |
return nil, nil, err |
| 38 |
} |
| 39 |
|
| 40 |
config := new(HookConfig) |
| 41 |
resp, err := s.client.Do(ctx, req, config) |
| 42 |
if err != nil { |
| 43 |
return nil, resp, err |
| 44 |
} |
| 45 |
|
| 46 |
return config, resp, nil |
| 47 |
} |
| 48 |
|
| 49 |
// EditHookConfiguration updates the configuration for the specified repository webhook. |
| 50 |
// |
| 51 |
// GitHub API docs: https://docs.github.com/rest/repos/webhooks#update-a-webhook-configuration-for-a-repository |
| 52 |
// |
| 53 |
//meta:operation PATCH /repos/{owner}/{repo}/hooks/{hook_id}/config |
| 54 |
func (s *RepositoriesService) EditHookConfiguration(ctx context.Context, owner, repo string, id int64, config *HookConfig) (*HookConfig, *Response, error) { |
| 55 |
u := fmt.Sprintf("repos/%v/%v/hooks/%v/config", owner, repo, id) |
| 56 |
req, err := s.client.NewRequest("PATCH", u, config) |
| 57 |
if err != nil { |
| 58 |
return nil, nil, err |
| 59 |
} |
| 60 |
|
| 61 |
c := new(HookConfig) |
| 62 |
resp, err := s.client.Do(ctx, req, c) |
| 63 |
if err != nil { |
| 64 |
return nil, resp, err |
| 65 |
} |
| 66 |
|
| 67 |
return c, resp, nil |
| 68 |
} |