diff --git a/shortcuts/pr/pr.go b/shortcuts/pr/pr.go index 03f537f..52b5e02 100644 --- a/shortcuts/pr/pr.go +++ b/shortcuts/pr/pr.go @@ -383,17 +383,12 @@ func Shortcuts(translators ...*i18n.Translator) []*common.Shortcut { } // Also post a journal comment so the review is visible in the PR conversation. - prEnv, journalErr := ctx.CallAPI("GET", fmt.Sprintf("%s/pulls/%s", ctx.RepoPath(), id), nil) - if journalErr == nil { - if issueID, extractErr := extractIssueID(prEnv); extractErr == nil { - statusLabel := map[string]string{ - "approved": "approved", "rejected": "rejected", "common": "commented", - }[status] - summary := fmt.Sprintf("## Review: %s\n\n%s", statusLabel, content) - ctx.CallAPI("POST", fmt.Sprintf("/v1/%s/%s/issues/%d/journals", ctx.Owner, ctx.Repo, issueID), - map[string]interface{}{"notes": summary}) - } - } + statusLabel := map[string]string{ + "approved": "approved", "rejected": "rejected", "common": "commented", + }[status] + summary := fmt.Sprintf("## Review: %s\n\n%s", statusLabel, content) + ctx.CallAPI("POST", fmt.Sprintf("%s/pulls/%s/journals", v1RepoPath(ctx), id), + map[string]interface{}{"note": summary}) return ctx.Output(env) }, @@ -412,19 +407,10 @@ func Shortcuts(translators ...*i18n.Translator) []*common.Shortcut { id, _ := ctx.RequireArg("id") body, _ := ctx.RequireArg("body") - prEnv, err := ctx.CallAPI("GET", fmt.Sprintf("%s/pulls/%s", ctx.RepoPath(), id), nil) - if err != nil { - return fmt.Errorf("fetch PR: %w", err) - } - issueID, err := extractIssueID(prEnv) - if err != nil { - return err - } - payload := map[string]interface{}{ - "notes": body, + "note": body, } - env, err := ctx.CallAPI("POST", fmt.Sprintf("/v1/%s/%s/issues/%d/journals", ctx.Owner, ctx.Repo, issueID), payload) + env, err := ctx.CallAPI("POST", fmt.Sprintf("%s/pulls/%s/journals", v1RepoPath(ctx), id), payload) if err != nil { return err } diff --git a/shortcuts/pr/pr_test.go b/shortcuts/pr/pr_test.go index eece6d9..589afe2 100644 --- a/shortcuts/pr/pr_test.go +++ b/shortcuts/pr/pr_test.go @@ -12,31 +12,17 @@ import ( "github.com/gitlink-org/gitlink-cli/shortcuts/common" ) -func TestPRCommentPostsToCorrectIssueJournal(t *testing.T) { +func TestPRCommentPostsToPullJournals(t *testing.T) { var journalPayload map[string]interface{} - var journalPath string server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - switch { - case r.Method == "GET" && r.URL.Path == "/owner/repo/pulls/13.json": - writeJSON(t, w, map[string]interface{}{ - "issue": map[string]interface{}{ - "id": float64(142301), - "subject": "test PR", - }, - "pull_request": map[string]interface{}{ - "id": float64(14791), - }, - }) - case r.Method == "POST" && r.URL.Path == "/v1/owner/repo/issues/142301/journals.json": - journalPath = r.URL.Path - journalPayload = decodeJSON(t, r) - writeJSON(t, w, map[string]interface{}{ - "id": float64(12345), - "message": "评论成功", - }) - default: + if r.Method != "POST" || r.URL.Path != "/v1/owner/repo/pulls/13/journals.json" { t.Fatalf("unexpected request: %s %s", r.Method, r.URL.Path) } + journalPayload = decodeJSON(t, r) + writeJSON(t, w, map[string]interface{}{ + "id": float64(12345), + "note": "LGTM, looks good!", + }) })) defer server.Close() @@ -47,11 +33,7 @@ func TestPRCommentPostsToCorrectIssueJournal(t *testing.T) { if err != nil { t.Fatalf("comment shortcut failed: %v", err) } - - if journalPath == "" { - t.Fatal("journal endpoint was not called") - } - assertEqual(t, journalPayload["notes"], "LGTM, looks good!") + assertEqual(t, journalPayload["note"], "LGTM, looks good!") } func TestPRCommentFailsWhenPRNotFound(t *testing.T) { @@ -73,25 +55,6 @@ func TestPRCommentFailsWhenPRNotFound(t *testing.T) { } } -func TestPRCommentFailsWhenIssueFieldMissing(t *testing.T) { - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - writeJSON(t, w, map[string]interface{}{ - "pull_request": map[string]interface{}{ - "id": float64(14791), - }, - }) - })) - defer server.Close() - - err := runPRShortcut(t, server, "comment", map[string]string{ - "id": "13", - "body": "test", - }) - if err == nil { - t.Fatal("expected error when issue field is missing, got nil") - } -} - // --- list --- func TestPRList(t *testing.T) {