Repository navigation
feat: add prefix filter to team sync groups data source - #3248
laughedelic wants to merge 4 commits into
Conversation
|
👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with |
deiga
left a comment
There was a problem hiding this comment.
Thanks for the PR. I left some comments that need addressing
deiga
left a comment
There was a problem hiding this comment.
Sorry, the ID will need to change and thus we need a schema migration
stevehipwell
left a comment
There was a problem hiding this comment.
@laughadelic please could you rebase this PR, please note that we've changed how the docs work and ideally want to generate the docs for this data source via the automation.
e21fe5d to
c2041b9
Compare
stevehipwell
left a comment
There was a problem hiding this comment.
Thanks for updating @laughedelic, I've added some review comments.
| } | ||
|
|
||
| if v, ok := d.GetOk("prefix_filter"); ok { | ||
| options.Query = v.(string) |
There was a problem hiding this comment.
| options.Query = v.(string) | |
| q, _ := v.(string) | |
| options.Query = q |
Otherwise you'll get a lint failure.
| "github.com/hashicorp/terraform-plugin-testing/tfjsonpath" | ||
| ) | ||
|
|
||
| func TestAccGithubOrganizationTeamSyncGroupsDataSource_existing(t *testing.T) { |
There was a problem hiding this comment.
| func TestAccGithubOrganizationTeamSyncGroupsDataSource_existing(t *testing.T) { | |
| func TestAccGithubOrganizationTeamSyncGroupsDataSource(t *testing.T) { |
Please nest sub-tests using t.Run instead of using steps for separate tests. I suggest the following sub tests.
all- Single step
filtered- Step 1 a filter that matches
- Step 2 change the filter to match nothing
|
|
||
| ## Example Usage | ||
|
|
||
| Retrieve all IdP groups: |
There was a problem hiding this comment.
Please can you update the docs to use the template pattern of automatically inserting the examples and using the schema for the attribute descriptions, meaning this description should be a comment in the example file.
| } | ||
|
|
||
| d.SetId(fmt.Sprintf("%s/github-org-team-sync-groups", orgName)) | ||
| id, err := buildID(orgName, options.Query) |
There was a problem hiding this comment.
This might be clearer if we use a placeholder when query isn't set.
There was a problem hiding this comment.
Done in de55491. The ID is now <org>:* when no filter is set, and <org>:<prefix> otherwise
c2041b9 to
d2915b1
Compare
Adds an optional prefix_filter argument to github_organization_team_sync_groups that filters returned IdP groups to those whose names begin with the given value. Uses buildID(orgName, options.Query) for the resource ID. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
- Avoid a lint failure by using a checked type assertion when reading the prefix_filter value. - Use "*" as an explicit placeholder in the data source ID when no prefix filter is set, so the ID always has the same shape. - Restructure the acceptance test into `all` and `filtered` sub-tests using t.Run instead of packing unrelated cases into steps. The `filtered` sub-test first applies a matching prefix, then switches to a prefix that matches nothing. - Switch the docs template to the standard tfplugindocs pattern: the examples are inserted automatically from the example files and the attribute documentation comes from the schema. The prose describing each example moved into the example files as comments.
The previous hand-written template was replaced with the standard tfplugindocs pattern in the previous commit, but the examples were not picked up because they lived in a directory named after the short data source name. tfplugindocs discovers them under examples/data-sources/<full_data_source_name>/data-source*.tf, so the examples move to examples/data-sources/github_organization_team_sync_groups/ and are renamed accordingly. With the description moved onto the schema, the per-data-source template no longer adds anything over templates/data-sources.md.tmpl, so it is removed and the page is now fully generated.
d2915b1 to
e0bb856
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The positive acceptance test does not verify that the prefix returns matching groups.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
These provider review instructions are being used. This PR adds server-side prefix filtering to the organization team sync groups data source.
Changes:
- Adds the optional
prefix_filterargument. - Adds acceptance coverage for filtered and empty results.
- Updates generated documentation and examples.
File summaries
| File | Description |
|---|---|
github/data_source_github_organization_team_sync_groups.go |
Implements prefix filtering and filter-aware IDs. |
github/data_source_github_organization_team_sync_groups_test.go |
Adds filter acceptance tests. |
docs/data-sources/organization_team_sync_groups.md |
Documents the new argument and examples. |
templates/data-sources/organization_team_sync_groups.md.tmpl |
Removes the obsolete custom template. |
examples/data-sources/organization_team_sync_groups/example_1.tf |
Removes the legacy example. |
examples/data-sources/github_organization_team_sync_groups/data-source_1.tf |
Adds the standard unfiltered example. |
examples/data-sources/github_organization_team_sync_groups/data-source_2.tf |
Adds the prefix-filter example. |
Review details
- Files reviewed: 7/7 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
deiga
left a comment
There was a problem hiding this comment.
I think in this case it could make sense to have a unit test which mocks the GH API enough to verify that the filter prefix is being sent could make sense here 🤔
@deiga the whole unit test problem has repercussions. Technically we should have a large number of unit tests to cover all code paths and then a smaller number of integration tests to validate that the system works as a whole. The problem with this code base and the GitHub API is that there isn't currently a strategy to make this work, meaning that unit tests just increase the overhead (cognitive and test duration) without decreasing the integration test overhead as the unit tests can't be trusted to actually represent the GitHub API. I think we need a separate issue to define how we could structure the tests and check the API to support this, but in the meantime I'd be very cautious about accepting unit tests that mock the GitHub API surface (or even worse undocumented API behaviour). |
stevehipwell
left a comment
There was a problem hiding this comment.
This looks good. Please add a named documentation template for the data source for consistency with all existing resources/data-sources using the auto generated documentation.
| func dataSourceGithubOrganizationTeamSyncGroups() *schema.Resource { | ||
| return &schema.Resource{ | ||
| ReadContext: dataSourceGithubOrganizationTeamSyncGroupsRead, | ||
| Description: "Get the external identity provider (IdP) groups for an organization.", |
There was a problem hiding this comment.
| Description: "Get the external identity provider (IdP) groups for an organization.", | |
| Description: "Data source to get the external identity provider (IdP) groups for an organization.", |
|
@stevehipwell I agree about the unit testing and mocking problems. That's why I proposed to mock the API to verify that the provider is sending the payload we think it should instead of verifying the API itself |
The problem is that this doesn't prove anything other than a unit test was written at the same time as the code so they match. Is there a reason why an acceptance test wouldn't work? |
AFAIK we can't guarantee that a result will be found with an acceptance test since that would require a external IdP connection? |
Yeah, the test would need a comment explaining how to configure it to function correctly but it's really the only way to check that it actually works with the real API. |
Before the change?
After the change?
Now it's possible to filter groups by prefix:
Pull request checklist
Does this introduce a breaking change?
I followed the API and the SDK in naming itq, but I'm open to something more descriptive, e.g.prefixorprefix_filter