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
// organizations for the authenticated user.
func (s *OrganizationsService) List(user string) ([]Organization, error) {
var url string
var url_ string
if user != "" {
url = fmt.Sprintf("users/%v/orgs", user)
url_ = fmt.Sprintf("users/%v/orgs", user)
} 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 {
return nil, err
}
@ -57,8 +57,8 @@ func (s *OrganizationsService) List(user string) ([]Organization, error) {
// Get an organization.
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 {
return nil, err
}
@ -70,8 +70,8 @@ func (s *OrganizationsService) Get(org string) (*Organization, error) {
// Edit an organization.
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 {
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,
// otherwise it will only return public members.
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 {
return nil, err
}
@ -98,8 +98,8 @@ func (s *OrganizationsService) ListMembers(org string) ([]User, error) {
// List the public members for an organization.
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 {
return nil, err
}
@ -111,8 +111,8 @@ func (s *OrganizationsService) ListPublicMembers(org string) ([]User, error) {
// List the teams for an organization.
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 {
return nil, err
}
@ -124,8 +124,8 @@ func (s *OrganizationsService) ListTeams(org string) ([]Team, error) {
// Add a user to a team.
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 {
return err
}
@ -136,8 +136,8 @@ func (s *OrganizationsService) AddTeamMember(team int, user string) error {
// Remove a user from a team.
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 {
return err
}
@ -148,8 +148,8 @@ func (s *OrganizationsService) RemoveTeamMember(team int, user string) error {
// Publicize a user's membership in an organization.
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 {
return err
}
@ -160,8 +160,8 @@ func (s *OrganizationsService) PublicizeMembership(org, user string) error {
// Conceal a user's membership in an organization.
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 {
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
// repositories for the authenticated user.
func (s *RepositoriesService) List(user string, opt *RepositoryListOptions) ([]Repository, error) {
var urls string
var url_ string
if user != "" {
urls = fmt.Sprintf("users/%v/repos", user)
url_ = fmt.Sprintf("users/%v/repos", user)
} else {
urls = "user/repos"
url_ = "user/repos"
}
if opt != nil {
params := url.Values{
@ -62,10 +62,13 @@ func (s *RepositoriesService) List(user string, opt *RepositoryListOptions) ([]R
"direction": []string{opt.Direction},
"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)
_, err = s.client.Do(req, repos)
@ -85,16 +88,16 @@ type RepositoryListByOrgOptions struct {
// List the repositories for an organization.
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 {
params := url.Values{
"type": []string{opt.Type},
"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
}
@ -106,8 +109,8 @@ func (s *RepositoriesService) ListByOrg(org string, opt *RepositoryListByOrgOpti
// Get fetches a repository.
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 {
return nil, err
}


+ 2
- 2
repos_test.go View File

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


Loading…
Cancel
Save