github.com/crosbymichael/octokat@v0.0.0-20160826194511-076a32289ed5/repositories.go (about)

     1  package octokat
     2  
     3  import (
     4  	"fmt"
     5  	"time"
     6  )
     7  
     8  type Repository struct {
     9  	ID            int           `json:"id,omitempty"`
    10  	Owner         User          `json:"owner,omitempty"`
    11  	Name          string        `json:"name,omitempty"`
    12  	FullName      string        `json:"full_name,omitempty"`
    13  	Description   string        `json:"description,omitempty"`
    14  	Private       bool          `json:"private,omitempty"`
    15  	Fork          bool          `json:"fork,omitempty"`
    16  	URL           string        `json:"url,omitempty"`
    17  	HTMLURL       string        `json:"html_url,omitempty"`
    18  	CloneURL      string        `json:"clone_url,omitempty"`
    19  	GitURL        string        `json:"git_url,omitempty"`
    20  	SSHURL        string        `json:"ssh_url,omitempty"`
    21  	SVNURL        string        `json:"svn_url,omitempty"`
    22  	MirrorURL     string        `json:"mirror_url,omitempty"`
    23  	Homepage      string        `json:"homepage,omitempty"`
    24  	Language      string        `json:"language,omitempty"`
    25  	Forks         int           `json:"forks,omitempty"`
    26  	ForksCount    int           `json:"forks_count,omitempty"`
    27  	Watchers      int           `json:"watchers,omitempty"`
    28  	WatchersCount int           `json:"watchers_count,omitempty"`
    29  	Size          int           `json:"size,omitempty"`
    30  	MasterBranch  string        `json:"master_branch,omitempty"`
    31  	OpenIssues    int           `json:"open_issues,omitempty"`
    32  	PushedAt      time.Time     `json:"pushed_at,omitempty"`
    33  	CreatedAt     time.Time     `json:"created_at,omitempty"`
    34  	UpdatedAt     time.Time     `json:"updated_at,omitempty"`
    35  	Organization  *Organization `json:"organization,omitempty"`
    36  	Parent        *Repository   `json:"parent,omitempty"`
    37  	Source        *Repository   `json:"source,omitempty"`
    38  	HasIssues     bool          `json:"has_issues,omitempty"`
    39  	HasWiki       bool          `json:"has_wiki,omitempty"`
    40  	HasDownloads  bool          `json:"has_downloads,omitempty"`
    41  }
    42  
    43  // List repositories
    44  //
    45  // If username is not supplied, repositories for the current
    46  // authenticated user are returned
    47  //
    48  // See http://developer.github.com/v3/repos/#list-your-repositories
    49  func (c *Client) Repositories(username string, options *Options) (repositories []Repository, err error) {
    50  	var path string
    51  	if username == "" {
    52  		path = "user/repos"
    53  	} else {
    54  		path = fmt.Sprintf("users/%s/repos", username)
    55  	}
    56  
    57  	err = c.jsonGet(path, options, &repositories)
    58  	return
    59  }
    60  
    61  // Get a single repository
    62  //
    63  // See http://developer.github.com/v3/repos/#get
    64  func (c *Client) Repository(repo Repo, options *Options) (repository *Repository, err error) {
    65  	path := fmt.Sprintf("repos/%s", repo)
    66  	err = c.jsonGet(path, options, &repository)
    67  	return
    68  }
    69  
    70  type RepositoryParams struct {
    71  	Name              string `json:"name,omitempty"`
    72  	Description       string `json:"description,omitempty"`
    73  	Homepage          string `json:"homepage,omitempty"`
    74  	Private           bool   `json:"private,omitempty"`
    75  	HasIssues         bool   `json:"has_issues,omitempty"`
    76  	HasWiki           bool   `json:"has_wiki,omitempty"`
    77  	HasDownloads      bool   `json:"has_downloads,omitempty"`
    78  	TeamID            int    `json:"team_id,omitempty"`
    79  	AutoInit          bool   `json:"auto_init,omitempty"`
    80  	GitignoreTemplate string `json:"gitignore_template,omitempty"`
    81  }
    82  
    83  // Create a repository for a user or organization
    84  //
    85  // If org is not specified, create a repository for current user.
    86  //
    87  // See http://developer.github.com/v3/repos/#create
    88  func (c *Client) CreateRepository(org string, options *Options) (repository *Repository, err error) {
    89  	var path string
    90  	if org == "" {
    91  		path = "user/repos"
    92  	} else {
    93  		path = fmt.Sprintf("orgs/%s/repos", org)
    94  	}
    95  
    96  	err = c.jsonPost(path, options, &repository)
    97  	return
    98  }
    99  
   100  // Fork a repository
   101  //
   102  // See http://developer.github.com/v3/repos/forks/#create-a-fork
   103  func (c *Client) Fork(repo Repo, options *Options) (repository *Repository, err error) {
   104  	path := fmt.Sprintf("repos/%s/forks", repo)
   105  	err = c.jsonPost(path, options, &repository)
   106  	return
   107  }