...

Source file src/github.com/xanzy/go-gitlab/external_status_checks.go

Documentation: github.com/xanzy/go-gitlab

     1  package gitlab
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"time"
     7  )
     8  
     9  // ExternalStatusChecksService handles communication with the external
    10  // status check related methods of the GitLab API.
    11  //
    12  // GitLab API docs: https://docs.gitlab.com/ee/api/status_checks.html
    13  type ExternalStatusChecksService struct {
    14  	client *Client
    15  }
    16  
    17  type MergeStatusCheck struct {
    18  	ID          int    `json:"id"`
    19  	Name        string `json:"name"`
    20  	ExternalURL string `json:"external_url"`
    21  	Status      string `json:"status"`
    22  }
    23  
    24  type ProjectStatusCheck struct {
    25  	ID                int                          `json:"id"`
    26  	Name              string                       `json:"name"`
    27  	ProjectID         int                          `json:"project_id"`
    28  	ExternalURL       string                       `json:"external_url"`
    29  	ProtectedBranches []StatusCheckProtectedBranch `json:"protected_branches"`
    30  }
    31  
    32  type StatusCheckProtectedBranch struct {
    33  	ID                        int        `json:"id"`
    34  	ProjectID                 int        `json:"project_id"`
    35  	Name                      string     `json:"name"`
    36  	CreatedAt                 *time.Time `json:"created_at"`
    37  	UpdatedAt                 *time.Time `json:"updated_at"`
    38  	CodeOwnerApprovalRequired bool       `json:"code_owner_approval_required"`
    39  }
    40  
    41  // ListMergeStatusChecks lists the external status checks that apply to it
    42  // and their status for a single merge request.
    43  //
    44  // GitLab API docs:
    45  // https://docs.gitlab.com/ee/api/status_checks.html#list-status-checks-for-a-merge-request
    46  func (s *ExternalStatusChecksService) ListMergeStatusChecks(pid interface{}, mr int, opt *ListOptions, options ...RequestOptionFunc) ([]*MergeStatusCheck, *Response, error) {
    47  	project, err := parseID(pid)
    48  	if err != nil {
    49  		return nil, nil, err
    50  	}
    51  	u := fmt.Sprintf("projects/%s/merge_requests/%d/status_checks", PathEscape(project), mr)
    52  
    53  	req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
    54  	if err != nil {
    55  		return nil, nil, err
    56  	}
    57  
    58  	var mscs []*MergeStatusCheck
    59  	resp, err := s.client.Do(req, &mscs)
    60  	if err != nil {
    61  		return nil, resp, err
    62  	}
    63  
    64  	return mscs, resp, nil
    65  }
    66  
    67  // SetExternalStatusCheckStatusOptions represents the available
    68  // SetExternalStatusCheckStatus() options.
    69  //
    70  // GitLab API docs:
    71  // https://docs.gitlab.com/ee/api/status_checks.html#set-status-of-an-external-status-check
    72  type SetExternalStatusCheckStatusOptions struct {
    73  	SHA                   *string `url:"sha,omitempty" json:"sha,omitempty"`
    74  	ExternalStatusCheckID *int    `url:"external_status_check_id,omitempty" json:"external_status_check_id,omitempty"`
    75  	Status                *string `url:"status,omitempty" json:"status,omitempty"`
    76  }
    77  
    78  // SetExternalStatusCheckStatus sets the status of an external status check.
    79  //
    80  // Gitlab API docs:
    81  // https://docs.gitlab.com/ee/api/status_checks.html#set-status-of-an-external-status-check
    82  func (s *ExternalStatusChecksService) SetExternalStatusCheckStatus(pid interface{}, mergeRequest int, opt *SetExternalStatusCheckStatusOptions, options ...RequestOptionFunc) (*Response, error) {
    83  	project, err := parseID(pid)
    84  	if err != nil {
    85  		return nil, err
    86  	}
    87  	u := fmt.Sprintf("projects/%s/merge_requests/%d/status_check_responses", PathEscape(project), mergeRequest)
    88  
    89  	req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
    90  	if err != nil {
    91  		return nil, err
    92  	}
    93  
    94  	return s.client.Do(req, nil)
    95  }
    96  
    97  // ListProjectStatusChecks lists the project external status checks.
    98  //
    99  // GitLab API docs:
   100  // https://docs.gitlab.com/ee/api/status_checks.html#get-project-external-status-checks
   101  func (s *ExternalStatusChecksService) ListProjectStatusChecks(pid interface{}, opt *ListOptions, options ...RequestOptionFunc) ([]*ProjectStatusCheck, *Response, error) {
   102  	project, err := parseID(pid)
   103  	if err != nil {
   104  		return nil, nil, err
   105  	}
   106  	u := fmt.Sprintf("projects/%s/external_status_checks", PathEscape(project))
   107  
   108  	req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
   109  	if err != nil {
   110  		return nil, nil, err
   111  	}
   112  
   113  	var pscs []*ProjectStatusCheck
   114  	resp, err := s.client.Do(req, &pscs)
   115  	if err != nil {
   116  		return nil, resp, err
   117  	}
   118  
   119  	return pscs, resp, nil
   120  }
   121  
   122  // CreateExternalStatusCheckOptions represents the available
   123  // CreateExternalStatusCheck() options.
   124  //
   125  // GitLab API docs:
   126  // https://docs.gitlab.com/ee/api/status_checks.html#create-external-status-check
   127  type CreateExternalStatusCheckOptions struct {
   128  	Name               *string `url:"name,omitempty" json:"name,omitempty"`
   129  	ExternalURL        *string `url:"external_url,omitempty" json:"external_url,omitempty"`
   130  	ProtectedBranchIDs *[]int  `url:"protected_branch_ids,omitempty" json:"protected_branch_ids,omitempty"`
   131  }
   132  
   133  // CreateExternalStatusCheck creates an external status check.
   134  //
   135  // Gitlab API docs:
   136  // https://docs.gitlab.com/ee/api/status_checks.html#create-external-status-check
   137  func (s *ExternalStatusChecksService) CreateExternalStatusCheck(pid interface{}, opt *CreateExternalStatusCheckOptions, options ...RequestOptionFunc) (*Response, error) {
   138  	project, err := parseID(pid)
   139  	if err != nil {
   140  		return nil, err
   141  	}
   142  	u := fmt.Sprintf("projects/%s/external_status_checks", PathEscape(project))
   143  
   144  	req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
   145  	if err != nil {
   146  		return nil, err
   147  	}
   148  
   149  	return s.client.Do(req, nil)
   150  }
   151  
   152  // DeleteExternalStatusCheck deletes an external status check.
   153  //
   154  // Gitlab API docs:
   155  // https://docs.gitlab.com/ee/api/status_checks.html#delete-external-status-check
   156  func (s *ExternalStatusChecksService) DeleteExternalStatusCheck(pid interface{}, check int, options ...RequestOptionFunc) (*Response, error) {
   157  	project, err := parseID(pid)
   158  	if err != nil {
   159  		return nil, err
   160  	}
   161  	u := fmt.Sprintf("projects/%s/external_status_checks/%d", PathEscape(project), check)
   162  
   163  	req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
   164  	if err != nil {
   165  		return nil, err
   166  	}
   167  
   168  	return s.client.Do(req, nil)
   169  }
   170  
   171  // UpdateExternalStatusCheckOptions represents the available
   172  // UpdateExternalStatusCheck() options.
   173  //
   174  // GitLab API docs:
   175  // https://docs.gitlab.com/ee/api/status_checks.html#update-external-status-check
   176  type UpdateExternalStatusCheckOptions struct {
   177  	Name               *string `url:"name,omitempty" json:"name,omitempty"`
   178  	ExternalURL        *string `url:"external_url,omitempty" json:"external_url,omitempty"`
   179  	ProtectedBranchIDs *[]int  `url:"protected_branch_ids,omitempty" json:"protected_branch_ids,omitempty"`
   180  }
   181  
   182  // UpdateExternalStatusCheck updates an external status check.
   183  //
   184  // Gitlab API docs:
   185  // https://docs.gitlab.com/ee/api/status_checks.html#update-external-status-check
   186  func (s *ExternalStatusChecksService) UpdateExternalStatusCheck(pid interface{}, check int, opt *UpdateExternalStatusCheckOptions, options ...RequestOptionFunc) (*Response, error) {
   187  	project, err := parseID(pid)
   188  	if err != nil {
   189  		return nil, err
   190  	}
   191  	u := fmt.Sprintf("projects/%s/external_status_checks/%d", PathEscape(project), check)
   192  
   193  	req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
   194  	if err != nil {
   195  		return nil, err
   196  	}
   197  
   198  	return s.client.Do(req, nil)
   199  }
   200  

View as plain text