Skip to content

Conversation

@naps62
Copy link
Member

@naps62 naps62 commented Dec 12, 2025

No description provided.

Copilot AI review requested due to automatic review settings December 12, 2025 16:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a new API endpoint to retrieve the status of a single stack by its slug, including whether the stack is currently running. The implementation follows existing patterns for authentication, authorization, and error handling in the codebase.

  • Adds GET /stacks/:slug endpoint returning stack details (slug, urls, and running status)
  • Implements is_slug_running?/1 helper function in Server module to check stack status
  • Uses existing authorization patterns to ensure users can only access their own stacks

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
lib/ethui_web/controllers/api/stack_controller.ex Adds show/2 action with authorization, error handling, and response formatting consistent with other endpoints
lib/ethui/stacks/server.ex Adds is_slug_running?/1 public API and handle_call implementation to query instances map

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +35 to +55
def show(conn, %{"slug" => slug}) do
user = conn.assigns[:current_user]

with %Stack{} = stack <- Repo.get_by(Stack, slug: slug),
:ok <- authorize_user_access(user, stack) do
json(conn, %{
status: "success",
data: %{
slug: stack.slug,
urls: Stacks.get_urls(stack),
status: if(Server.is_slug_running?(slug), do: "running", else: "stopped")
}
})
else
nil ->
conn |> put_status(404) |> json(%{status: "error", error: "not found"})

{:error, :unauthorized} ->
conn |> put_status(403) |> json(%{status: "error", error: "unauthorized"})
end
end
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

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

The new show endpoint lacks test coverage. Based on existing tests in stack_controller_test.exs, the following scenarios should be tested:

  1. Successfully retrieving a stack owned by the authenticated user (returns 200 with status, slug, urls)
  2. Attempting to retrieve a stack owned by another user (returns 403 unauthorized)
  3. Attempting to retrieve a non-existent stack (returns 404 not found)
  4. Correctly reporting running vs stopped status based on Server state

These tests would ensure the authentication/authorization logic and response formatting work correctly.

Copilot uses AI. Check for mistakes.
Comment on lines +38 to +42
@doc "Check if a stack with the given slug is running"
@spec is_slug_running?(slug) :: boolean
def is_slug_running?(slug) do
GenServer.call(__MODULE__, {:is_slug_running, slug})
end
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

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

The new is_slug_running? function lacks test coverage. Based on existing tests in server_test.exs, tests should verify:

  1. Returns false when no stack with the given slug is running
  2. Returns true when a stack with the given slug is running
  3. Returns false after a stack is stopped

This would ensure the function correctly queries the instances map state.

Copilot uses AI. Check for mistakes.
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