Skip to content

feat: add POST /api/v1/project/{projectId}/gh-org endpoint#243

Merged
UlisesGascon merged 3 commits intomainfrom
ulises/v1-add-gh-org
Jun 16, 2025
Merged

feat: add POST /api/v1/project/{projectId}/gh-org endpoint#243
UlisesGascon merged 3 commits intomainfrom
ulises/v1-add-gh-org

Conversation

@UlisesGascon
Copy link
Member

@UlisesGascon UlisesGascon commented Jun 15, 2025

Related #216

Screenshot from 2025-06-15 20-29-30

Summary by CodeRabbit

  • New Features

    • Introduced a new API endpoint to add a GitHub organization to a project.
    • Updated API documentation to describe the new endpoint and the detailed GitHub organization data structure.
  • Tests

    • Added comprehensive tests covering successful and error scenarios for adding GitHub organizations to projects via the new endpoint.

@UlisesGascon UlisesGascon self-assigned this Jun 15, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jun 15, 2025

Walkthrough

A new API endpoint, POST /api/v1/project/{projectId}/gh-org, was added to allow associating GitHub organizations with projects. The change includes the implementation, OpenAPI documentation, and comprehensive tests for the endpoint, covering validation, error handling, and database integration. Supporting utility and store functions were also integrated.

Changes

Files/Group Change Summary
src/httpServer/routers/apiV1.js Added POST endpoint /project/:projectId/gh-org for adding GitHub organizations to projects; integrated new store and validation utilities.
src/httpServer/swagger/api-v1.yml Documented the new endpoint and added a detailed GithubOrganization schema to the OpenAPI spec.
__tests__/httpServer/apiV1.test.js Added tests for the new endpoint, covering success, validation, error cases, and database assertions.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API_Router
    participant Store/DB

    Client->>API_Router: POST /api/v1/project/{projectId}/gh-org { githubOrgUrl }
    API_Router->>API_Router: Validate projectId & githubOrgUrl
    API_Router->>Store/DB: getProjectById(projectId)
    alt Project not found
        API_Router-->>Client: 404 Project not found
    else Project found
        API_Router->>Store/DB: getAllGithubOrganizationsByProjectsId(projectId)
        alt Org already exists
            API_Router-->>Client: 409 Conflict
        else Org does not exist
            API_Router->>Store/DB: addGithubOrganization(projectId, githubOrgUrl)
            alt Success
                API_Router-->>Client: 201 Created (GithubOrganization)
            else DB Error
                API_Router-->>Client: 500 Internal Server Error
            end
        end
    end
Loading

Poem

In the warren of code, a new path appears,
Linking projects to orgs, with minimal fears.
Tests hop along, checking each flow,
Docs bloom with schemas, making it glow.
Now rabbits can cheer, with a wiggle and song—
GitHub and projects, together, hop strong!
🐇✨


📜 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 e1bc818 and 183d5bc.

📒 Files selected for processing (3)
  • __tests__/httpServer/apiV1.test.js (3 hunks)
  • src/httpServer/routers/apiV1.js (2 hunks)
  • src/httpServer/swagger/api-v1.yml (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/httpServer/routers/apiV1.js
  • tests/httpServer/apiV1.test.js
  • src/httpServer/swagger/api-v1.yml
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Playwright Tests
✨ Finishing Touches
  • 📝 Generate Docstrings

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

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: 5

🧹 Nitpick comments (2)
__tests__/httpServer/apiV1.test.js (1)

268-276: Test is tightly coupled to OpenAPI validator wording

The assertion expects the exact message
must match pattern "https://github.com/[^/]+".
Any change in the schema or the validator library will break the test while the behaviour (400) remains correct. Consider asserting only the status code and maybe the presence of an error array, e.g.

expect(response.status).toBe(400)
expect(response.body).toHaveProperty('errors')

This keeps the test valuable yet resilient.

src/httpServer/swagger/api-v1.yml (1)

214-214: Trailing whitespace detected

YAML-lint flagged trailing spaces on this line. Trim to keep the spec tidy.

🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 214-214: trailing spaces

(trailing-spaces)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3ab3fd1 and f2f7917.

📒 Files selected for processing (3)
  • __tests__/httpServer/apiV1.test.js (3 hunks)
  • src/httpServer/routers/apiV1.js (2 hunks)
  • src/httpServer/swagger/api-v1.yml (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
__tests__/httpServer/apiV1.test.js (1)
src/store/index.js (2)
  • addProject (51-61)
  • getAllGithubOrganizationsByProjectsId (135-143)
🪛 YAMLlint (1.37.1)
src/httpServer/swagger/api-v1.yml

[error] 214-214: trailing spaces

(trailing-spaces)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Playwright Tests
🔇 Additional comments (1)
src/httpServer/swagger/api-v1.yml (1)

181-186: Location header description mismatches implementation

The spec promises a Location header but the handler currently omits it (see router comment). After adding the header, ensure the example value reflects the final URL (/api/v1/project/{projectId}/gh-org/{orgId}) to keep docs & code in sync.

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: 2

🧹 Nitpick comments (7)
src/httpServer/swagger/api-v1.yml (7)

157-163: Constrain projectId to a positive integer
To prevent invalid IDs (0 or negative), add a minimum: 1 constraint under the parameter schema.


165-177: Enhance request body schema
Consider adding format: uri and a description for githubOrgUrl to improve validation and generated docs.


178-213: Add examples to responses
Include example or examples for the 201 success payload (and error cases) to aid clients and documentation.


214-214: Remove trailing spaces
YAMLlint flags trailing whitespace on this line. Please delete any extra spaces.

🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 214-214: trailing spaces

(trailing-spaces)


269-272: Manage schema complexity
The GithubOrganization object is very large. Splitting it into reusable sub-schemas or leveraging shared definitions will improve maintainability.


273-279: Add property descriptions
Fields like id and login lack description: entries. Document each property to enrich API docs.


279-479: Review extensibility of optional fields
The long list of nullable booleans and integers may be hard to maintain. Consider grouping related flags or using additionalProperties: true for less-critical fields.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f2f7917 and ee0b516.

📒 Files selected for processing (3)
  • __tests__/httpServer/apiV1.test.js (3 hunks)
  • src/httpServer/routers/apiV1.js (2 hunks)
  • src/httpServer/swagger/api-v1.yml (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/httpServer/apiV1.test.js
  • src/httpServer/routers/apiV1.js
🧰 Additional context used
🪛 YAMLlint (1.37.1)
src/httpServer/swagger/api-v1.yml

[error] 214-214: trailing spaces

(trailing-spaces)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Playwright Tests

@UlisesGascon UlisesGascon force-pushed the ulises/v1-add-gh-org branch from ee0b516 to 43f357c Compare June 15, 2025 19:02
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: 2

🧹 Nitpick comments (1)
src/httpServer/swagger/api-v1.yml (1)

214-214: Remove trailing whitespace

Line 214 has trailing spaces, which triggers a YAML linter error. Please remove the extra spaces.

🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 214-214: trailing spaces

(trailing-spaces)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ee0b516 and 43f357c.

📒 Files selected for processing (3)
  • __tests__/httpServer/apiV1.test.js (3 hunks)
  • src/httpServer/routers/apiV1.js (2 hunks)
  • src/httpServer/swagger/api-v1.yml (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/httpServer/apiV1.test.js
  • src/httpServer/routers/apiV1.js
🧰 Additional context used
🪛 YAMLlint (1.37.1)
src/httpServer/swagger/api-v1.yml

[error] 214-214: trailing spaces

(trailing-spaces)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Playwright Tests
🔇 Additional comments (3)
src/httpServer/swagger/api-v1.yml (3)

157-164: Project ID parameter is defined correctly

The projectId path parameter is now typed as integer with an appropriate example, aligning with backend expectations.


165-177: Request body schema validation is strict and well-anchored

The githubOrgUrl property is correctly marked as required, with additionalProperties: false and an anchored regex pattern to prevent invalid URLs.


179-213: Responses section follows the established pattern

All response codes (201, 400, 404, 409, 500) and the Location header on 201 are defined consistently with existing endpoints.

@UlisesGascon UlisesGascon force-pushed the ulises/v1-add-gh-org branch from 43f357c to e1bc818 Compare June 16, 2025 05:53
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: 0

♻️ Duplicate comments (2)
src/httpServer/swagger/api-v1.yml (2)

173-175: ⚠️ Potential issue

Anchor the githubOrgUrl pattern
The regex still allows trailing characters. Re-apply the earlier fix by anchoring the end of the pattern.

-                  pattern: '^https://github.com/[^/]+'
+                  pattern: '^https://github.com/[^/]+$'

270-479: 🛠️ Refactor suggestion

GithubOrganization schema still lacks a required list
Without it, the validator will happily emit partly-filled objects. At minimum mark the core fields as required:

       properties:
         id:
           type: integer
           example: 1
         ...
         project_id:
           type: integer
           example: 1
+      required:
+        - id
+        - login
+        - html_url
+        - created_at
+        - updated_at
🧹 Nitpick comments (1)
src/httpServer/swagger/api-v1.yml (1)

208-214: Trailing-space lint error
yamllint flags line 214 – remove the stray spaces to keep the spec clean.

🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 214-214: trailing spaces

(trailing-spaces)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 43f357c and e1bc818.

📒 Files selected for processing (3)
  • __tests__/httpServer/apiV1.test.js (3 hunks)
  • src/httpServer/routers/apiV1.js (2 hunks)
  • src/httpServer/swagger/api-v1.yml (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/httpServer/routers/apiV1.js
🧰 Additional context used
🧬 Code Graph Analysis (1)
__tests__/httpServer/apiV1.test.js (1)
src/store/index.js (2)
  • addProject (51-61)
  • getAllGithubOrganizationsByProjectsId (135-143)
🪛 YAMLlint (1.37.1)
src/httpServer/swagger/api-v1.yml

[error] 214-214: trailing spaces

(trailing-spaces)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Playwright Tests
🔇 Additional comments (3)
__tests__/httpServer/apiV1.test.js (3)

37-39: addProject / getAllGithubOrganizationsByProjectsId mock extraction looks good
Pulling the extra store helpers into the test context improves readability and keeps each spec self-contained.


230-259: Nice happy-path coverage
The test exercises: status, body, header and DB side-effects – exactly what we want for an endpoint contract test.


316-324: Error-message assertion will break once the OpenAPI regex is tightened
Previous reviews asked to anchor the regex with $ (see swagger file).
After that change the automatic validation message will include the $, so this assertion will fail.

- expect(response.body.errors[0]).toHaveProperty('message', 'must match pattern "^https://github.com/[^/]+"')
+ expect(response.body.errors[0]).toHaveProperty(
+   'message',
+   'must match pattern "^https://github.com/[^/]+$"'
+ )

Please adjust when you update the spec.

@UlisesGascon UlisesGascon force-pushed the ulises/v1-add-gh-org branch from e1bc818 to 183d5bc Compare June 16, 2025 06:04
@UlisesGascon UlisesGascon merged commit 5e7e681 into main Jun 16, 2025
7 checks passed
@UlisesGascon UlisesGascon deleted the ulises/v1-add-gh-org branch June 16, 2025 06:12
@UlisesGascon UlisesGascon added this to the v1.0.0 milestone Jun 16, 2025
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.

1 participant