github.com/nesv/gothub@v0.0.0-20140406181320-f0c824044d5f/repositories.go (about)

     1  package gothub
     2  
     3  import (
     4  	"fmt"
     5  	"time"
     6  )
     7  
     8  type RepositoryOwner struct {
     9  	AvatarUrl        string `json:"avatar_url"`
    10  	EventsUrl        string `json:"events_url"`
    11  	FollowersUrl     string `json:"followers_url"`
    12  	FollowingUrl     string `json:"following_url"`
    13  	GistsUrl         string `json:"gists_url"`
    14  	GravatarId       string `json:"gravatar_id"`
    15  	HtmlUrl          string `json:"html_url"`
    16  	Id               int    `json:"id"`
    17  	Login            string `json:"login"`
    18  	OrganizationsUrl string `json:"organizations_url"`
    19  	ReposUrl         string `json:"repos_url"`
    20  	StarredUrl       string `json:"starred_url"`
    21  	SubscriptionsUrl string `json:"subscriptions_url"`
    22  	Type             string `json:"type"`
    23  	Url              string `json:"url"`
    24  }
    25  
    26  type RepositoryPermissions struct {
    27  	Admin bool `json:"admin"`
    28  	Pull  bool `json:"pull"`
    29  	Push  bool `json:"push"`
    30  }
    31  
    32  type Repository struct {
    33  	ArchiveUrl       string                `json:"archive_url"`
    34  	AssigneesUrl     string                `json:"assignees_url"`
    35  	BlobsUrl         string                `json:"blobs_url"`
    36  	CloneUrl         string                `json:"clone_url"`
    37  	CollaboratorsUrl string                `json:"collaborators_url"`
    38  	CommentsUrl      string                `json:"comments_url"`
    39  	CommitsUrl       string                `json:"comments_url"`
    40  	CompareUrl       string                `json:"compare_url"`
    41  	ContentsUrl      string                `json:"contentsUrl"`
    42  	ContributorsUrl  string                `json:"contributors_url"`
    43  	CreatedAt        time.Time             `json:"created_at"`
    44  	DefaultBranch    string                `json:"default_branch"`
    45  	Description      string                `json:"description"`
    46  	DownloadsUrl     string                `json:"downloads_url"`
    47  	EventsUrl        string                `json:"events_url"`
    48  	Fork             bool                  `json:"fork"`
    49  	Forks            int                   `json:"forks"`
    50  	ForksCount       int                   `json:"forks_count"`
    51  	ForksUrl         string                `json:"forks_url"`
    52  	FullName         string                `json:"full_name"`
    53  	GitCommitsUrl    string                `json:"git_commits_url"`
    54  	GitRefsUrl       string                `json:"git_refs_url"`
    55  	GitTagsUrl       string                `json:"git_tags_url"`
    56  	GitUrl           string                `json:"git_url"`
    57  	HasDownloads     bool                  `json:"has_downloads"`
    58  	HasIssues        bool                  `json:"has_issues"`
    59  	HasWiki          bool                  `json:"has_wiki"`
    60  	Homepage         string                `json:"homepage"`
    61  	HooksUrl         string                `json:"hooks_url"`
    62  	HtmlUrl          string                `json:"html_url"`
    63  	Id               int                   `json:"id"`
    64  	IssueCommentUrl  string                `json:"issue_comment_url"`
    65  	IssueEventsUrl   string                `json:"issue_events_url"`
    66  	IssuesUrl        string                `json:"issues_url"`
    67  	KeysUrl          string                `json:"keys_url"`
    68  	LabelsUrl        string                `json:"labels_url"`
    69  	Language         string                `json:"language"`
    70  	LanguagesUrl     string                `json:"languages_url"`
    71  	MasterBranch     string                `json:"master_branch"`
    72  	MergesUrl        string                `json:"merges_url"`
    73  	MilestonesUrl    string                `json:"milestones_url"`
    74  	MirrorUrl        string                `json:"mirror_url"`
    75  	Name             string                `json:"name"`
    76  	NotificationsUrl string                `json:"notifications_url"`
    77  	OpenIssues       int                   `json:"open_issues"`
    78  	OpenIssuesCount  int                   `json:"open_issues_count"`
    79  	Owner            RepositoryOwner       `json:"owner"`
    80  	Permissions      RepositoryPermissions `json:"permissions"`
    81  	Private          bool                  `json:"private"`
    82  	PullsUrl         string                `json:"pulls_url"`
    83  	PushedAt         time.Time             `json:"pushed_at"`
    84  	Size             int                   `json:"size"`
    85  	SshUrl           string                `json:"ssh_url"`
    86  	StargazersUrl    string                `json:"stargazers_url"`
    87  	StatusesUrl      string                `json:"statuses_url"`
    88  	SubscribersUrl   string                `json:"subscribers_url"`
    89  	SubscriptionUrl  string                `json:"subscription_url"`
    90  	SvnUrl           string                `json:"svn_url"`
    91  	TagsUrl          string                `json:"tags_url"`
    92  	TeamsUrl         string                `json:"teams_url"`
    93  	TreesUrl         string                `json:"trees_url"`
    94  	UpdatedAt        time.Time             `json:"updated_at"`
    95  	Url              string                `json:"url"`
    96  	Watchers         int                   `json:"watchers"`
    97  	WatchersCount    int                   `json:"watchers_count"`
    98  }
    99  
   100  // Get the currently-authenticated user's repositories.
   101  func (g GitHub) Repositories(options ...int) (repositories []Repository, err error) {
   102  	var uri string
   103  	if len(options) > 0 {
   104  		page := options[0]
   105  		uri = fmt.Sprintf("/user/repos?page=%d", page)
   106  	} else {
   107  		uri = "/user/repos"
   108  	}
   109  
   110  	repositories = make([]Repository, 0)
   111  	err = g.callGithubApi("GET", uri, &repositories)
   112  	return
   113  }
   114  
   115  // Get the user's repositories.
   116  func (u User) Repositories(options ...int) (repositories []Repository, err error) {
   117  	var uri string
   118  	if len(options) > 0 {
   119  		page := options[0]
   120  		uri = fmt.Sprintf("/users/%s/repos?page=%d", u.Login, page)
   121  	} else {
   122  		uri = fmt.Sprintf("/users/%s/repos", u.Login)
   123  	}
   124  
   125  	repositories = make([]Repository, 0)
   126  	err = u.g.callGithubApi("GET", uri, &repositories)
   127  	return
   128  }