Skip to content

Conversation

@Fodoj
Copy link
Contributor

@Fodoj Fodoj commented Sep 1, 2025

Description

Previous implementation followed API a bit too closely, to the point of being pointless a bit. Now the provider will go through all users till no more are found.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce.

  • Unit tests
  • Acceptance tests
  • Manual testing

Summary by CodeRabbit

  • Refactor

    • Organization users data source now auto-paginates and returns all users. Removed pagination options and metadata (after, limit, first_id, last_id, has_more). Simplified ID to reflect total count. Single-user queries continue to work without pagination fields.
  • Documentation

    • Updated install instructions to suggest “make install-dev”.
    • Added guidance to run tfplugindocs when resources change.
    • Revised data source docs to remove pagination fields.
  • Chores

    • Added tooling dependency to pin tfplugindocs.
    • Minor whitespace/style cleanups.

@Fodoj Fodoj requested a review from pabloinigo September 1, 2025 12:22
@coderabbitai
Copy link

coderabbitai bot commented Sep 1, 2025

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch auto-pagination-org-users

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Fodoj Fodoj self-assigned this Sep 1, 2025
@pabloinigo pabloinigo merged commit e1b78a2 into main Sep 1, 2025
5 of 6 checks passed
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
README.md (1)

163-166: Be explicit about how to run tfplugindocs.

Suggest adding the exact command, leveraging tools.go.

Add after the line:

 Make sure to run `tfplugindocs` if resources are updated.
+For a local run:
+`go run -tags tools github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs generate`
internal/provider/data_source_openai_organization_users.go (2)

127-130: Consider making batch size tunable.

A fixed batchSize=100 works, but a schema or env override (with sane max) can help testing and large orgs.


168-170: Use a stable content-derived ID instead of count-only.

Count-only IDs collide when filters/content change but the total stays constant.

Apply:

-  // Set a unique ID for the data source
-  d.SetId(fmt.Sprintf("organization-users-all-%d", len(allUsers)))
+  // Set a stable ID derived from inputs and results
+  id, err := computeUsersDataSourceID(allUsers, emails)
+  if err != nil {
+    return diag.FromErr(fmt.Errorf("error computing data source ID: %w", err))
+  }
+  d.SetId(id)

Add this helper (and imports) elsewhere in the file:

// imports to add:
import (
  "crypto/sha256"
  "encoding/hex"
  "sort"
  "strings"
)

// computeUsersDataSourceID builds a stable ID from filters and returned user IDs.
func computeUsersDataSourceID(users []map[string]interface{}, emails []string) (string, error) {
  ids := make([]string, 0, len(users))
  for _, u := range users {
    if id, ok := u["id"].(string); ok {
      ids = append(ids, id)
    }
  }
  sort.Strings(ids)
  sort.Strings(emails)

  var b strings.Builder
  b.WriteString("count=")
  b.WriteString(fmt.Sprint(len(users)))
  b.WriteString(";emails=")
  b.WriteString(strings.Join(emails, ","))
  b.WriteString(";ids=")
  b.WriteString(strings.Join(ids, ","))

  sum := sha256.Sum256([]byte(b.String()))
  // Shorten for readability
  return "organization-users-" + hex.EncodeToString(sum[:8]), nil
}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 64176c2 and ca21d6e.

📒 Files selected for processing (6)
  • README.md (2 hunks)
  • docs/data-sources/organization_users.md (0 hunks)
  • internal/provider/data_source_openai_organization_users.go (1 hunks)
  • internal/provider/resource_openai_model_response.go (1 hunks)
  • internal/provider/resource_openai_organization_user.go (0 hunks)
  • tools/tools.go (1 hunks)
💤 Files with no reviewable changes (2)
  • internal/provider/resource_openai_organization_user.go
  • docs/data-sources/organization_users.md
🔇 Additional comments (3)
internal/provider/resource_openai_model_response.go (1)

256-260: No-op whitespace change — LGTM.

No functional impact.

tools/tools.go (1)

1-8: Pinning tfplugindocs via tools build tag — LGTM.

Standard pattern; won’t affect normal builds.

README.md (1)

84-85: install-dev target defined in Makefile

Comment on lines +159 to 164
// Check if there are more pages
hasMore = resp.HasMore
if hasMore && resp.LastID != "" {
after = resp.LastID
}
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Guard against infinite pagination if the API doesn’t advance.

If HasMore=true but LastID is empty or unchanged, this can loop forever. Fail fast.

Apply:

-  // Check if there are more pages
-  hasMore = resp.HasMore
-  if hasMore && resp.LastID != "" {
-    after = resp.LastID
-  }
+  // Check if there are more pages and ensure progress
+  prevAfter := after
+  hasMore = resp.HasMore
+  if hasMore {
+    if resp.LastID == "" || resp.LastID == prevAfter {
+      return diag.Errorf("pagination did not advance at page %d (last_id=%q)", pageCount, resp.LastID)
+    }
+    after = resp.LastID
+  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Check if there are more pages
hasMore = resp.HasMore
if hasMore && resp.LastID != "" {
after = resp.LastID
}
}
// Check if there are more pages and ensure progress
prevAfter := after
hasMore = resp.HasMore
if hasMore {
if resp.LastID == "" || resp.LastID == prevAfter {
return diag.Errorf("pagination did not advance at page %d (last_id=%q)", pageCount, resp.LastID)
}
after = resp.LastID
}
}
🤖 Prompt for AI Agents
In internal/provider/data_source_openai_organization_users.go around lines
159-164, the pagination loop sets hasMore = resp.HasMore and updates after =
resp.LastID without guarding for an unchanged or empty LastID, which can cause
an infinite loop; modify the loop to detect when resp.HasMore is true but
resp.LastID is empty or equal to the previous after value (track previousLastID
before update) and then fail fast or break with a clear error (or set
hasMore=false) to prevent infinite pagination; ensure you return or propagate an
informative error so callers know pagination did not advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants