feat: add prefix filter to team sync groups data source#3248
feat: add prefix filter to team sync groups data source#3248laughedelic wants to merge 10 commits intointegrations:mainfrom
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
| if options.Query != "" { | ||
| d.SetId(fmt.Sprintf("%s/github-org-team-sync-groups/%s", orgName, options.Query)) | ||
| } else { | ||
| d.SetId(fmt.Sprintf("%s/github-org-team-sync-groups", orgName)) | ||
| } |
There was a problem hiding this comment.
Okay, looking at this makes my skin crawl a bit 😬
While we're at it, let's change to buildID to conform to our standards :)
| if options.Query != "" { | |
| d.SetId(fmt.Sprintf("%s/github-org-team-sync-groups/%s", orgName, options.Query)) | |
| } else { | |
| d.SetId(fmt.Sprintf("%s/github-org-team-sync-groups", orgName)) | |
| } | |
| id, err := buildID(orgName, "team-sync-groups", options.Query) | |
| if err != nil { | |
| return diag.FromErr(err) | |
| } | |
| d.SetId(id) |
With this change we'll need you to make a StateUpgrader to migrate the old IDs to new IDs. Look at any of the existing ones to see how to go about it :)
There was a problem hiding this comment.
Oh, I see what you mean 😅 I have to admit, I'm moving in the dark here, trying to make the minimal necessary changes, and I don't have a good overview of the whole codebase (yet). Thanks for the guidance.
I didn't know about buildID. But it uses : as a separator. I wonder why the original ID used / 🤔
There was a problem hiding this comment.
If the query is empty, the id is going to look like orgname:team-sync-groups: with a trailing :. Isn't this odd? Should it be orgname:team-sync-groups instead?
There was a problem hiding this comment.
So how about
| if options.Query != "" { | |
| d.SetId(fmt.Sprintf("%s/github-org-team-sync-groups/%s", orgName, options.Query)) | |
| } else { | |
| d.SetId(fmt.Sprintf("%s/github-org-team-sync-groups", orgName)) | |
| } | |
| idParts := []string{orgName, "team-sync-groups"} | |
| if options.Query != "" { | |
| idParts = append(idParts, options.Query) | |
| } | |
| id, err := buildID(idParts...) | |
| if err != nil { | |
| return diag.FromErr(err) | |
| } | |
| d.SetId(id) |
?
There was a problem hiding this comment.
Thanks. I don't think that conditional IDs are great, since that requires then custom logic when parsing them (if necessary). We already have other examples of IDs where they just end with : if the last part is empty
| }, | ||
| { | ||
| Config: `data "github_organization_team_sync_groups" "test" { prefix_filter = "nonexistent_prefix_" }`, | ||
| Check: resource.ComposeTestCheckFunc( |
There was a problem hiding this comment.
Please use ConfigStateChecks instead of Check
| SchemaVersion: 1, | ||
| StateUpgraders: []schema.StateUpgrader{ | ||
| { | ||
| Type: dataSourceGithubOrganizationTeamSyncGroupsV0().CoreConfigSchema().ImpliedType(), | ||
| Upgrade: dataSourceGithubOrganizationTeamSyncGroupsStateUpgradeV0, | ||
| Version: 0, | ||
| }, | ||
| }, |
There was a problem hiding this comment.
🤦 Silly me. Do data sources even need Schema Migrations? @stevehipwell
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 it
q, but I'm open to something more descriptive, e.g.prefixorprefix_filter