func (client *Client) CreateRepository(project *Project, description, homepage string, isPrivate bool) (repo *octokit.Repository, err error) { var repoURL octokit.Hyperlink if project.Owner != client.Host.User { repoURL = octokit.OrgRepositoriesURL } else { repoURL = octokit.UserRepositoriesURL } url, err := repoURL.Expand(octokit.M{"org": project.Owner}) if err != nil { return } api, err := client.api() if err != nil { err = FormatError("creating repository", err) return } params := octokit.Repository{ Name: project.Name, Description: description, Homepage: homepage, Private: isPrivate, } repo, result := api.Repositories(client.requestURL(url)).Create(params) if result.HasError() { err = FormatError("creating repository", result.Err) return } return }
func releaseRequest(owner, name, etag string, uri octokit.Hyperlink, output interface{}) (result *octokit.Result, respEtag string) { params := repoParams(owner, name) url, err := uri.Expand(params) if err != nil { return &octokit.Result{Err: err}, "" } result, respEtag = sendRequest(url, func(req *octokit.Request) (*octokit.Response, error) { req.Header.Set(noneMatchKey, etag) return req.Get(output) }) return }
func (repo *GitHubRepository) expandURL(link octokit.Hyperlink, state, sort string) (*url.URL, error) { queryParams := map[string]string{ "sort": sort, "direction": "asc", "state": state, "per_page": "100", } u, err := link.Expand(octokit.M{"owner": repo.Owner, "repo": repo.Name}) if err != nil { return nil, err } q := u.Query() for k, v := range queryParams { q.Set(k, v) } u.RawQuery = q.Encode() return u, nil }