Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcad048b

Browse files
authored
use go-github to remove sub issue (#856)
1 parent0b80f68 commitcad048b

File tree

1 file changed

+33
-61
lines changed

1 file changed

+33
-61
lines changed

‎pkg/github/issues.go‎

Lines changed: 33 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -506,67 +506,39 @@ func RemoveSubIssue(getClient GetClientFn, t translations.TranslationHelperFunc)
506506
}
507507

508508
client,err:=getClient(ctx)
509-
iferr!=nil {
510-
returnnil,fmt.Errorf("failed to get GitHub client: %w",err)
511-
}
512-
513-
// Create the request body
514-
requestBody:=map[string]interface{}{
515-
"sub_issue_id":subIssueID,
516-
}
517-
reqBodyBytes,err:=json.Marshal(requestBody)
518-
iferr!=nil {
519-
returnnil,fmt.Errorf("failed to marshal request body: %w",err)
520-
}
521-
522-
// Create the HTTP request
523-
url:=fmt.Sprintf("%srepos/%s/%s/issues/%d/sub_issue",
524-
client.BaseURL.String(),owner,repo,issueNumber)
525-
req,err:=http.NewRequestWithContext(ctx,"DELETE",url,strings.NewReader(string(reqBodyBytes)))
526-
iferr!=nil {
527-
returnnil,fmt.Errorf("failed to create request: %w",err)
528-
}
529-
req.Header.Set("Accept","application/vnd.github+json")
530-
req.Header.Set("Content-Type","application/json")
531-
req.Header.Set("X-GitHub-Api-Version","2022-11-28")
532-
533-
httpClient:=client.Client()// Use authenticated GitHub client
534-
resp,err:=httpClient.Do(req)
535-
iferr!=nil {
536-
varghResp*github.Response
537-
ifresp!=nil {
538-
ghResp=&github.Response{Response:resp}
539-
}
540-
returnghErrors.NewGitHubAPIErrorResponse(ctx,
541-
"failed to remove sub-issue",
542-
ghResp,
543-
err,
544-
),nil
545-
}
546-
deferfunc() {_=resp.Body.Close() }()
547-
548-
body,err:=io.ReadAll(resp.Body)
549-
iferr!=nil {
550-
returnnil,fmt.Errorf("failed to read response body: %w",err)
551-
}
552-
553-
ifresp.StatusCode!=http.StatusOK {
554-
returnmcp.NewToolResultError(fmt.Sprintf("failed to remove sub-issue: %s",string(body))),nil
555-
}
556-
557-
// Parse and re-marshal to ensure consistent formatting
558-
varresultinterface{}
559-
iferr:=json.Unmarshal(body,&result);err!=nil {
560-
returnnil,fmt.Errorf("failed to unmarshal response: %w",err)
561-
}
562-
563-
r,err:=json.Marshal(result)
564-
iferr!=nil {
565-
returnnil,fmt.Errorf("failed to marshal response: %w",err)
566-
}
567-
568-
returnmcp.NewToolResultText(string(r)),nil
569-
}
509+
iferr!=nil {
510+
returnnil,fmt.Errorf("failed to get GitHub client: %w",err)
511+
}
512+
513+
subIssueRequest:= github.SubIssueRequest{
514+
SubIssueID:int64(subIssueID),
515+
}
516+
517+
subIssue,resp,err:=client.SubIssue.Remove(ctx,owner,repo,int64(issueNumber),subIssueRequest)
518+
iferr!=nil {
519+
returnghErrors.NewGitHubAPIErrorResponse(ctx,
520+
"failed to remove sub-issue",
521+
resp,
522+
err,
523+
),nil
524+
}
525+
deferfunc() {_=resp.Body.Close() }()
526+
527+
ifresp.StatusCode!=http.StatusOK {
528+
body,err:=io.ReadAll(resp.Body)
529+
iferr!=nil {
530+
returnnil,fmt.Errorf("failed to read response body: %w",err)
531+
}
532+
returnmcp.NewToolResultError(fmt.Sprintf("failed to remove sub-issue: %s",string(body))),nil
533+
}
534+
535+
r,err:=json.Marshal(subIssue)
536+
iferr!=nil {
537+
returnnil,fmt.Errorf("failed to marshal response: %w",err)
538+
}
539+
540+
returnmcp.NewToolResultText(string(r)),nil
541+
}
570542
}
571543

572544
// ReprioritizeSubIssue creates a tool to reprioritize a sub-issue to a different position in the parent list.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp