Repository: google/go-github
Pull request #1171 (2019-05-16 14:44:07)

Add GetTeamBySlug methods in teamsService
Add a method to call the following endpoint
https://developer.github.com/v3/teams/#get-team-by-name

codecov[bot]: # [Codecov](https://codecov.io/gh/google/go-github/pull/1171?src=pr&el=h1) Report
> Merging [#1171](https://codecov.io/gh/google/go-github/pull/1171?src=pr&el=desc) into [master](https://codecov.io/gh/google/go-github/commit/901030391ab7f418a984389fd3f8f65e39e5c823?src=pr&el=desc) will **decrease** coverage by `0.01%`.
> The diff coverage is `60%`.

[![Impacted file tree graph](https://codecov.io/gh/google/go-github/pull/1171/graphs/tree.svg?width=650&token=EgYjGjZlI0&height=150&src=pr)](https://codecov.io/gh/google/go-github/pull/1171?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #1171      +/-   ##
==========================================
- Coverage    70.2%   70.19%   -0.02%     
==========================================
  Files          84       84              
  Lines        5844     5854      +10     
==========================================
+ Hits         4103     4109       +6     
- Misses        954      956       +2     
- Partials      787      789       +2
```


| [Impacted Files](https://codecov.io/gh/google/go-github/pull/1171?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [github/teams.go](https://codecov.io/gh/google/go-github/pull/1171/diff?src=pr&el=tree#diff-Z2l0aHViL3RlYW1zLmdv) | `69.49% <60%> (-0.57%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/google/go-github/pull/1171?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/google/go-github/pull/1171?src=pr&el=footer). Last update [9010303...4392098](https://codecov.io/gh/google/go-github/pull/1171?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

adrienzieba: I signed it!
gmlewis: Hi @willnorris, when you get a chance, can you please check the status of the corporate CLA mentioned above?  Also, just FYI... I will be OOO for one week starting tomorrow without internet access, so feel free to moderate as you see fit. @gauntface - just FYI for you too. Thanks!
adrienzieba: CLA should be good now
googlebot: CLAs look good, thanks!

ℹ️ **Googlers: [Go here](https://goto.google.com/prinfo/https%3A%2F%2Fgithub.com%2Fgoogle%2Fgo-github%2Fpull%2F1171) for more info**.

<!-- ok -->
adrienzieba: Any update ?
gmlewis: @gauntface - do you have an opinion about my [comment above](https://github.com/google/go-github/pull/1171#discussion_r285317230)?
gmlewis: No problem, @gauntface! We greatly appreciate all your awesome reviews!
Merging.

Patch:
diff --git a/github/teams.go b/github/teams.go
index dcf619ab..a8247a3b 100644
--- a/github/teams.go
+++ b/github/teams.go
@@ -121,6 +121,25 @@ func (s *TeamsService) GetTeam(ctx context.Context, team int64) (*Team, *Respons
 	return t, resp, nil
 }
 
+// GetTeamBySlug fetches a team by slug.
+//
+// GitHub API docs: https://developer.github.com/v3/teams/#get-team-by-name
+func (s *TeamsService) GetTeamBySlug(ctx context.Context, org, slug string) (*Team, *Response, error) {
+	u := fmt.Sprintf("orgs/%v/teams/%v", org, slug)
+	req, err := s.client.NewRequest("GET", u, nil)
+	if err != nil {
+		return nil, nil, err
+	}
+
+	t := new(Team)
+	resp, err := s.client.Do(ctx, req, t)
+	if err != nil {
+		return nil, resp, err
+	}
+
+	return t, resp, nil
+}
+
 // NewTeam represents a team to be created or modified.
 type NewTeam struct {
 	Name         string   `json:"name"` // Name of the team. (Required.)


Test patch:
diff --git a/github/teams_test.go b/github/teams_test.go
index fbd8130f..84514ee9 100644
--- a/github/teams_test.go
+++ b/github/teams_test.go
@@ -92,6 +92,55 @@ func TestTeamsService_GetTeam_nestedTeams(t *testing.T) {
 	}
 }
 
+func TestTeamsService_GetTeamBySlug(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	mux.HandleFunc("/orgs/o/teams/s", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "GET")
+		fmt.Fprint(w, `{"id":1, "name":"n", "description": "d", "url":"u", "slug": "s", "permission":"p", "ldap_dn":"cn=n,ou=groups,dc=example,dc=com", "parent":null}`)
+	})
+
+	team, _, err := client.Teams.GetTeamBySlug(context.Background(), "o", "s")
+	if err != nil {
+		t.Errorf("Teams.GetTeamBySlug returned error: %v", err)
+	}
+
+	want := &Team{ID: Int64(1), Name: String("n"), Description: String("d"), URL: String("u"), Slug: String("s"), Permission: String("p"), LDAPDN: String("cn=n,ou=groups,dc=example,dc=com")}
+	if !reflect.DeepEqual(team, want) {
+		t.Errorf("Teams.GetTeamBySlug returned %+v, want %+v", team, want)
+	}
+}
+
+func TestTeamsService_GetTeamBySlug_invalidOrg(t *testing.T) {
+	client, _, _, teardown := setup()
+	defer teardown()
+
+	_, _, err := client.Teams.GetTeamBySlug(context.Background(), "%", "s")
+	testURLParseError(t, err)
+}
+
+func TestTeamsService_GetTeamBySlug_notFound(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	mux.HandleFunc("/orgs/o/teams/s", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "GET")
+		w.WriteHeader(http.StatusNotFound)
+	})
+
+	team, resp, err := client.Teams.GetTeamBySlug(context.Background(), "o", "s")
+	if err == nil {
+		t.Errorf("Expected HTTP 404 response")
+	}
+	if got, want := resp.Response.StatusCode, http.StatusNotFound; got != want {
+		t.Errorf("Teams.GetTeamBySlug returned status %d, want %d", got, want)
+	}
+	if team != nil {
+		t.Errorf("Teams.GetTeamBySlug returned %+v, want nil", team)
+	}
+}
+
 func TestTeamsService_CreateTeam(t *testing.T) {
 	client, mux, _, teardown := setup()
 	defer teardown()