Skip to content

Commit 34465bd

Browse files
committed
update to use go github v73
1 parent 26469ad commit 34465bd

1 file changed

Lines changed: 36 additions & 56 deletions

File tree

pkg/github/issues.go

Lines changed: 36 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ func ReprioritizeSubIssue(getClient GetClientFn, t translations.TranslationHelpe
457457
),
458458
mcp.WithNumber("sub_issue_id",
459459
mcp.Required(),
460-
mcp.Description("The ID of the sub-issue to reprioritize"),
460+
mcp.Description("The ID of the sub-issue to reprioritize. Note: This is NOT the same as the issue number."),
461461
),
462462
mcp.WithNumber("after_id",
463463
mcp.Description("The ID of the sub-issue to be prioritized after (either after_id OR before_id should be specified)"),
@@ -503,68 +503,48 @@ func ReprioritizeSubIssue(getClient GetClientFn, t translations.TranslationHelpe
503503
}
504504

505505
client, err := getClient(ctx)
506-
if err != nil {
507-
return nil, fmt.Errorf("failed to get GitHub client: %w", err)
508-
}
509-
510-
// Create the request body
511-
requestBody := map[string]interface{}{
512-
"sub_issue_id": subIssueID,
513-
}
514-
if afterID != 0 {
515-
requestBody["after_id"] = afterID
516-
}
517-
if beforeID != 0 {
518-
requestBody["before_id"] = beforeID
519-
}
520-
521-
// Since the go-github library might not have sub-issues support yet,
522-
// we'll make a direct HTTP request using the client's HTTP client
523-
reqBodyBytes, err := json.Marshal(requestBody)
524-
if err != nil {
525-
return nil, fmt.Errorf("failed to marshal request body: %w", err)
526-
}
527-
528-
url := fmt.Sprintf("%srepos/%s/%s/issues/%d/sub_issues/priority",
529-
client.BaseURL.String(), owner, repo, issueNumber)
530-
req, err := http.NewRequestWithContext(ctx, "PATCH", url, strings.NewReader(string(reqBodyBytes)))
531-
if err != nil {
532-
return nil, fmt.Errorf("failed to create request: %w", err)
533-
}
506+
if err != nil {
507+
return nil, fmt.Errorf("failed to get GitHub client: %w", err)
508+
}
534509

535-
req.Header.Set("Accept", "application/vnd.github+json")
536-
req.Header.Set("Content-Type", "application/json")
537-
req.Header.Set("X-GitHub-Api-Version", "2022-11-28")
510+
subIssueRequest := github.SubIssueRequest{
511+
SubIssueID: int64(subIssueID),
512+
}
538513

539-
// Use the same authentication as the GitHub client
540-
httpClient := client.Client()
541-
resp, err := httpClient.Do(req)
542-
if err != nil {
543-
return nil, fmt.Errorf("failed to reprioritize sub-issue: %w", err)
544-
}
545-
defer func() { _ = resp.Body.Close() }()
514+
if afterID != 0 {
515+
afterIDInt64 := int64(afterID)
516+
subIssueRequest.AfterID = &afterIDInt64
517+
}
518+
if beforeID != 0 {
519+
beforeIDInt64 := int64(beforeID)
520+
subIssueRequest.BeforeID = &beforeIDInt64
521+
}
546522

547-
body, err := io.ReadAll(resp.Body)
548-
if err != nil {
549-
return nil, fmt.Errorf("failed to read response body: %w", err)
550-
}
523+
subIssue, resp, err := client.SubIssue.Reprioritize(ctx, owner, repo, int64(issueNumber), subIssueRequest)
524+
if err != nil {
525+
return ghErrors.NewGitHubAPIErrorResponse(ctx,
526+
"failed to reprioritize sub-issue",
527+
resp,
528+
err,
529+
), nil
530+
}
551531

552-
if resp.StatusCode != http.StatusOK {
553-
return mcp.NewToolResultError(fmt.Sprintf("failed to reprioritize sub-issue: %s", string(body))), nil
554-
}
532+
defer func() { _ = resp.Body.Close() }()
555533

556-
// Parse and re-marshal to ensure consistent formatting
557-
var result interface{}
558-
if err := json.Unmarshal(body, &result); err != nil {
559-
return nil, fmt.Errorf("failed to unmarshal response: %w", err)
560-
}
534+
if resp.StatusCode != http.StatusOK {
535+
body, err := io.ReadAll(resp.Body)
536+
if err != nil {
537+
return nil, fmt.Errorf("failed to read response body: %w", err)
538+
}
539+
return mcp.NewToolResultError(fmt.Sprintf("failed to reprioritize sub-issue: %s", string(body))), nil
540+
}
561541

562-
r, err := json.Marshal(result)
563-
if err != nil {
564-
return nil, fmt.Errorf("failed to marshal response: %w", err)
565-
}
542+
r, err := json.Marshal(subIssue)
543+
if err != nil {
544+
return nil, fmt.Errorf("failed to marshal response: %w", err)
545+
}
566546

567-
return mcp.NewToolResultText(string(r)), nil
547+
return mcp.NewToolResultText(string(r)), nil
568548
}
569549
}
570550

0 commit comments

Comments
 (0)