fix(pr): post comments to the pull request journals endpoint
pr +comment (and the conversation note posted by pr +review) wrote to POST /api/v1/:owner/:repo/issues/:issue_id/journals, which attaches the journal to the underlying issue record. Those journals never show up in GET /pulls/:id/journals — the list the PR conversation is built from — so comments posted by the CLI were invisible on the pull request page. Post to POST /api/v1/:owner/:repo/pulls/:id/journals (payload key "note") instead, which also drops the extra PR-detail fetch that was only needed to resolve the issue id. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
c09645da62
commit
3665a8698b
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue