Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: find correct permission #1230

Closed
wants to merge 66 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
1bd34d6
Add only_protected_branches in data source github_repository (#1162)
bpaquet Jul 15, 2022
5f1a989
Remove mistakenly committed binary (#1223)
kfcampbell Jul 18, 2022
ce4c046
Revert PR #1162 (#1224)
kfcampbell Jul 18, 2022
420a34d
Revert "Revert PR #1162 (#1224)"
Jul 22, 2022
f419d7a
find correct permission
Jul 22, 2022
82cd6da
fix: remove dead code
Jul 22, 2022
10af5f2
Replaying the changes in #1162 without the binary (#1234)
kfcampbell Jul 28, 2022
d544bbc
Revert 754d73f66bd3b5da49d5f3e0714a4186d40d0377 (#1235)
kfcampbell Jul 28, 2022
942e965
Add default binary name to .gitignore (#1237)
kfcampbell Jul 28, 2022
b732b01
Add note deprecating changelog (#1254)
kfcampbell Aug 10, 2022
86e4b44
Switch to Go1.19 in CI check (#1256)
kfcampbell Aug 15, 2022
6b9e025
Create data source for external groups (#1185)
kfcampbell Aug 16, 2022
2c15b55
Support github_team_members role edits (#1216)
csainty Aug 23, 2022
772c71b
Add membership_type to data.github_team (#1242)
bpaquet Aug 26, 2022
b60a8af
Bump go-github to v46.0.0 (#1258)
gesellix Aug 30, 2022
c753688
feat(github_ip_ranges): support for Web and API IP Ranges (#1220)
Jamian Aug 30, 2022
cb52c61
Bump go-github to v47 (#1269)
kfcampbell Aug 30, 2022
cbb3d7e
Add support for default merge commit params (#1263)
garrettheel Aug 30, 2022
1f14bb2
Bump to v1.17.2 (#1272)
kfcampbell Sep 1, 2022
6119318
Bump non-Terraform dependencies. (#1274)
kfcampbell Sep 6, 2022
dbda9b9
Refactor out branches attribute to new data source (#1117)
k24dizzle Sep 6, 2022
91e9a78
[Feature] New datasource github_repository_teams (#1244)
bpaquet Sep 7, 2022
0b103e6
Small README cleanup (#1282)
kfcampbell Sep 13, 2022
6fb72e3
Small issue docs fix (#1285)
kfcampbell Sep 13, 2022
0ba3d4b
Initial commit of bumping version number to v5 (#1288)
kfcampbell Sep 14, 2022
ce9a54a
Feature github_repository_tag_protection closes#1250 (#1283)
kuhlman-labs Sep 16, 2022
9e522d6
[Feature] Add data source to read secrets (#1245)
bpaquet Sep 16, 2022
06054eb
Remove scripts/changelog-links.sh (#1291)
kfcampbell Sep 16, 2022
fcef86f
Remove gogetcookie.sh (#1292)
kfcampbell Sep 19, 2022
3724f74
Set `node_id` in `github_organization` data source (#1277)
douglascayers Sep 19, 2022
aaf1a88
Create data source for organization ip allow list (#1275)
douglascayers Sep 20, 2022
759426b
Adding resource github_organization_settings to provider closes#1125 …
kuhlman-labs Sep 21, 2022
6773d80
Allow to get only protected on non protected branch with github_repos…
bpaquet Sep 23, 2022
9d58e1d
Fix `github_repository_file`: Disable default compute of author and e…
pawnu Oct 10, 2022
553785b
feat(branch-protection): Push/Reviewer actors can be specified by nam…
dion-gionet Oct 12, 2022
25f682b
fix: `github_dependabot_organization_secret` panic (#1323)
nikolay Oct 12, 2022
ae05952
Fix doc of github_dependabot_secrets (#1297)
bpaquet Oct 13, 2022
2b22c64
Lowercase error strings (#1329)
kfcampbell Oct 13, 2022
0080e4a
Add datasource: github_repository_deploy_keys (#1299)
bpaquet Oct 13, 2022
ad2193c
Add data source organization webhooks and repository webhooks (#1300)
bpaquet Oct 13, 2022
05a8875
Revert PR #1020 to undo performance regression as reported in #1328 (…
kfcampbell Oct 13, 2022
f3640e6
Update github_organization_settings to only need RO permissions at pl…
avgalani Oct 24, 2022
3083e4c
Initial commit of advice about searching for prior work in repo befor…
kfcampbell Oct 26, 2022
7dfb5d2
Suppress plan diff when github_repository changes to archived (#1326)
kangaechu Oct 27, 2022
156b7ea
fix(branch-protection): Use more efficient function to fetch actors (…
dion-gionet Oct 27, 2022
49795e1
feat: allow_update_branch argument (#1143)
strantalis Oct 27, 2022
27ed4c2
Correct docs to match code state (#1346)
kfcampbell Oct 27, 2022
13e9384
Create data source for github app (#1268)
g-chouzadjian Oct 27, 2022
abe26d0
Bump go-github to v48 (#1347)
kfcampbell Oct 27, 2022
99dd636
Add support for a summary view of org teams. (#1176)
david-bain Oct 31, 2022
f7da074
Add support for repository alphanumeric autolinks (Fixes #1270) (#1314)
douglascayers Oct 31, 2022
76bcc17
Merge branch 'main' into custom-roles
nickfloyd Nov 1, 2022
6bbcfdd
Initial commit of standardized templates
kfcampbell Nov 4, 2022
690a093
[maint] Add standardized issue templates
nickfloyd Nov 7, 2022
bbc334c
feat: closes #862 by adding a state attribute for the state of the in…
wwsean08 Nov 8, 2022
ffd6f0a
Add release assets (#1195)
shabbyrobe Nov 8, 2022
1b851ad
Include All Branches in template repositories (#1353)
kfcampbell Nov 8, 2022
baafae0
Fix asserts_url typo (#1194)
shabbyrobe Nov 8, 2022
fc51853
new resource: github_actions_repository_permissions (#1339)
fatmcgav-depop Nov 10, 2022
c2d19be
feat: add pull_request_template.md PR template (#1354)
nickfloyd Nov 14, 2022
0602774
Add only_protected_branches in data source github_repository (#1162)
bpaquet Jul 15, 2022
5cd82f6
Remove mistakenly committed binary (#1223)
kfcampbell Jul 18, 2022
3c93cdb
find correct permission
Jul 22, 2022
10c5bc9
fix: remove dead code
Jul 22, 2022
d212ebf
Revert "Revert PR #1162 (#1224)"
Jul 22, 2022
ac9e797
Merge branch 'custom-roles' of github.com:joshua-hancox/terraform-pro…
nickfloyd Nov 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion github/data_source_github_collaborators.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func flattenGitHubCollaborators(collaborators []*github.User) ([]interface{}, er
result["received_events_url"] = c.GetReceivedEventsURL()
result["type"] = c.GetType()
result["site_admin"] = c.GetSiteAdmin()
result["permission"] = c.GetRoleName()
result["permission"] = getInvitationPermission(c.GetRoleName())
results = append(results, result)
}

Expand Down
12 changes: 11 additions & 1 deletion github/data_source_github_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ func dataSourceGithubRepository() *schema.Resource {
Computed: true,
ConflictsWith: []string{"full_name"},
},
"only_protected_branches": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},

"description": {
Type: schema.TypeString,
Expand Down Expand Up @@ -242,7 +247,12 @@ func dataSourceGithubRepositoryRead(d *schema.ResourceData, meta interface{}) er
d.Set("repo_id", repo.GetID())
d.Set("has_projects", repo.GetHasProjects())

branches, _, err := client.Repositories.ListBranches(context.TODO(), owner, repoName, nil)
onlyProtectedBranches := d.Get("only_protected_branches").(bool)
listBranchOptions := &github.BranchListOptions{
Protected: &onlyProtectedBranches,
}

branches, _, err := client.Repositories.ListBranches(context.TODO(), owner, repoName, listBranchOptions)
if err != nil {
return err
}
Expand Down
13 changes: 7 additions & 6 deletions github/resource_github_repository_collaborator.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ func resourceGithubRepositoryCollaborator() *schema.Resource {
ForceNew: true,
},
"permission": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: "push",
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: "push",
ValidateFunc: validateValueFunc([]string{"pull", "triage", "push", "maintain", "admin"}),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The addition of this ValidateFunc means that custom roles can no longer be used, correct?

DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
if d.Get("permission_diff_suppression").(bool) {
if new == "triage" || new == "maintain" {
Expand Down Expand Up @@ -114,7 +115,7 @@ func resourceGithubRepositoryCollaboratorRead(d *schema.ResourceData, meta inter
if invitation != nil {
username = invitation.GetInvitee().GetLogin()

permissionName, err := getInvitationPermission(invitation)
permissionName := getInvitationPermission(invitation.GetPermissions())
if err != nil {
return err
}
Expand Down Expand Up @@ -142,7 +143,7 @@ func resourceGithubRepositoryCollaboratorRead(d *schema.ResourceData, meta inter
if strings.EqualFold(c.GetLogin(), username) {
d.Set("repository", repoName)
d.Set("username", c.GetLogin())
d.Set("permission", c.GetRoleName())
d.Set("permission", getInvitationPermission(c.GetRoleName()))
return nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion github/resource_github_team_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func resourceGithubTeamRepositoryRead(d *schema.ResourceData, meta interface{})
d.Set("team_id", teamIdString)
}
d.Set("repository", repo.GetName())
d.Set("permission", repo.GetRoleName())
d.Set("permission", getInvitationPermission(repo.GetRoleName()))

return nil
}
Expand Down
37 changes: 10 additions & 27 deletions github/util_permissions.go
Original file line number Diff line number Diff line change
@@ -1,37 +1,20 @@
package github

import (
"fmt"

"github.com/google/go-github/v45/github"
)

const (
pullPermission string = "pull"
triagePermission string = "triage"
pushPermission string = "push"
maintainPermission string = "maintain"
adminPermission string = "admin"
writePermission string = "write"
readPermission string = "read"
pullPermission string = "pull"
pushPermission string = "push"
writePermission string = "write"
readPermission string = "read"
)

func getInvitationPermission(i *github.RepositoryInvitation) (string, error) {
func getInvitationPermission(permission string) string {
// Permissions for some GitHub API routes are expressed as "read",
// "write", and "admin"; in other places, they are expressed as "pull",
// "push", and "admin".
permissions := i.GetPermissions()
if permissions == readPermission {
return pullPermission, nil
} else if permissions == writePermission {
return pushPermission, nil
} else if permissions == adminPermission {
return adminPermission, nil
} else if *i.Permissions == maintainPermission {
return maintainPermission, nil
} else if *i.Permissions == triagePermission {
return triagePermission, nil
if permission == readPermission {
return pullPermission
} else if permission == writePermission {
return pushPermission
}

return "", fmt.Errorf("unexpected permission value: %v", permissions)
return permission
}
2 changes: 2 additions & 0 deletions website/docs/d/repository.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ The following arguments are supported:

* `full_name` - (Optional) Full name of the repository (in `org/name` format).

* `only_protected_branches` - (Optional). If true, the `branches` attributes will be populated only with protected branches. Default: `false`.

## Attributes Reference

* `node_id` - the Node ID of the repository.
Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/repository_collaborator.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ The following arguments are supported:
* `repository` - (Required) The GitHub repository
* `username` - (Required) The user to add to the repository as a collaborator.
* `permission` - (Optional) The permission of the outside collaborator for the repository.
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.
Must be one of `pull`, `push`, `maintain`, `triage` or `admin` for organization-owned repositories.
Must be `push` for personal repositories. Defaults to `push`.
* `permission_diff_suppression` - (Optional) Suppress plan diffs for `triage` and `maintain`. Defaults to `false`.

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

```
$ terraform import github_repository_collaborator.collaborator terraform:someuser
```
```