func (r *Router) URLToRepoSearch(repoPath string, at vcs.CommitID, opt vcs.SearchOptions) *url.URL { u := r.URLTo(RouteRepoSearch, "RepoPath", repoPath, "CommitID", string(at)) q, err := query.Values(opt) if err != nil { panic(err.Error()) } u.RawQuery = q.Encode() return u }
func (r *Router) URLToRepoCommits(repoPath string, opt vcs.CommitsOptions) *url.URL { u := r.URLTo(RouteRepoCommits, "RepoPath", repoPath) q, err := query.Values(opt) if err != nil { panic(err.Error()) } u.RawQuery = q.Encode() return u }
func (r *Router) URLToRepoCrossRepoDiff(baseRepoPath string, base vcs.CommitID, headRepoPath string, head vcs.CommitID, opt *vcs.DiffOptions) *url.URL { u := r.URLTo(RouteRepoCrossRepoDiff, "RepoPath", baseRepoPath, "Base", string(base), "HeadRepoPath", headRepoPath, "Head", string(head)) if opt != nil { q, err := query.Values(opt) if err != nil { panic(err.Error()) } u.RawQuery = q.Encode() } return u }
func (r *Router) URLToRepoBlameFile(repoPath string, path string, opt *vcs.BlameOptions) *url.URL { u := r.URLTo(RouteRepoBlameFile, "RepoPath", repoPath, "Path", path) if opt != nil { q, err := query.Values(opt) if err != nil { panic(err.Error()) } u.RawQuery = q.Encode() } return u }
// addOptions adds the parameters in opt as URL query parameters to u. opt // must be a struct whose fields may contain "url" tags. func addOptions(u *url.URL, opt interface{}) error { v := reflect.ValueOf(opt) if v.Kind() == reflect.Ptr && v.IsNil() { return nil } qs, err := query.Values(opt) if err != nil { return err } u.RawQuery = qs.Encode() return nil }
// addOptions adds the parameters in opt as URL query parameters to s. opt // must be a struct whose fields may contain "url" tags. func addOptions(s string, opt interface{}) (string, error) { v := reflect.ValueOf(opt) if v.Kind() == reflect.Ptr && v.IsNil() { return s, nil } u, err := url.Parse(s) if err != nil { return s, err } qs, err := query.Values(opt) if err != nil { return s, err } u.RawQuery = qs.Encode() return u.String(), nil }
// Helper function that executes search queries against different // GitHub search types (repositories, code, issues, users) func (s *SearchService) search(searchType string, query string, opt *SearchOptions, result interface{}) (*Response, error) { params, err := qs.Values(opt) if err != nil { return nil, err } params.Add("q", query) u := fmt.Sprintf("search/%s?%s", searchType, params.Encode()) req, err := s.client.NewRequest("GET", u, nil) if err != nil { return nil, err } if opt.TextMatch { // Accept header defaults to "application/vnd.github.v3+json" // We change it here to fetch back text-match metadata req.Header.Set("Accept", "application/vnd.github.v3.text-match+json") } return s.client.Do(req, result) }