8000 docs: Autogenerate list of connector capabilities for docs generation by laouji · Pull Request #466 · formancehq/payments · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

docs: Autogenerate list of connector capabilities for docs generation #466

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

Jump to bottom
Merged
merged 2 commits into from
Jun 13, 2025

Conversation

laouji
Copy link
Contributor
@laouji laouji commented Jun 11, 2025

Relates to: formancehq/docs#126

This file is used to generate the following table in docs:
Capture d’écran 2025-06-11 à 16 35 14

Copy link
Contributor
coderabbitai bot commented Jun 11, 2025

"""

Walkthrough

A new Go program was introduced to scan connector directories, extract capability information using the registry package, and output the aggregated data as JSON. A corresponding Justfile recipe was added to build and run this program, and the pre-commit alias was updated to include this new compilation step.

Changes

File(s) Change Summary
tools/compile-capabilities/main.go Added a Go program to scan connector directories, extract capabilities using registry, and output JSON.
Justfile Added compile-connector-capabilities recipe and updated pre-commit alias to invoke it.

Sequence Diagram(s)

sequenceDiagram
    participant Dev as Developer
    participant Just as Justfile
    participant GoTool as compile-capabilities (Go Program)
    participant FS as Filesystem

    Dev->>Just: Run pre-commit alias
    Just->>GoTool: Execute compile-connector-capabilities recipe
    GoTool->>FS: Scan connector directories
    loop For each connector
        GoTool->>FS: Read capabilities.go
        GoTool->>FS: Parse AST, extract capabilities
    end
    GoTool->>FS: Write JSON output
Loading

Poem

In burrows deep, with code so bright,
A rabbit hops through files at night.
Capabilities gathered, neat and clear,
Compiled to JSON, now they appear!
With every pre-commit, we leap ahead—
Hoppy coding, just as the Justfile said.
🐇✨
"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 53a47a0 and e0f098c.

📒 Files selected for processing (1)
  • tools/compile-capabilities/main.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tools/compile-capabilities/main.go
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Dirty
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Commit Unit Tests in branch poc/capabilities
  • Post Copyable Unit Tests in Comment

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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai 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

Documentation and Community

  • 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.

@laouji laouji changed the title poc: Autogenerate list of connector capabilities for docs generation docs: Autogenerate list of connector capabilities for docs generation Jun 11, 2025
Copy link
codecov bot commented Jun 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 69.66%. Comparing base (933bad9) to head (e0f098c).
Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #466   +/-   ##
=======================================
  Coverage   69.66%   69.66%           
=======================================
  Files         627      627           
  Lines       32196    32196           
==================
8000
=====================
  Hits        22428    22428           
  Misses       8554     8554           
  Partials     1214     1214           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@laouji laouji marked this pull request as ready for review June 11, 2025 14:36
@laouji laouji requested a review from a team as a code owner June 11, 2025 14:36
Copy link
Contributor
@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 (5)
tools/compile-capabilities/main.go (4)

21-23: Rename flag variable to avoid shadowing package names

The path identifier shadows the standard path package (even if it’s not currently imported). Renaming it to something like inputDir or connectorsDir removes the potential for confusion and accidental misuse later.


53-57: Emit deterministic, human-readable JSON

Using json.Marshal produces compact output and a map with random key order.
For version-controlled artefacts, indentation plus stable ordering makes diffs far clearer.

-    d, err := json.Marshal(&connectorCapabilities)
+    // Sort keys for deterministic output
+    keys := maps.Keys(connectorCapabilities) // Go 1.21
+    slices.Sort(keys)
+    ordered := make(map[string][]string, len(keys))
+    for _, k := range keys {
+        ordered[k] = connectorCapabilities[k]
+    }
+    d, err := json.MarshalIndent(ordered, "", "  ")

Requires import "golang.org/x/exp/maps" and import "golang.org/x/exp/slices" (or hand-rolled sorting).


81-83: Use filepath.Rel for path validation instead of HasPrefix

Prefix checks are fragile on case-insensitive filesystems or when symbolic links are involved.
filepath.Rel (or filepath.EvalSymlinks) gives a safer guarantee that the target is inside the intended directory.


103-109: Strip the Capability prefix as well for cleaner JSON values

Currently you get "CapabilityTransferToWallet" after trimming "models.".
If the docs table is meant to show the raw capability names ("TransferToWallet"), extend the trim:

-    capabilities = append(capabilities, strings.TrimPrefix(str, "models."))
+    capabilities = append(capabilities,
+        strings.TrimPrefix(strings.TrimPrefix(str, "models."), "Capability"))

(Or use strings.TrimPrefix(str, "models.Capability") once.)

Justfile (1)

24-27: Run the tool with go run to avoid the build-cleanup dance

Compiling a throw-away binary then rm-ing it adds I/O and complexity.
Consider:

compile-connector-capabilities:
    @go run {{justfile_directory()}}/tools/compile-capabilities \
        --path {{justfile_directory()}}/internal/connectors/plugins/public \
        --output {{justfile_directory()}}/docs/other/connector-capabilities.json

Cleaner, faster, and nothing to delete.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 933bad9 and 63c4da2.

⛔ Files ignored due to path filters (1)
  • docs/other/connector-capabilities.json is excluded by !**/*.json
📒 Files selected for processing (2)
  • Justfile (2 hunks)
  • tools/compile-capabilities/main.go (1 hunks)

Comment on lines 34 to 50
entries, err := os.ReadDir(*path)
10000 if err != nil {
log.Fatal(err)
}

connectorCapabilities = make(map[string][]string)
for _, e := range entries {
if !e.IsDir() {
continue
}

capabilities, err := readCapabilities(e.Name())
if err != nil {
log.Fatal(err)
}

connectorCapabilities[e.Name()] = capabilities
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Gracefully ignore connectors lacking capabilities.go instead of aborting the run

readCapabilities returns an error for every directory that does not contain a capabilities.go file, and this error bubbles up to a log.Fatal, terminating the whole program.
That will block the tool as soon as you add a connector that doesn’t implement capabilities yet.

A minimal change:

-        capabilities, err := readCapabilities(e.Name())
-        if err != nil {
-            log.Fatal(err)
-        }
+        capabilities, err := readCapabilities(e.Name())
+        if errors.Is(err, os.ErrNotExist) {
+            // Connector has no capabilities file – perfectly valid, just skip.
+            continue
+        }
+        if err != nil {
+            log.Fatalf("parsing capabilities for %s: %v", e.Name(), err)
+        }

(Remember to import "errors" at the top.)

📝 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
entries, err := os.ReadDir(*path)
if err != nil {
log.Fatal(err)
}
connectorCapabilities = make(map[string][]string)
for _, e := range entries {
if !e.IsDir() {
continue
}
capabilities, err := readCapabilities(e.Name())
if err != nil {
log.Fatal(err)
}
connectorCapabilities[e.Name()] = capabilities
entries, err := os.ReadDir(*path)
if err != nil {
log.Fatal(err)
}
connectorCapabilities = make(map[string][]string)
for _, e := range entries {
if !e.IsDir() {
continue
}
capabilities, err := readCapabilities(e.Name())
if errors.Is(err, os.ErrNotExist) {
// Connector has no capabilities file – perfectly valid, just skip.
continue
}
if err != nil {
log.Fatalf("parsing capabilities for %s: %v", e.Name(), err)
}
connectorCapabilities[e.Name()] = capabilities
🤖 Prompt for AI Agents
In tools/compile-capabilities/main.go around lines 34 to 50, the code currently
calls log.Fatal on any error returned by readCapabilities, which causes the
program to exit if a directory lacks a capabilities.go file. To fix this, modify
the error handling to check if the error indicates a missing capabilities.go
file (using errors.Is or a similar check) and if so, skip that directory without
logging a fatal error. Only call log.Fatal for other unexpected errors. This
change will allow the program to continue running even if some connectors do not
implement capabilities yet.

Copy link
Contributor
@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

♻️ Duplicate comments (1)
tools/compile-capabilities/main.go (1)

41-49: Abort-on-missing-plugin logic blocks the entire run

registry.GetCapabilities returns ErrPluginNotFound when a connector hasn’t registered capabilities yet, but the code still calls log.Fatal, terminating the tool.
Silently skipping those connectors (or at least degrading to a warning) keeps the generator useful while new connectors are under active development.

-        capabilities, err := registry.GetCapabilities(e.Name())
-        if err != nil {
-            log.Fatal(err)
-        }
+        capabilities, err := registry.GetCapabilities(e.Name())
+        if errors.Is(err, registry.ErrPluginNotFound) { // skip silently
+            continue
+        }
+        if err != nil {
+            log.Fatalf("reading capabilities for %s: %v", e.Name(), err)
+        }

(Remember to add import "errors" and export ErrPluginNotFound from the registry package if it is not already.)

🧹 Nitpick comments (1)
tools/compile-capabilities/main.go (1)

54-57: Consider deterministic & human-readable JSON output

json.Marshal produces non-stable key ordering and no indentation, which makes diffs noisy and the generated file hard to eyeball. Using json.MarshalIndent on a map[string][]string sorted beforehand (or converting to a struct with a deterministic order) yields cleaner PRs.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 63c4da2 and 53a47a0.

📒 Files selected for processing (1)
  • tools/compile-capabilities/main.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
tools/compile-capabilities/main.go (2)
internal/connectors/plugins/registry/plugins.go (1)
  • GetCapabilities (122-130)
internal/models/capabilities.go (1)
  • Capability (9-9)
🪛 GitHub Actions: Default
tools/compile-capabilities/main.go

[warning] 80-80: Go lint warning: func astString is unused

@laouji laouji force-pushed the poc/capabilities branch from 53a47a0 to e0f098c Compare June 12, 2025 11:08
@laouji laouji added this pull request to the merge queue Jun 13, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jun 13, 2025
@laouji laouji added this pull request to the merge queue Jun 13, 2025
Merged via the queue into main with commit 03ee559 Jun 13, 2025
9 checks passed
@laouji laouji deleted the poc/capabilities branch June 13, 2025 14:39
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.

2 participants
0