Repository: google/go-github
Pull request #1864 (2021-05-06 04:11:11)

Add permissions to teams
This PR addresses https://github.com/google/go-github/issues/1863 by adding a Permissions field to the Team type.

google-cla[bot]: 
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: **Please visit <https://cla.developers.google.com/> to sign.**

Once you've signed (or fixed any issues), please reply here with `@googlebot I signed it!` and we'll verify it.

----

#### What to do if you already signed the CLA

##### Individual signers

*   It's possible we don't have your GitHub username or you're using a different email address on your commit. Check [your existing CLA data](https://cla.developers.google.com/clas) and verify that your [email is set on your git commits](https://help.github.com/articles/setting-your-email-in-git/).

##### Corporate signers

*   Your company has a Point of Contact who decides which employees are authorized to participate. Ask your POC to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the Google project maintainer to [go/cla#troubleshoot](http://go/cla#troubleshoot) ([Public version](https://opensource.google/docs/cla/#troubleshoot)).
*   The email used to register you as an authorized contributor must be the email used for the Git commit. Check [your existing CLA data](https://cla.developers.google.com/clas) and verify that your [email is set on your git commits](https://help.github.com/articles/setting-your-email-in-git/).
*   The email used to register you as an authorized contributor must also be [attached to your GitHub account](https://github.com/settings/emails).
		

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

<!-- need_sender_cla -->
derekjobst: @googlebot I signed it!
gmlewis: Also, please make sure to run `go generate ./...` as described in our `CONTRIBUTING.md` guide.
gmlewis: You will want to commit/push (not force-push) the changes to the PR once you run `go generate ./...`.
gmlewis: Hmmm... it looks like my `go generate ./...` code is breaking the tests... sorry about that @derekjobst - let me investigate.
derekjobst: I got caught up on [Stringify](https://github.com/derekjobst/go-github/blob/5c30ef9f9382b5cfea673c8d837d8032bdd5e6b2/github/teams.go#L59) returning a string with the empty Permissions{} in it when Team is converted to a string.

This was easy to fix in [strings_test](https://github.com/derekjobst/go-github/blob/5c30ef9f9382b5cfea673c8d837d8032bdd5e6b2/github/strings_test.go#L126), but the auto-generated github-stringify tests for `TestTeam_String` refer to a parent team, which does not include the empty Permissions in the string.

It seems like the best solution might be to have the [stringifyValue](https://github.com/derekjobst/go-github/blob/5c30ef9f9382b5cfea673c8d837d8032bdd5e6b2/github/strings.go#L30) function in strings.go omit empty Permissions.
derekjobst: I've reverted the pointer change to get tests passing — happy to change back if we'd like to change the stringify methods
codecov[bot]: # [Codecov](https://codecov.io/gh/google/go-github/pull/1864?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) Report
> Merging [#1864](https://codecov.io/gh/google/go-github/pull/1864?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (66fa351) into [master](https://codecov.io/gh/google/go-github/commit/b1b5e4e9d0ebffbb88e5c19958c87462fb94f169?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (b1b5e4e) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/google/go-github/pull/1864/graphs/tree.svg?width=650&height=150&src=pr&token=EgYjGjZlI0&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google)](https://codecov.io/gh/google/go-github/pull/1864?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google)

```diff
@@           Coverage Diff           @@
##           master    #1864   +/-   ##
=======================================
  Coverage   97.65%   97.65%           
=======================================
  Files         105      105           
  Lines        6769     6769           
=======================================
  Hits         6610     6610           
  Misses         86       86           
  Partials       73       73           
```


| [Impacted Files](https://codecov.io/gh/google/go-github/pull/1864?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) | Coverage Δ | |
|---|---|---|
| [github/teams.go](https://codecov.io/gh/google/go-github/pull/1864/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google#diff-Z2l0aHViL3RlYW1zLmdv) | `98.09% <ø> (ø)` | |

------

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

gmlewis: > I've reverted the pointer change to get tests passing — happy to change back if we'd like to change the stringify methods

OK, excellent.   I've gone ahead and created #1865 and #1866 to address this.

Patch:
diff --git a/github/github-accessors.go b/github/github-accessors.go
index 37ddb180..08108341 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -14276,6 +14276,14 @@ func (t *Team) GetPermission() string {
 	return *t.Permission
 }
 
+// GetPermissions returns the Permissions field if it's non-nil, zero value otherwise.
+func (t *Team) GetPermissions() map[string]bool {
+	if t == nil || t.Permissions == nil {
+		return map[string]bool{}
+	}
+	return *t.Permissions
+}
+
 // GetPrivacy returns the Privacy field if it's non-nil, zero value otherwise.
 func (t *Team) GetPrivacy() string {
 	if t == nil || t.Privacy == nil {
diff --git a/github/teams.go b/github/teams.go
index 592a11fd..2e1cd3da 100644
--- a/github/teams.go
+++ b/github/teams.go
@@ -32,6 +32,10 @@ type Team struct {
 	// Permission specifies the default permission for repositories owned by the team.
 	Permission *string `json:"permission,omitempty"`
 
+	// Permissions identifies the permissions that a team has on a given
+	// repository. This is only populated when calling Repositories.ListTeams.
+	Permissions *map[string]bool `json:"permissions,omitempty"`
+
 	// Privacy identifies the level of privacy this team should have.
 	// Possible values are:
 	//     secret - only visible to organization owners and members of this team


Test patch:
diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go
index 3da8dda1..49ceb123 100644
--- a/github/github-accessors_test.go
+++ b/github/github-accessors_test.go
@@ -16730,6 +16730,16 @@ func TestTeam_GetPermission(tt *testing.T) {
 	t.GetPermission()
 }
 
+func TestTeam_GetPermissions(tt *testing.T) {
+	var zeroValue map[string]bool
+	t := &Team{Permissions: &zeroValue}
+	t.GetPermissions()
+	t = &Team{}
+	t.GetPermissions()
+	t = nil
+	t.GetPermissions()
+}
+
 func TestTeam_GetPrivacy(tt *testing.T) {
 	var zeroValue string
 	t := &Team{Privacy: &zeroValue}