Skip to content

docs: add block api #68

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

Merged
merged 2 commits into from
Sep 26, 2024
Merged

docs: add block api #68

merged 2 commits into from
Sep 26, 2024

Conversation

kwaa
Copy link
Member

@kwaa kwaa commented Sep 26, 2024

Summary by CodeRabbit

  • New Features

    • Introduced methods for blocking and unblocking URLs via the API.
    • Added documentation for blocking instances or actors in the Hatsu Admin API.
  • Documentation

    • Updated the documentation summary to include a reference for blocking instances or actors.
    • Enhanced the blocking functionality documentation with examples and explanations.
    • Modified formatting in the account creation documentation for better emphasis.

@kwaa kwaa added the documentation Improvements or additions to documentation label Sep 26, 2024
@kwaa kwaa added this to the 0.3 [Strobe Nights] milestone Sep 26, 2024
Copy link
Contributor

coderabbitai bot commented Sep 26, 2024

Walkthrough

The changes introduce new methods for blocking and unblocking URLs in the Justfile, enhancing its functionality. Additionally, documentation updates include a new entry related to blocking instances or actors, a detailed guide on the API's blocking functionality, and a formatting change in an existing document for clarity. These modifications collectively aim to improve the usability and comprehensiveness of the system's documentation and functionality.

Changes

File Change Summary
Justfile Added methods: block-url url and unblock-url url for API interactions to block/unblock URLs.
docs/src/SUMMARY.md Added entry: [Block Instances or Actors](./admins/block-instances-or-actors.md) under "for Administrators".
docs/src/admins/block-instances-or-actors.md Introduced document detailing the blocking/unblocking functionality and usage of the Hatsu Admin API.
docs/src/admins/create-account.md Modified formatting of an instruction line to include a blockquote for emphasis.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Justfile
    participant API

    User->>Justfile: Call block-url(url)
    Justfile->>API: POST /api/v0/admin/block-url?url={url}&token={HATSU_ACCESS_TOKEN}
    API-->>Justfile: Response (success/failure)

    User->>Justfile: Call unblock-url(url)
    Justfile->>API: POST /api/v0/admin/unblock-url?url={url}&token={HATSU_ACCESS_TOKEN}
    API-->>Justfile: Response (success/failure)
Loading

Poem

In the meadow where rabbits play,
New methods hop in, brightening the day.
Block and unblock, a dance so neat,
With just a curl, they can't be beat!
Hatsu's magic, clear and bright,
In the docs, it takes flight! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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

@kwaa kwaa marked this pull request as ready for review September 26, 2024 15:53
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: 3

🧹 Outside diff range and nitpick comments (6)
docs/src/SUMMARY.md (1)

28-28: LGTM! Consider a minor clarification.

The new entry "Block Instances or Actors" is correctly placed and formatted. It fits well within the "for Admins" section and follows the established pattern for documentation links.

For improved clarity, consider slightly expanding the title to "Block Remote Instances or Actors". This could help administrators immediately understand that this refers to external entities, not local ones.

-- [Block Instances or Actors](./admins/block-instances-or-actors.md)
++ [Block Remote Instances or Actors](./admins/block-instances-or-actors.md)
docs/src/admins/block-instances-or-actors.md (5)

1-3: Minor grammatical improvement suggested

The sentence structure in the note about setting HATSU_ACCESS_TOKEN can be improved for better readability.

Consider revising the sentence as follows:

-> Ensure you set `HATSU_ACCESS_TOKEN` correctly in the [previous section](./environments.md#hatsu_access_token-optional) first, otherwise you will not be able to use the Hatsu Admin API.
+> Ensure you set `HATSU_ACCESS_TOKEN` correctly in the [previous section](./environments.md#hatsu_access_token-optional) first. Otherwise, you will not be able to use the Hatsu Admin API.

This change separates the two clauses into distinct sentences, improving clarity.

🧰 Tools
🪛 LanguageTool

[typographical] ~3-~3: The word “otherwise” is an adverb that can’t be used like a conjunction, and therefore needs to be separated from the sentence.
Context: ...onments.md#hatsu_access_token-optional) first, otherwise you will not be able to use the Hatsu A...

(THUS_SENTENCE)


7-8: Enhance explanation and improve grammar

The explanation about blocking URLs could be more detailed, and there's a minor grammar issue.

Consider revising as follows:

-Block URL. if path is `/`, it is recognized as an instance.
+Block a URL using this API. If the path is `/`, it is recognized as an instance. Otherwise, it is treated as an actor.

This change provides more context and fixes the capitalization issue.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~7-~7: Possible missing article found.
Context: ...Admin API. ## Block URL Block URL. if path is /, it is recognized as an instance...

(AI_HYDRA_LEO_MISSING_A)


9-9: Improve sentence structure

The sentence structure can be improved for better readability.

Consider revising as follows:

-Each time an activity is received an origin match is performed on blocked instances and an exact match is performed on blocked actors.
+Each time an activity is received, an origin match is performed on blocked instances, and an exact match is performed on blocked actors.

This change adds necessary commas to improve readability.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~9-~9: Possible missing comma found.
Context: ... an instance. Each time an activity is received an origin match is performed on blocked...

(AI_HYDRA_LEO_MISSING_COMMA)


11-13: Improve curl command readability

The curl command example could be formatted for better readability.

Consider restructuring the command as follows:

BLOCK_URL="https://example.com"
HATSU_API_URL="http://localhost:$(echo $HATSU_LISTEN_PORT)"

curl -X POST "${HATSU_API_URL}/api/v0/admin/block-url" \
     -d "url=${BLOCK_URL}" \
     -d "token=${HATSU_ACCESS_TOKEN}"

This format:

  1. Separates the URL construction for clarity.
  2. Uses -d for data parameters, which is more common and readable.
  3. Splits the command across multiple lines for better readability.

15-15: Correct grammatical error in section title

There's a minor grammatical error in the section title.

Please revise the title as follows:

-### Get the Actors URL for a Fediverse user
+### Get the Actor's URL for a Fediverse user

This change adds the missing apostrophe to make "Actor's" possessive.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~15-~15: It seems likely that a singular genitive (’s) apostrophe is missing.
Context: ... $HATSU_ACCESS_TOKEN)" ``` ### Get the Actors URL for a Fediverse user In Fediverse,...

(AI_HYDRA_LEO_APOSTROPHE_S_XS)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e9ac6fe and 1a638a8.

📒 Files selected for processing (4)
  • Justfile (1 hunks)
  • docs/src/SUMMARY.md (1 hunks)
  • docs/src/admins/block-instances-or-actors.md (1 hunks)
  • docs/src/admins/create-account.md (1 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/src/admins/block-instances-or-actors.md

[typographical] ~3-~3: The word “otherwise” is an adverb that can’t be used like a conjunction, and therefore needs to be separated from the sentence.
Context: ...onments.md#hatsu_access_token-optional) first, otherwise you will not be able to use the Hatsu A...

(THUS_SENTENCE)


[uncategorized] ~7-~7: Possible missing article found.
Context: ...Admin API. ## Block URL Block URL. if path is /, it is recognized as an instance...

(AI_HYDRA_LEO_MISSING_A)


[uncategorized] ~9-~9: Possible missing comma found.
Context: ... an instance. Each time an activity is received an origin match is performed on blocked...

(AI_HYDRA_LEO_MISSING_COMMA)


[uncategorized] ~15-~15: It seems likely that a singular genitive (’s) apostrophe is missing.
Context: ... $HATSU_ACCESS_TOKEN)" ``` ### Get the Actors URL for a Fediverse user In Fediverse,...

(AI_HYDRA_LEO_APOSTROPHE_S_XS)

docs/src/admins/create-account.md

[typographical] ~3-~3: The word “otherwise” is an adverb that can’t be used like a conjunction, and therefore needs to be separated from the sentence.
Context: ...onments.md#hatsu_access_token-optional) first, otherwise you will not be able to use the Hatsu A...

(THUS_SENTENCE)

🔇 Additional comments (3)
Justfile (3)

83-85: 🛠️ Refactor suggestion

Refactor unblock-url method and reduce duplication.

The unblock-url method has the same structure and potential improvements as the block-url method. To reduce duplication and improve maintainability, consider refactoring both methods to use a common helper function.

Here's a suggested refactor:

-block-url url:
-  curl -X POST "http://localhost:${HATSU_LISTEN_PORT}/api/v0/admin/block-url?url={{url}}&token=${HATSU_ACCESS_TOKEN}"
-
-# /api/v0/admin/unblock-url
-unblock-url url:
-  curl -X POST "http://localhost:${HATSU_LISTEN_PORT}/api/v0/admin/unblock-url?url={{url}}&token=${HATSU_ACCESS_TOKEN}"
+# Helper function for URL operations
+_url_operation operation url:
+    #!/bin/sh
+    response=$(curl -X POST "http://localhost:${HATSU_LISTEN_PORT}/api/v0/admin/{{operation}}-url" \
+        -H "Content-Type: application/json" \
+        -H "Authorization: Bearer ${HATSU_ACCESS_TOKEN}" \
+        -d "{\"url\": \"{{url}}\"}" \
+        -s -w "\n%{http_code}")
+    body=$(echo "$response" | sed -n '1p')
+    code=$(echo "$response" | sed -n '2p')
+    if [ "$code" = "200" ]; then
+        echo "URL {{operation}} successful"
+    else
+        echo "Error: $body"
+    fi
+
+# /api/v0/admin/block-url
+block-url url:
+    just _url_operation "block" "{{url}}"
+
+# /api/v0/admin/unblock-url
+unblock-url url:
+    just _url_operation "unblock" "{{url}}"

This refactored version:

  1. Creates a helper function _url_operation that handles the common logic.
  2. Uses this helper function in both block-url and unblock-url methods.
  3. Implements the improvements suggested in the previous comment (body parameters, authorization header, error handling).
  4. Reduces code duplication and improves maintainability.

Let's check if there are any other similar API calls in the Justfile that could benefit from this pattern:

#!/bin/bash
# Search for other API calls in the Justfile
rg 'curl.*POST.*api/v0/admin' Justfile

79-85: 🛠️ Refactor suggestion

Consider standardizing API call patterns across the Justfile.

The new block-url and unblock-url methods are good additions that align with the existing structure of the Justfile. However, there's an opportunity to improve consistency across all API-related commands in the file.

  1. Review all API-related commands in the Justfile (e.g., account, block-url, unblock-url) and consider applying a consistent pattern for making API calls. This could involve:

    • Using a common helper function for API calls.
    • Consistent error handling and response processing.
    • Uniform use of headers (e.g., Content-Type, Authorization).
  2. Consider adding a comment block at the top of the file explaining the common patterns and conventions used for API calls in this Justfile. This will help future contributors maintain consistency.

  3. If not already present, consider adding a .env.example file to the project root, listing all the environment variables used in this Justfile (like HATSU_LISTEN_PORT and HATSU_ACCESS_TOKEN). This will help new developers set up their environment correctly.

Let's check for all API-related commands in the Justfile:

This will help us identify all places where we might want to apply consistent patterns.

✅ Verification successful

API call patterns are consistent across the Justfile.

Verified that all API-related commands (account, block-url, unblock-url) follow a consistent pattern in their curl usage and environment variable configurations. No further standardization is necessary at this time.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for all API-related commands in the Justfile
rg 'curl.*api/v0' Justfile

Length of output: 383


79-81: 🛠️ Refactor suggestion

Consider improving the block-url method implementation.

The method successfully implements the block URL functionality, which aligns with the PR objective. However, there are a few points to consider:

  1. For POST requests, it's generally better to send data in the request body rather than as query parameters. This is especially important for potentially long or complex URLs.
  2. The method doesn't handle errors or process the response, which could make debugging difficult.

Consider refactoring the method like this:

 block-url url:
-  curl -X POST "http://localhost:${HATSU_LISTEN_PORT}/api/v0/admin/block-url?url={{url}}&token=${HATSU_ACCESS_TOKEN}"
+  curl -X POST "http://localhost:${HATSU_LISTEN_PORT}/api/v0/admin/block-url" \
+    -H "Content-Type: application/json" \
+    -H "Authorization: Bearer ${HATSU_ACCESS_TOKEN}" \
+    -d "{\"url\": \"{{url}}\"}" \
+    -s -w "\n%{http_code}" \
+    | awk 'NR==1{body=$0} NR==2{code=$0} END{if(code==200) {print "URL blocked successfully"} else {print "Error: " body}}'

This refactored version:

  1. Sends the URL in the request body.
  2. Uses a proper Authorization header for the token.
  3. Processes the response to provide meaningful feedback.

To ensure consistency across the codebase, let's check if there are other instances of API calls that might benefit from similar improvements:

@kwaa kwaa merged commit dfbf4fb into main Sep 26, 2024
2 checks passed
@kwaa kwaa deleted the docs/block branch September 26, 2024 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant