github.com/google/go-github/v60@v60.0.0/github/apps_hooks.go (about)

     1  // Copyright 2021 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  )
    11  
    12  // GetHookConfig returns the webhook configuration for a GitHub App.
    13  // The underlying transport must be authenticated as an app.
    14  //
    15  // GitHub API docs: https://docs.github.com/rest/apps/webhooks#get-a-webhook-configuration-for-an-app
    16  //
    17  //meta:operation GET /app/hook/config
    18  func (s *AppsService) GetHookConfig(ctx context.Context) (*HookConfig, *Response, error) {
    19  	req, err := s.client.NewRequest("GET", "app/hook/config", nil)
    20  	if err != nil {
    21  		return nil, nil, err
    22  	}
    23  
    24  	config := new(HookConfig)
    25  	resp, err := s.client.Do(ctx, req, &config)
    26  	if err != nil {
    27  		return nil, resp, err
    28  	}
    29  
    30  	return config, resp, nil
    31  }
    32  
    33  // UpdateHookConfig updates the webhook configuration for a GitHub App.
    34  // The underlying transport must be authenticated as an app.
    35  //
    36  // GitHub API docs: https://docs.github.com/rest/apps/webhooks#update-a-webhook-configuration-for-an-app
    37  //
    38  //meta:operation PATCH /app/hook/config
    39  func (s *AppsService) UpdateHookConfig(ctx context.Context, config *HookConfig) (*HookConfig, *Response, error) {
    40  	req, err := s.client.NewRequest("PATCH", "app/hook/config", config)
    41  	if err != nil {
    42  		return nil, nil, err
    43  	}
    44  
    45  	c := new(HookConfig)
    46  	resp, err := s.client.Do(ctx, req, c)
    47  	if err != nil {
    48  		return nil, resp, err
    49  	}
    50  
    51  	return c, resp, nil
    52  }