Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c026d24d11 |
@@ -56,7 +56,6 @@ 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}/merge", h.MergePull)
|
||||
|
||||
// Settings (handled separately for auth bypass).
|
||||
settingsHandler := &SettingsHandler{
|
||||
@@ -1103,49 +1102,3 @@ func (h *Handler) SubmitReview(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
http.Redirect(w, r, fmt.Sprintf("/pulls/%s/%s/%d", owner, repo, index), http.StatusSeeOther)
|
||||
}
|
||||
|
||||
// MergePull handles POST /pulls/{owner}/{repo}/{index}/merge.
|
||||
func (h *Handler) MergePull(w http.ResponseWriter, r *http.Request) {
|
||||
token := getToken(r)
|
||||
owner := r.PathValue("owner")
|
||||
repo := r.PathValue("repo")
|
||||
indexStr := r.PathValue("index")
|
||||
|
||||
index, err := strconv.ParseInt(indexStr, 10, 64)
|
||||
if err != nil {
|
||||
http.Error(w, "invalid PR index", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if err := r.ParseForm(); err != nil {
|
||||
http.Error(w, "bad request", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
style := r.FormValue("Do")
|
||||
if style == "" {
|
||||
style = "merge"
|
||||
}
|
||||
title := r.FormValue("merge_title")
|
||||
message := r.FormValue("merge_message")
|
||||
|
||||
if err := h.Client.MergePull(r.Context(), token, owner, repo, index, style, title, message); err != nil {
|
||||
slog.Error("failed to merge pull request", "error", err, "owner", owner, "repo", repo, "index", index)
|
||||
if isHTMX(r) {
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
fmt.Fprint(w, `<span style="color:#f85149">Failed to merge pull request.</span>`)
|
||||
return
|
||||
}
|
||||
http.Error(w, "failed to merge pull request", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if isHTMX(r) {
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
fmt.Fprint(w, `<span style="color:#a371f7;font-weight:bold">Merged</span>`)
|
||||
return
|
||||
}
|
||||
|
||||
http.Redirect(w, r, fmt.Sprintf("/pulls/%s/%s/%d", owner, repo, index), http.StatusSeeOther)
|
||||
}
|
||||
|
||||
@@ -185,11 +185,6 @@ func mockGiteaAPI(t *testing.T) *httptest.Server {
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{"id": 1, "state": "APPROVED"})
|
||||
})
|
||||
|
||||
// POST /api/v1/repos/{owner}/{repo}/pulls/{index}/merge — merge PR.
|
||||
mux.HandleFunc("POST /api/v1/repos/{owner}/{repo}/pulls/{index}/merge", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
})
|
||||
|
||||
// POST /api/v1/markdown — render markdown.
|
||||
mux.HandleFunc("POST /api/v1/markdown", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
@@ -494,6 +489,78 @@ func TestIntegration_PullDetail_InvalidIndex(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// --- Issue #217: HTMX fragment assertions for IssueDetail and PullDetail ---
|
||||
|
||||
func TestIntegration_IssueDetail_HTMX(t *testing.T) {
|
||||
h, srv := newTestHandlerWithMock(t)
|
||||
defer srv.Close()
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("GET /issues/{owner}/{repo}/{index}", h.IssueDetail)
|
||||
|
||||
req := reqWithToken(http.MethodGet, "/issues/test-org/repo1/1", "")
|
||||
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()
|
||||
|
||||
// HTMX response must NOT contain layout boilerplate.
|
||||
if contains(body, "<html") {
|
||||
t.Error("HTMX response should not contain <html tag")
|
||||
}
|
||||
if contains(body, "<!DOCTYPE") {
|
||||
t.Error("HTMX response should not contain <!DOCTYPE")
|
||||
}
|
||||
if contains(body, `class="bottom-nav"`) {
|
||||
t.Error("HTMX response should not contain bottom-nav")
|
||||
}
|
||||
|
||||
// HTMX response MUST contain issue-specific content.
|
||||
if !contains(body, "Test issue #1") {
|
||||
t.Errorf("expected issue title 'Test issue #1' in HTMX fragment, got: %s", body[:min(300, len(body))])
|
||||
}
|
||||
}
|
||||
|
||||
func TestIntegration_PullDetail_HTMX(t *testing.T) {
|
||||
h, srv := newTestHandlerWithMock(t)
|
||||
defer srv.Close()
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("GET /pulls/{owner}/{repo}/{index}", h.PullDetail)
|
||||
|
||||
req := reqWithToken(http.MethodGet, "/pulls/test-org/repo1/1", "")
|
||||
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()
|
||||
|
||||
// HTMX response must NOT contain layout boilerplate.
|
||||
if contains(body, "<html") {
|
||||
t.Error("HTMX response should not contain <html tag")
|
||||
}
|
||||
if contains(body, "<!DOCTYPE") {
|
||||
t.Error("HTMX response should not contain <!DOCTYPE")
|
||||
}
|
||||
if contains(body, `class="bottom-nav"`) {
|
||||
t.Error("HTMX response should not contain bottom-nav")
|
||||
}
|
||||
|
||||
// HTMX response MUST contain PR-specific content.
|
||||
if !contains(body, "Test PR #1") {
|
||||
t.Errorf("expected PR title 'Test PR #1' in HTMX fragment, got: %s", body[:min(300, len(body))])
|
||||
}
|
||||
}
|
||||
|
||||
// --- Issue #138: Integration tests for GET /issues/new and GET /issues/new/labels ---
|
||||
|
||||
func TestIntegration_NewIssue_WithToken(t *testing.T) {
|
||||
@@ -922,67 +989,6 @@ func TestIntegration_SubmitReview_RequestChanges(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// --- Issue #229: Integration tests for POST /pulls/{owner}/{repo}/{index}/merge ---
|
||||
|
||||
func TestIntegration_MergePull_Valid(t *testing.T) {
|
||||
h, srv := newTestHandlerWithMock(t)
|
||||
defer srv.Close()
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("POST /pulls/{owner}/{repo}/{index}/merge", h.MergePull)
|
||||
|
||||
form := url.Values{"Do": {"merge"}}
|
||||
req := reqWithToken(http.MethodPost, "/pulls/test-org/repo1/1/merge", 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_MergePull_HTMX(t *testing.T) {
|
||||
h, srv := newTestHandlerWithMock(t)
|
||||
defer srv.Close()
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("POST /pulls/{owner}/{repo}/{index}/merge", h.MergePull)
|
||||
|
||||
form := url.Values{"Do": {"squash"}}
|
||||
req := reqWithToken(http.MethodPost, "/pulls/test-org/repo1/1/merge", 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, "Merged") {
|
||||
t.Errorf("expected 'Merged' in HTMX response, got: %s", body)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIntegration_MergePull_DefaultStyle(t *testing.T) {
|
||||
h, srv := newTestHandlerWithMock(t)
|
||||
defer srv.Close()
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("POST /pulls/{owner}/{repo}/{index}/merge", h.MergePull)
|
||||
|
||||
// No "Do" form value — should default to "merge".
|
||||
req := reqWithToken(http.MethodPost, "/pulls/test-org/repo1/1/merge", "")
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
mux.ServeHTTP(w, req)
|
||||
|
||||
if w.Code != http.StatusSeeOther {
|
||||
t.Errorf("status = %d, want %d", w.Code, http.StatusSeeOther)
|
||||
}
|
||||
}
|
||||
|
||||
// --- Issue #110: Integration tests for POST /issues/{owner}/{repo}/{index}/labels ---
|
||||
|
||||
func TestIntegration_ApplyLabels_Valid(t *testing.T) {
|
||||
|
||||
@@ -33,23 +33,6 @@
|
||||
{{end}}
|
||||
</div>
|
||||
|
||||
{{if and .Pull.Mergeable (eq .Pull.State "open")}}
|
||||
<div class="card" style="margin-top:1rem;" id="merge-section">
|
||||
<h2>Merge Pull Request</h2>
|
||||
<form hx-post="/pulls/{{.Pull.RepoOwner}}/{{.Pull.RepoName}}/{{.Pull.Number}}/merge" hx-target="#merge-section" hx-swap="innerHTML">
|
||||
<div class="form-group">
|
||||
<label for="merge-style">Merge Style</label>
|
||||
<select id="merge-style" name="Do">
|
||||
<option value="merge">Merge Commit</option>
|
||||
<option value="rebase">Rebase</option>
|
||||
<option value="squash">Squash</option>
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary" style="background-color:var(--accent-purple,#a371f7);">Merge PR</button>
|
||||
</form>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
<div class="card" style="margin-top:1rem;">
|
||||
<h2>Submit Review</h2>
|
||||
<form hx-post="/pulls/{{.Pull.RepoOwner}}/{{.Pull.RepoName}}/{{.Pull.Number}}/review" hx-swap="outerHTML">
|
||||
|
||||
Reference in New Issue
Block a user