Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d0bcbd1ed0 |
+2
-2
@@ -7,10 +7,10 @@ COPY . .
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o /gitea-mobile ./cmd/server
|
||||
|
||||
# Stage 2: Runtime
|
||||
# Templates and static assets are embedded in the binary via go:embed,
|
||||
# so no COPY steps are needed for them.
|
||||
FROM gcr.io/distroless/static:nonroot
|
||||
COPY --from=builder /gitea-mobile /gitea-mobile
|
||||
COPY static/ /static/
|
||||
COPY internal/templates/ /templates/
|
||||
EXPOSE 8080
|
||||
USER nonroot:nonroot
|
||||
ENTRYPOINT ["/gitea-mobile"]
|
||||
|
||||
@@ -12,8 +12,6 @@ import (
|
||||
"gitea.leeworks.dev/0xwheatyz/gitea-mobile/internal/config"
|
||||
giteaclient "gitea.leeworks.dev/0xwheatyz/gitea-mobile/internal/gitea"
|
||||
"gitea.leeworks.dev/0xwheatyz/gitea-mobile/internal/middleware"
|
||||
"gitea.leeworks.dev/0xwheatyz/gitea-mobile/internal/templates"
|
||||
"gitea.leeworks.dev/0xwheatyz/gitea-mobile/static"
|
||||
)
|
||||
|
||||
// Handler holds shared dependencies for all HTTP handlers.
|
||||
@@ -58,6 +56,7 @@ func (h *Handler) RegisterRoutes(mux *http.ServeMux) {
|
||||
mux.HandleFunc("GET /pulls/{owner}/{repo}/{index}", h.PullDetail)
|
||||
mux.HandleFunc("POST /pulls/{owner}/{repo}/{index}/review", h.SubmitReview)
|
||||
mux.HandleFunc("POST /pulls/{owner}/{repo}/{index}/state", h.SetPullState)
|
||||
mux.HandleFunc("POST /pulls/{owner}/{repo}/{index}/assignees", h.AssignIssue)
|
||||
|
||||
// Settings (handled separately for auth bypass).
|
||||
settingsHandler := &SettingsHandler{
|
||||
@@ -66,8 +65,8 @@ func (h *Handler) RegisterRoutes(mux *http.ServeMux) {
|
||||
}
|
||||
mux.HandleFunc("/settings", settingsHandler.ServeHTTP)
|
||||
|
||||
// Static files — served from embedded filesystem.
|
||||
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServerFS(static.FS)))
|
||||
// Static files.
|
||||
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
|
||||
}
|
||||
|
||||
// isHTMX returns true if the request is an HTMX partial request.
|
||||
@@ -237,7 +236,7 @@ func (h *Handler) ErrorInternal(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// renderError renders the error template with the given data and status code.
|
||||
func (h *Handler) renderError(w http.ResponseWriter, r *http.Request, data errorData) {
|
||||
tmpl, err := template.ParseFS(templates.FS, "error.html")
|
||||
tmpl, err := template.ParseFiles("internal/templates/error.html")
|
||||
if err != nil {
|
||||
slog.Error("failed to parse error template", "error", err)
|
||||
http.Error(w, fmt.Sprintf("%d %s", data.Code, data.Title), data.Code)
|
||||
@@ -300,7 +299,7 @@ func (h *Handler) Dashboard(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
tmpl, err := template.ParseFS(templates.FS, "dashboard.html")
|
||||
tmpl, err := template.ParseFiles("internal/templates/dashboard.html")
|
||||
if err != nil {
|
||||
slog.Error("failed to parse dashboard template", "error", err)
|
||||
http.Error(w, "template error", http.StatusInternalServerError)
|
||||
@@ -392,7 +391,7 @@ func (h *Handler) ListIssues(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// For HTMX infinite-scroll requests (page > 1), return only the card fragment.
|
||||
if isHTMX(r) && page > 1 {
|
||||
tmpl, err := template.ParseFS(templates.FS, "issues.html")
|
||||
tmpl, err := template.ParseFiles("internal/templates/issues.html")
|
||||
if err != nil {
|
||||
slog.Error("failed to parse issues template", "error", err)
|
||||
http.Error(w, "template error", http.StatusInternalServerError)
|
||||
@@ -409,7 +408,7 @@ func (h *Handler) ListIssues(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
tmpl, err := template.ParseFS(templates.FS, "issues.html")
|
||||
tmpl, err := template.ParseFiles("internal/templates/issues.html")
|
||||
if err != nil {
|
||||
slog.Error("failed to parse issues template", "error", err)
|
||||
http.Error(w, "template error", http.StatusInternalServerError)
|
||||
@@ -504,7 +503,7 @@ func (h *Handler) ListPulls(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// For HTMX infinite-scroll requests (page > 1), return only the card fragment.
|
||||
if isHTMX(r) && page > 1 {
|
||||
tmpl, err := template.ParseFS(templates.FS, "pulls.html")
|
||||
tmpl, err := template.ParseFiles("internal/templates/pulls.html")
|
||||
if err != nil {
|
||||
slog.Error("failed to parse pulls template", "error", err)
|
||||
http.Error(w, "template error", http.StatusInternalServerError)
|
||||
@@ -521,7 +520,7 @@ func (h *Handler) ListPulls(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
tmpl, err := template.ParseFS(templates.FS, "pulls.html")
|
||||
tmpl, err := template.ParseFiles("internal/templates/pulls.html")
|
||||
if err != nil {
|
||||
slog.Error("failed to parse pulls template", "error", err)
|
||||
http.Error(w, "template error", http.StatusInternalServerError)
|
||||
@@ -589,7 +588,7 @@ func (h *Handler) IssueDetail(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// Build the content HTML using the template.
|
||||
tmpl, err := template.ParseFS(templates.FS, "issue_detail.html")
|
||||
tmpl, err := template.ParseFiles("internal/templates/issue_detail.html")
|
||||
if err != nil {
|
||||
slog.Error("failed to parse issue_detail template", "error", err)
|
||||
http.Error(w, "template error", http.StatusInternalServerError)
|
||||
@@ -662,7 +661,7 @@ func (h *Handler) PullDetail(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// Build the content HTML using the template.
|
||||
tmpl, err := template.ParseFS(templates.FS, "pull_detail.html")
|
||||
tmpl, err := template.ParseFiles("internal/templates/pull_detail.html")
|
||||
if err != nil {
|
||||
slog.Error("failed to parse pull_detail template", "error", err)
|
||||
http.Error(w, "template error", http.StatusInternalServerError)
|
||||
@@ -703,7 +702,7 @@ func (h *Handler) NewIssue(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
tmpl, err := template.ParseFS(templates.FS, "create_issue.html")
|
||||
tmpl, err := template.ParseFiles("internal/templates/create_issue.html")
|
||||
if err != nil {
|
||||
slog.Error("failed to parse create_issue template", "error", err)
|
||||
http.Error(w, "template error", http.StatusInternalServerError)
|
||||
|
||||
@@ -7,6 +7,9 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -15,8 +18,26 @@ import (
|
||||
"gitea.leeworks.dev/0xwheatyz/gitea-mobile/internal/middleware"
|
||||
)
|
||||
|
||||
// Note: TestMain is no longer needed because templates and static assets
|
||||
// are embedded at compile time via go:embed. Tests work from any directory.
|
||||
// TestMain changes the working directory to the project root so that
|
||||
// template files can be found by handlers that use relative paths.
|
||||
func TestMain(m *testing.M) {
|
||||
// Walk up from this source file to find the project root (where go.mod lives).
|
||||
_, filename, _, _ := runtime.Caller(0)
|
||||
dir := filepath.Dir(filename)
|
||||
for {
|
||||
if _, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil {
|
||||
break
|
||||
}
|
||||
parent := filepath.Dir(dir)
|
||||
if parent == dir {
|
||||
// Reached filesystem root without finding go.mod; run tests from cwd.
|
||||
break
|
||||
}
|
||||
dir = parent
|
||||
}
|
||||
_ = os.Chdir(dir)
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
// mockGiteaAPI starts an httptest server that simulates the Gitea API
|
||||
// endpoints needed by the handlers. Returns the server and a cleanup func.
|
||||
@@ -705,6 +726,66 @@ func TestIntegration_AssignIssue_MissingAssignee(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// --- Issue #228: Integration tests for POST /pulls/{owner}/{repo}/{index}/assignees ---
|
||||
|
||||
func TestIntegration_AssignPull_Valid(t *testing.T) {
|
||||
h, srv := newTestHandlerWithMock(t)
|
||||
defer srv.Close()
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("POST /pulls/{owner}/{repo}/{index}/assignees", h.AssignIssue)
|
||||
|
||||
form := url.Values{"assignee": {"user1"}}
|
||||
req := reqWithToken(http.MethodPost, "/pulls/test-org/repo1/1/assignees", form.Encode())
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
mux.ServeHTTP(w, req)
|
||||
|
||||
if w.Code != http.StatusSeeOther {
|
||||
t.Errorf("status = %d, want %d", w.Code, http.StatusSeeOther)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIntegration_AssignPull_HTMX(t *testing.T) {
|
||||
h, srv := newTestHandlerWithMock(t)
|
||||
defer srv.Close()
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("POST /pulls/{owner}/{repo}/{index}/assignees", h.AssignIssue)
|
||||
|
||||
form := url.Values{"assignee": {"user1"}}
|
||||
req := reqWithToken(http.MethodPost, "/pulls/test-org/repo1/1/assignees", form.Encode())
|
||||
req.Header.Set("HX-Request", "true")
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
mux.ServeHTTP(w, req)
|
||||
|
||||
if w.Code != http.StatusOK {
|
||||
t.Errorf("status = %d, want %d", w.Code, http.StatusOK)
|
||||
}
|
||||
body := w.Body.String()
|
||||
if !contains(body, "Assigned to user1") {
|
||||
t.Errorf("expected 'Assigned to user1' in HTMX response, got: %s", body)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIntegration_AssignPull_MissingAssignee(t *testing.T) {
|
||||
h, srv := newTestHandlerWithMock(t)
|
||||
defer srv.Close()
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("POST /pulls/{owner}/{repo}/{index}/assignees", h.AssignIssue)
|
||||
|
||||
req := reqWithToken(http.MethodPost, "/pulls/test-org/repo1/1/assignees", "")
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
mux.ServeHTTP(w, req)
|
||||
|
||||
if w.Code != http.StatusBadRequest {
|
||||
t.Errorf("status = %d, want %d", w.Code, http.StatusBadRequest)
|
||||
}
|
||||
}
|
||||
|
||||
// --- Issue #118: Integration tests for CloseIssue and AddComment ---
|
||||
|
||||
func TestIntegration_CloseIssue(t *testing.T) {
|
||||
|
||||
@@ -8,9 +8,10 @@ import (
|
||||
|
||||
"gitea.leeworks.dev/0xwheatyz/gitea-mobile/internal/auth"
|
||||
"gitea.leeworks.dev/0xwheatyz/gitea-mobile/internal/middleware"
|
||||
"gitea.leeworks.dev/0xwheatyz/gitea-mobile/internal/templates"
|
||||
)
|
||||
|
||||
const settingsTemplatePath = "internal/templates/settings.html"
|
||||
|
||||
// SettingsHandler handles GET and POST requests for the settings page.
|
||||
type SettingsHandler struct {
|
||||
SessionSecret string
|
||||
@@ -100,7 +101,7 @@ func (h *SettingsHandler) renderWithMessage(w http.ResponseWriter, r *http.Reque
|
||||
}
|
||||
|
||||
func (h *SettingsHandler) renderSettings(w http.ResponseWriter, data settingsData) {
|
||||
tmpl, err := template.ParseFS(templates.FS, "settings.html")
|
||||
tmpl, err := template.ParseFiles(settingsTemplatePath)
|
||||
if err != nil {
|
||||
slog.Error("failed to parse settings template", "error", err)
|
||||
http.Error(w, "template error", http.StatusInternalServerError)
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
// Package templates provides embedded HTML template files.
|
||||
package templates
|
||||
|
||||
import "embed"
|
||||
|
||||
// FS contains all HTML template files embedded at compile time.
|
||||
//
|
||||
//go:embed *.html
|
||||
var FS embed.FS
|
||||
@@ -1,10 +0,0 @@
|
||||
// Package static provides embedded static asset files (CSS, JS, icons, etc.).
|
||||
package static
|
||||
|
||||
import "embed"
|
||||
|
||||
// FS contains all static asset files embedded at compile time.
|
||||
// Files are served via http.FileServerFS in the handlers package.
|
||||
//
|
||||
//go:embed *.css *.js *.json *.png
|
||||
var FS embed.FS
|
||||
Reference in New Issue
Block a user