-
Notifications
You must be signed in to change notification settings - Fork 927
feat: add data sources for listing GitHub App installations in an organization #2573
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
base: main
Are you sure you want to change the base?
Conversation
|
👋 Hey Friends, this pull request has been automatically marked as |
deiga
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey 👋
Thank you for your contribution!
I've requested a few changes to make this fit into the provider even better :)
| return &schema.Resource{ | ||
| Read: dataSourceGithubOrganizationAppInstallationsRead, | ||
|
|
||
| Schema: map[string]*schema.Schema{ | ||
| "installations": { | ||
| Type: schema.TypeList, | ||
| Computed: true, | ||
| Elem: &schema.Resource{ | ||
| Schema: map[string]*schema.Schema{ | ||
| "id": { | ||
| Type: schema.TypeInt, | ||
| Computed: true, | ||
| }, | ||
| "slug": { | ||
| Type: schema.TypeString, | ||
| Computed: true, | ||
| }, | ||
| "app_id": { | ||
| Type: schema.TypeInt, | ||
| Computed: true, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: Could you please add Description fields to the Schema and all fields?
|
|
||
| func dataSourceGithubOrganizationAppInstallations() *schema.Resource { | ||
| return &schema.Resource{ | ||
| Read: dataSourceGithubOrganizationAppInstallationsRead, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Could you refactor this to use ReadContext?
| import ( | ||
| "context" | ||
|
|
||
| "github.com/google/go-github/v66/github" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: I doubt we'll be able to land this before #2602
Maybe you could even rebase on top of that branch?
| "github.com/google/go-github/v66/github" | |
| "github.com/google/go-github/v77/github" |
| "app_id": { | ||
| Type: schema.TypeInt, | ||
| Computed: true, | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Could you add the following fields to this:
- repository_selection
- permissions
- events
- html_url
- client_id
- target_id
- target_type
- suspended
|
@atilsensalduz Please rebase and go through the comments |
Hey @deiga , apologies for the late reply. I somehow missed this PR. Thanks so much for the review! I’ve worked through your suggestions. |
|
Hi @deiga , I've changed the PR according to your suggestions. Could you please take a look again when you have time? Thanks in advance. |
| return &schema.Resource{ | ||
| ReadContext: dataSourceGithubOrganizationAppInstallationsRead, | ||
|
|
||
| Schema: map[string]*schema.Schema{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a top-level Description field
| client := meta.(*Owner).v3client | ||
|
|
||
| options := &github.ListOptions{ | ||
| PerPage: 100, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets use the global constant here
| PerPage: 100, | |
| PerPage: maxPerPage, |
| if v := appInstallation.Permissions.Actions; v != nil { | ||
| permissions["actions"] = *v | ||
| } | ||
| if v := appInstallation.Permissions.Administration; v != nil { | ||
| permissions["administration"] = *v | ||
| } | ||
| if v := appInstallation.Permissions.Checks; v != nil { | ||
| permissions["checks"] = *v | ||
| } | ||
| if v := appInstallation.Permissions.Contents; v != nil { | ||
| permissions["contents"] = *v | ||
| } | ||
| if v := appInstallation.Permissions.Deployments; v != nil { | ||
| permissions["deployments"] = *v | ||
| } | ||
| if v := appInstallation.Permissions.Environments; v != nil { | ||
| permissions["environments"] = *v | ||
| } | ||
| if v := appInstallation.Permissions.Issues; v != nil { | ||
| permissions["issues"] = *v | ||
| } | ||
| if v := appInstallation.Permissions.Metadata; v != nil { | ||
| permissions["metadata"] = *v | ||
| } | ||
| if v := appInstallation.Permissions.Members; v != nil { | ||
| permissions["members"] = *v | ||
| } | ||
| if v := appInstallation.Permissions.OrganizationAdministration; v != nil { | ||
| permissions["organization_administration"] = *v | ||
| } | ||
| if v := appInstallation.Permissions.OrganizationHooks; v != nil { | ||
| permissions["organization_hooks"] = *v | ||
| } | ||
| if v := appInstallation.Permissions.OrganizationPlan; v != nil { | ||
| permissions["organization_plan"] = *v | ||
| } | ||
| if v := appInstallation.Permissions.OrganizationProjects; v != nil { | ||
| permissions["organization_projects"] = *v | ||
| } | ||
| if v := appInstallation.Permissions.OrganizationSecrets; v != nil { | ||
| permissions["organization_secrets"] = *v | ||
| } | ||
| if v := appInstallation.Permissions.OrganizationSelfHostedRunners; v != nil { | ||
| permissions["organization_self_hosted_runners"] = *v | ||
| } | ||
| if v := appInstallation.Permissions.OrganizationUserBlocking; v != nil { | ||
| permissions["organization_user_blocking"] = *v | ||
| } | ||
| if v := appInstallation.Permissions.Packages; v != nil { | ||
| permissions["packages"] = *v | ||
| } | ||
| if v := appInstallation.Permissions.Pages; v != nil { | ||
| permissions["pages"] = *v | ||
| } | ||
| if v := appInstallation.Permissions.PullRequests; v != nil { | ||
| permissions["pull_requests"] = *v | ||
| } | ||
| if v := appInstallation.Permissions.RepositoryHooks; v != nil { | ||
| permissions["repository_hooks"] = *v | ||
| } | ||
| if v := appInstallation.Permissions.RepositoryProjects; v != nil { | ||
| permissions["repository_projects"] = *v | ||
| } | ||
| if v := appInstallation.Permissions.RepositoryPreReceiveHooks; v != nil { | ||
| permissions["repository_pre_receive_hooks"] = *v | ||
| } | ||
| if v := appInstallation.Permissions.Secrets; v != nil { | ||
| permissions["secrets"] = *v | ||
| } | ||
| if v := appInstallation.Permissions.SecretScanningAlerts; v != nil { | ||
| permissions["secret_scanning_alerts"] = *v | ||
| } | ||
| if v := appInstallation.Permissions.SecurityEvents; v != nil { | ||
| permissions["security_events"] = *v | ||
| } | ||
| if v := appInstallation.Permissions.SingleFile; v != nil { | ||
| permissions["single_file"] = *v | ||
| } | ||
| if v := appInstallation.Permissions.Statuses; v != nil { | ||
| permissions["statuses"] = *v | ||
| } | ||
| if v := appInstallation.Permissions.TeamDiscussions; v != nil { | ||
| permissions["team_discussions"] = *v | ||
| } | ||
| if v := appInstallation.Permissions.VulnerabilityAlerts; v != nil { | ||
| permissions["vulnerability_alerts"] = *v | ||
| } | ||
| if v := appInstallation.Permissions.Workflows; v != nil { | ||
| permissions["workflows"] = *v | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use the Get*() accessors for these attributes to not have to deal with pointers?
And since there are so many fields, I wonder if using reflect to build a field iterator could make sense 🤔
| check := resource.ComposeAggregateTestCheckFunc( | ||
| resource.TestCheckResourceAttrSet("data.github_organization_app_installations.test", "installations.0.id"), | ||
| resource.TestCheckResourceAttrSet("data.github_organization_app_installations.test", "installations.0.slug"), | ||
| resource.TestCheckResourceAttrSet("data.github_organization_app_installations.test", "installations.0.app_id"), | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please inline this variable
| testCase := func(t *testing.T, mode string) { | ||
| resource.Test(t, resource.TestCase{ | ||
| Providers: testAccProviders, | ||
| Steps: []resource.TestStep{ | ||
| { | ||
| Config: config, | ||
| Check: check, | ||
| }, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| t.Run("with an anonymous account", func(t *testing.T) { | ||
| t.Skip("anonymous account not supported for this operation") | ||
| }) | ||
|
|
||
| t.Run("with an individual account", func(t *testing.T) { | ||
| t.Skip("individual account not supported for this operation") | ||
| }) | ||
|
|
||
| t.Run("with an organization account", func(t *testing.T) { | ||
| testCase(t, organization) | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't use this testCase pattern anymore
| testCase := func(t *testing.T, mode string) { | |
| resource.Test(t, resource.TestCase{ | |
| Providers: testAccProviders, | |
| Steps: []resource.TestStep{ | |
| { | |
| Config: config, | |
| Check: check, | |
| }, | |
| }, | |
| }) | |
| } | |
| t.Run("with an anonymous account", func(t *testing.T) { | |
| t.Skip("anonymous account not supported for this operation") | |
| }) | |
| t.Run("with an individual account", func(t *testing.T) { | |
| t.Skip("individual account not supported for this operation") | |
| }) | |
| t.Run("with an organization account", func(t *testing.T) { | |
| testCase(t, organization) | |
| }) | |
| resource.Test(t, resource.TestCase{ | |
| PreCheck: func() { skipUnlessHasOrgs(t) }, | |
| ProviderFactories: providerFactories, | |
| Steps: []resource.TestStep{ | |
| { | |
| Config: config, | |
| Check: check, | |
| }, | |
| }, | |
| }) |
|
@atilsensalduz could you please rebase this PR? |
stevehipwell
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @atilsensalduz, I've added a couple of comments. Could you also add support for single_file_paths, created_at & updated_at.
| Computed: true, | ||
| Description: "The ID of the GitHub App installation.", | ||
| }, | ||
| "slug": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be app_slug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes you're right @stevehipwell app_slug is more explicit and consistent.
…pp_installations data source Signed-off-by: atilsensalduz <atil.sensalduz@gmail.com>
Co-authored-by: Steve Hipwell <steve.hipwell@gmail.com>
Co-authored-by: Steve Hipwell <steve.hipwell@gmail.com>
Co-authored-by: Steve Hipwell <steve.hipwell@gmail.com>
…pp_installations data source Signed-off-by: atilsensalduz <atil.sensalduz@gmail.com>
This PR introduces a new data source, github_app_installations, to enable listing all installed GitHub Apps within an organization. This addition enhances integration with existing resources such as github_app_installation_repository, providing better automation and management capabilities for GitHub App permissions.
What's New?
New Data Source: github_app_installations
Allows fetching all installed GitHub Apps in an organization:
data "github_organization_app_installations" "all_apps" {}Example Use Case:
This data source can be integrated with the github_app_installation_repository resource to manage app permissions on specific repositories:
API Reference: https://docs.github.com/en/rest/orgs/orgs?apiVersion=2022-11-28#list-app-installations-for-an-organization
Related Issue: #2570