Skip to content

Commit 58e9ef9

Browse files
use getrolename instead of permission mapping func (integrations#1192)
Co-authored-by: Keegan Campbell <me@kfcampbell.com>
1 parent f44d60f commit 58e9ef9

File tree

5 files changed

+9
-49
lines changed

5 files changed

+9
-49
lines changed

github/data_source_github_collaborators.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,7 @@ func flattenGitHubCollaborators(collaborators []*github.User) ([]interface{}, er
179179
result["received_events_url"] = c.GetReceivedEventsURL()
180180
result["type"] = c.GetType()
181181
result["site_admin"] = c.GetSiteAdmin()
182-
183-
permissionName, err := getRepoPermission(c.GetPermissions())
184-
if err != nil {
185-
return nil, err
186-
}
187-
188-
result["permission"] = permissionName
182+
result["permission"] = c.GetRoleName()
189183
results = append(results, result)
190184
}
191185

github/resource_github_repository_collaborator.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@ func resourceGithubRepositoryCollaborator() *schema.Resource {
3535
ForceNew: true,
3636
},
3737
"permission": {
38-
Type: schema.TypeString,
39-
Optional: true,
40-
ForceNew: true,
41-
Default: "push",
42-
ValidateFunc: validateValueFunc([]string{"pull", "triage", "push", "maintain", "admin"}),
38+
Type: schema.TypeString,
39+
Optional: true,
40+
ForceNew: true,
41+
Default: "push",
4342
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
4443
if d.Get("permission_diff_suppression").(bool) {
4544
if new == "triage" || new == "maintain" {
@@ -141,14 +140,9 @@ func resourceGithubRepositoryCollaboratorRead(d *schema.ResourceData, meta inter
141140

142141
for _, c := range collaborators {
143142
if strings.EqualFold(c.GetLogin(), username) {
144-
permissionName, err := getRepoPermission(c.GetPermissions())
145-
if err != nil {
146-
return err
147-
}
148-
149143
d.Set("repository", repoName)
150144
d.Set("username", c.GetLogin())
151-
d.Set("permission", permissionName)
145+
d.Set("permission", c.GetRoleName())
152146
return nil
153147
}
154148
}

github/resource_github_team_repository.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,7 @@ func resourceGithubTeamRepositoryRead(d *schema.ResourceData, meta interface{})
131131
d.Set("team_id", teamIdString)
132132
}
133133
d.Set("repository", repo.GetName())
134-
135-
permName, permErr := getRepoPermission(repo.GetPermissions())
136-
if permErr != nil {
137-
return permErr
138-
}
139-
140-
d.Set("permission", permName)
134+
d.Set("permission", repo.GetRoleName())
141135

142136
return nil
143137
}

github/util_permissions.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package github
22

33
import (
4-
"errors"
54
"fmt"
65

76
"github.com/google/go-github/v45/github"
@@ -17,27 +16,6 @@ const (
1716
readPermission string = "read"
1817
)
1918

20-
func getRepoPermission(p map[string]bool) (string, error) {
21-
22-
// Permissions are returned in this map format such that if you have a certain level
23-
// of permission, all levels below are also true. For example, if a team has push
24-
// permission, the map will be: {"pull": true, "push": true, "admin": false}
25-
if (p)[adminPermission] {
26-
return adminPermission, nil
27-
} else if (p)[maintainPermission] {
28-
return maintainPermission, nil
29-
} else if (p)[pushPermission] {
30-
return pushPermission, nil
31-
} else if (p)[triagePermission] {
32-
return triagePermission, nil
33-
} else {
34-
if (p)[pullPermission] {
35-
return pullPermission, nil
36-
}
37-
return "", errors.New("At least one permission expected from permissions map.")
38-
}
39-
}
40-
4119
func getInvitationPermission(i *github.RepositoryInvitation) (string, error) {
4220
// Permissions for some GitHub API routes are expressed as "read",
4321
// "write", and "admin"; in other places, they are expressed as "pull",

website/docs/r/repository_collaborator.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ The following arguments are supported:
4444
* `repository` - (Required) The GitHub repository
4545
* `username` - (Required) The user to add to the repository as a collaborator.
4646
* `permission` - (Optional) The permission of the outside collaborator for the repository.
47-
Must be one of `pull`, `push`, `maintain`, `triage` or `admin` for organization-owned repositories.
47+
Must be one of `pull`, `push`, `maintain`, `triage` or `admin` or the name of an existing [custom repository role](https://docs.github.com/en/enterprise-cloud@latest/organizations/managing-peoples-access-to-your-organization-with-roles/managing-custom-repository-roles-for-an-organization) within the organization for organization-owned repositories.
4848
Must be `push` for personal repositories. Defaults to `push`.
4949
* `permission_diff_suppression` - (Optional) Suppress plan diffs for `triage` and `maintain`. Defaults to `false`.
5050

@@ -60,4 +60,4 @@ GitHub Repository Collaborators can be imported using an ID made up of `reposito
6060

6161
```
6262
$ terraform import github_repository_collaborator.collaborator terraform:someuser
63-
```
63+
```

0 commit comments

Comments
 (0)