Browse Source

minor cleanup

- standardize on "url_" for internal vars rather than "urls" or "url"
- move var definition closer to first use in several tests
- add .gitignore for test binary
Will Norris 13 years ago
parent
commit
83d5c799b3
4 changed files with 38 additions and 34 deletions
  1. +1
    -0
      .gitignore
  2. +22
    -22
      orgs.go
  3. +13
    -10
      repos.go
  4. +2
    -2
      repos_test.go

+ 1
- 0
.gitignore View File

@ -0,0 +1 @@
go-github.test

+ 22
- 22
orgs.go View File

@ -39,13 +39,13 @@ type Team struct {
// List the organizations for a user. Passing the empty string will list // List the organizations for a user. Passing the empty string will list
// organizations for the authenticated user. // organizations for the authenticated user.
func (s *OrganizationsService) List(user string) ([]Organization, error) { func (s *OrganizationsService) List(user string) ([]Organization, error) {
var url string
var url_ string
if user != "" { if user != "" {
url = fmt.Sprintf("users/%v/orgs", user)
url_ = fmt.Sprintf("users/%v/orgs", user)
} else { } else {
url = "user/orgs"
url_ = "user/orgs"
} }
req, err := s.client.NewRequest("GET", url, nil)
req, err := s.client.NewRequest("GET", url_, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -57,8 +57,8 @@ func (s *OrganizationsService) List(user string) ([]Organization, error) {
// Get an organization. // Get an organization.
func (s *OrganizationsService) Get(org string) (*Organization, error) { func (s *OrganizationsService) Get(org string) (*Organization, error) {
url := fmt.Sprintf("orgs/%v", org)
req, err := s.client.NewRequest("GET", url, nil)
url_ := fmt.Sprintf("orgs/%v", org)
req, err := s.client.NewRequest("GET", url_, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -70,8 +70,8 @@ func (s *OrganizationsService) Get(org string) (*Organization, error) {
// Edit an organization. // Edit an organization.
func (s *OrganizationsService) Edit(name string, org *Organization) (*Organization, error) { func (s *OrganizationsService) Edit(name string, org *Organization) (*Organization, error) {
url := fmt.Sprintf("orgs/%v", name)
req, err := s.client.NewRequest("PATCH", url, org)
url_ := fmt.Sprintf("orgs/%v", name)
req, err := s.client.NewRequest("PATCH", url_, org)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -85,8 +85,8 @@ func (s *OrganizationsService) Edit(name string, org *Organization) (*Organizati
// of the organization, this will return concealed and public members, // of the organization, this will return concealed and public members,
// otherwise it will only return public members. // otherwise it will only return public members.
func (s *OrganizationsService) ListMembers(org string) ([]User, error) { func (s *OrganizationsService) ListMembers(org string) ([]User, error) {
url := fmt.Sprintf("orgs/%v/members", org)
req, err := s.client.NewRequest("GET", url, nil)
url_ := fmt.Sprintf("orgs/%v/members", org)
req, err := s.client.NewRequest("GET", url_, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -98,8 +98,8 @@ func (s *OrganizationsService) ListMembers(org string) ([]User, error) {
// List the public members for an organization. // List the public members for an organization.
func (s *OrganizationsService) ListPublicMembers(org string) ([]User, error) { func (s *OrganizationsService) ListPublicMembers(org string) ([]User, error) {
url := fmt.Sprintf("orgs/%v/public_members", org)
req, err := s.client.NewRequest("GET", url, nil)
url_ := fmt.Sprintf("orgs/%v/public_members", org)
req, err := s.client.NewRequest("GET", url_, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -111,8 +111,8 @@ func (s *OrganizationsService) ListPublicMembers(org string) ([]User, error) {
// List the teams for an organization. // List the teams for an organization.
func (s *OrganizationsService) ListTeams(org string) ([]Team, error) { func (s *OrganizationsService) ListTeams(org string) ([]Team, error) {
url := fmt.Sprintf("orgs/%v/teams", org)
req, err := s.client.NewRequest("GET", url, nil)
url_ := fmt.Sprintf("orgs/%v/teams", org)
req, err := s.client.NewRequest("GET", url_, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -124,8 +124,8 @@ func (s *OrganizationsService) ListTeams(org string) ([]Team, error) {
// Add a user to a team. // Add a user to a team.
func (s *OrganizationsService) AddTeamMember(team int, user string) error { func (s *OrganizationsService) AddTeamMember(team int, user string) error {
url := fmt.Sprintf("teams/%v/members/%v", team, user)
req, err := s.client.NewRequest("PUT", url, nil)
url_ := fmt.Sprintf("teams/%v/members/%v", team, user)
req, err := s.client.NewRequest("PUT", url_, nil)
if err != nil { if err != nil {
return err return err
} }
@ -136,8 +136,8 @@ func (s *OrganizationsService) AddTeamMember(team int, user string) error {
// Remove a user from a team. // Remove a user from a team.
func (s *OrganizationsService) RemoveTeamMember(team int, user string) error { func (s *OrganizationsService) RemoveTeamMember(team int, user string) error {
url := fmt.Sprintf("teams/%v/members/%v", team, user)
req, err := s.client.NewRequest("DELETE", url, nil)
url_ := fmt.Sprintf("teams/%v/members/%v", team, user)
req, err := s.client.NewRequest("DELETE", url_, nil)
if err != nil { if err != nil {
return err return err
} }
@ -148,8 +148,8 @@ func (s *OrganizationsService) RemoveTeamMember(team int, user string) error {
// Publicize a user's membership in an organization. // Publicize a user's membership in an organization.
func (s *OrganizationsService) PublicizeMembership(org, user string) error { func (s *OrganizationsService) PublicizeMembership(org, user string) error {
url := fmt.Sprintf("orgs/%v/public_members/%v", org, user)
req, err := s.client.NewRequest("PUT", url, nil)
url_ := fmt.Sprintf("orgs/%v/public_members/%v", org, user)
req, err := s.client.NewRequest("PUT", url_, nil)
if err != nil { if err != nil {
return err return err
} }
@ -160,8 +160,8 @@ func (s *OrganizationsService) PublicizeMembership(org, user string) error {
// Conceal a user's membership in an organization. // Conceal a user's membership in an organization.
func (s *OrganizationsService) ConcealMembership(org, user string) error { func (s *OrganizationsService) ConcealMembership(org, user string) error {
url := fmt.Sprintf("orgs/%v/public_members/%v", org, user)
req, err := s.client.NewRequest("DELETE", url, nil)
url_ := fmt.Sprintf("orgs/%v/public_members/%v", org, user)
req, err := s.client.NewRequest("DELETE", url_, nil)
if err != nil { if err != nil {
return err return err
} }


+ 13
- 10
repos.go View File

@ -49,11 +49,11 @@ type RepositoryListOptions struct {
// List the repositories for a user. Passing the empty string will list // List the repositories for a user. Passing the empty string will list
// repositories for the authenticated user. // repositories for the authenticated user.
func (s *RepositoriesService) List(user string, opt *RepositoryListOptions) ([]Repository, error) { func (s *RepositoriesService) List(user string, opt *RepositoryListOptions) ([]Repository, error) {
var urls string
var url_ string
if user != "" { if user != "" {
urls = fmt.Sprintf("users/%v/repos", user)
url_ = fmt.Sprintf("users/%v/repos", user)
} else { } else {
urls = "user/repos"
url_ = "user/repos"
} }
if opt != nil { if opt != nil {
params := url.Values{ params := url.Values{
@ -62,10 +62,13 @@ func (s *RepositoriesService) List(user string, opt *RepositoryListOptions) ([]R
"direction": []string{opt.Direction}, "direction": []string{opt.Direction},
"page": []string{strconv.Itoa(opt.Page)}, "page": []string{strconv.Itoa(opt.Page)},
} }
urls += "?" + params.Encode()
url_ += "?" + params.Encode()
} }
req, err := s.client.NewRequest("GET", urls, nil)
req, err := s.client.NewRequest("GET", url_, nil)
if err != nil {
return nil, err
}
repos := new([]Repository) repos := new([]Repository)
_, err = s.client.Do(req, repos) _, err = s.client.Do(req, repos)
@ -85,16 +88,16 @@ type RepositoryListByOrgOptions struct {
// List the repositories for an organization. // List the repositories for an organization.
func (s *RepositoriesService) ListByOrg(org string, opt *RepositoryListByOrgOptions) ([]Repository, error) { func (s *RepositoriesService) ListByOrg(org string, opt *RepositoryListByOrgOptions) ([]Repository, error) {
urls := fmt.Sprintf("orgs/%v/repos", org)
url_ := fmt.Sprintf("orgs/%v/repos", org)
if opt != nil { if opt != nil {
params := url.Values{ params := url.Values{
"type": []string{opt.Type}, "type": []string{opt.Type},
"page": []string{strconv.Itoa(opt.Page)}, "page": []string{strconv.Itoa(opt.Page)},
} }
urls += "?" + params.Encode()
url_ += "?" + params.Encode()
} }
req, err := s.client.NewRequest("GET", urls, nil)
req, err := s.client.NewRequest("GET", url_, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -106,8 +109,8 @@ func (s *RepositoriesService) ListByOrg(org string, opt *RepositoryListByOrgOpti
// Get fetches a repository. // Get fetches a repository.
func (s *RepositoriesService) Get(owner, repo string) (*Repository, error) { func (s *RepositoriesService) Get(owner, repo string) (*Repository, error) {
url := fmt.Sprintf("repos/%v/%v", owner, repo)
req, err := s.client.NewRequest("GET", url, nil)
url_ := fmt.Sprintf("repos/%v/%v", owner, repo)
req, err := s.client.NewRequest("GET", url_, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }


+ 2
- 2
repos_test.go View File

@ -39,7 +39,6 @@ func TestRepositoriesService_List_specifiedUser(t *testing.T) {
setup() setup()
defer teardown() defer teardown()
opt := &RepositoryListOptions{"owner", "created", "asc", 2}
mux.HandleFunc("/users/u/repos", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/users/u/repos", func(w http.ResponseWriter, r *http.Request) {
var v string var v string
if r.Method != "GET" { if r.Method != "GET" {
@ -61,6 +60,7 @@ func TestRepositoriesService_List_specifiedUser(t *testing.T) {
fmt.Fprint(w, `[{"id":1}]`) fmt.Fprint(w, `[{"id":1}]`)
}) })
opt := &RepositoryListOptions{"owner", "created", "asc", 2}
repos, err := client.Repositories.List("u", opt) repos, err := client.Repositories.List("u", opt)
if err != nil { if err != nil {
t.Errorf("Repositories.List returned error: %v", err) t.Errorf("Repositories.List returned error: %v", err)
@ -76,7 +76,6 @@ func TestRepositoriesService_ListByOrg(t *testing.T) {
setup() setup()
defer teardown() defer teardown()
opt := &RepositoryListByOrgOptions{"forks", 2}
mux.HandleFunc("/orgs/o/repos", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/orgs/o/repos", func(w http.ResponseWriter, r *http.Request) {
if r.Method != "GET" { if r.Method != "GET" {
t.Errorf("Request method = %v, want %v", r.Method, "GET") t.Errorf("Request method = %v, want %v", r.Method, "GET")
@ -92,6 +91,7 @@ func TestRepositoriesService_ListByOrg(t *testing.T) {
fmt.Fprint(w, `[{"id":1}]`) fmt.Fprint(w, `[{"id":1}]`)
}) })
opt := &RepositoryListByOrgOptions{"forks", 2}
repos, err := client.Repositories.ListByOrg("o", opt) repos, err := client.Repositories.ListByOrg("o", opt)
if err != nil { if err != nil {
t.Errorf("Repositories.ListByOrg returned error: %v", err) t.Errorf("Repositories.ListByOrg returned error: %v", err)


Loading…
Cancel
Save