(ctx context.Context, client *github.Client, deps ToolDependencies, owner string, repo string, issueNumber int)
| 713 | } |
| 714 | |
| 715 | func GetIssue(ctx context.Context, client *github.Client, deps ToolDependencies, owner string, repo string, issueNumber int) (*mcp.CallToolResult, error) { |
| 716 | cache, err := deps.GetRepoAccessCache(ctx) |
| 717 | if err != nil { |
| 718 | return nil, fmt.Errorf("failed to get repo access cache: %w", err) |
| 719 | } |
| 720 | flags := deps.GetFlags(ctx) |
| 721 | |
| 722 | issue, resp, err := client.Issues.Get(ctx, owner, repo, issueNumber) |
| 723 | if err != nil { |
| 724 | return nil, fmt.Errorf("failed to get issue: %w", err) |
| 725 | } |
| 726 | defer func() { _ = resp.Body.Close() }() |
| 727 | |
| 728 | if resp.StatusCode != http.StatusOK { |
| 729 | body, err := io.ReadAll(resp.Body) |
| 730 | if err != nil { |
| 731 | return nil, fmt.Errorf("failed to read response body: %w", err) |
| 732 | } |
| 733 | return ghErrors.NewGitHubAPIStatusErrorResponse(ctx, "failed to get issue", resp, body), nil |
| 734 | } |
| 735 | |
| 736 | if flags.LockdownMode { |
| 737 | if cache == nil { |
| 738 | return nil, fmt.Errorf("lockdown cache is not configured") |
| 739 | } |
| 740 | login := issue.GetUser().GetLogin() |
| 741 | if login != "" { |
| 742 | isSafeContent, err := cache.IsSafeContent(ctx, login, owner, repo) |
| 743 | if err != nil { |
| 744 | return utils.NewToolResultError(fmt.Sprintf("failed to check lockdown mode: %v", err)), nil |
| 745 | } |
| 746 | if !isSafeContent { |
| 747 | return utils.NewToolResultError("access to issue details is restricted by lockdown mode"), nil |
| 748 | } |
| 749 | } |
| 750 | } |
| 751 | |
| 752 | // Sanitize title/body on response |
| 753 | if issue != nil { |
| 754 | if issue.Title != nil { |
| 755 | issue.Title = github.Ptr(sanitize.Sanitize(*issue.Title)) |
| 756 | } |
| 757 | if issue.Body != nil { |
| 758 | issue.Body = github.Ptr(sanitize.Sanitize(*issue.Body)) |
| 759 | } |
| 760 | } |
| 761 | |
| 762 | minimalIssue := convertToMinimalIssue(issue) |
| 763 | |
| 764 | // Always drop the verbose REST IssueFieldValues; enrich with the GraphQL |
| 765 | // field_values view instead. |
| 766 | minimalIssue.IssueFieldValues = nil |
| 767 | if issue != nil && issue.NodeID != nil && *issue.NodeID != "" { |
| 768 | gqlClient, err := deps.GetGQLClient(ctx) |
| 769 | if err == nil { |
| 770 | if fieldValuesByID, err := fetchIssueFieldValuesByNodeID(ctx, gqlClient, []*github.Issue{issue}); err == nil { |
| 771 | minimalIssue.FieldValues = fieldValuesByID[*issue.NodeID] |
| 772 | } |
no test coverage detected