github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/release/github/statuses.go (about)

     1  // Copyright 2015 Keybase, Inc. All rights reserved. Use of
     2  // this source code is governed by the included BSD license.
     3  
     4  package github
     5  
     6  import "fmt"
     7  
     8  // Status defines a git commit on Github
     9  type Status struct {
    10  	State   string `json:"state"`
    11  	Context string `json:"context"`
    12  }
    13  
    14  // Statuses defines the overall status of a git commit on Github
    15  type Statuses struct {
    16  	State    string   `json:"state"`
    17  	Statuses []Status `json:"statuses"`
    18  }
    19  
    20  const (
    21  	statusesListPath = "/repos/%s/%s/statuses/%s"
    22  	statusListPath   = "/repos/%s/%s/commits/%s/status"
    23  )
    24  
    25  // Statuses lists statuses for a git commit
    26  func getStatuses(token, user, repo, sha string) ([]Status, error) {
    27  	url, err := githubURL(githubAPIURL)
    28  	if err != nil {
    29  		return nil, err
    30  	}
    31  	url.Path = fmt.Sprintf(statusesListPath, user, repo, sha)
    32  	var statuses []Status
    33  	if err = Get(token, url.String()+"?per_page=100", &statuses); err != nil {
    34  		return nil, err
    35  	}
    36  	return statuses, nil
    37  }
    38  
    39  // OverallStatus lists the overall status for a git commit.
    40  // Instead of all the statuses, it gives an overall status
    41  // if all have passed, plus a list of the most recent results
    42  // for each context.
    43  func overallStatus(token, user, repo, sha string) (Statuses, error) {
    44  	url, err := githubURL(githubAPIURL)
    45  	if err != nil {
    46  		return Statuses{}, err
    47  	}
    48  	url.Path = fmt.Sprintf(statusListPath, user, repo, sha)
    49  	var statuses Statuses
    50  	if err = Get(token, url.String(), &statuses); err != nil {
    51  		return Statuses{}, err
    52  	}
    53  	return statuses, nil
    54  }