MCPcopy Index your code
hub / github.com/github/github-mcp-server / GetIssueComments

Function GetIssueComments

pkg/github/issues.go:779–837  ·  view source on GitHub ↗
(ctx context.Context, client *github.Client, deps ToolDependencies, owner string, repo string, issueNumber int, pagination PaginationParams)

Source from the content-addressed store, hash-verified

777}
778
779func GetIssueComments(ctx context.Context, client *github.Client, deps ToolDependencies, owner string, repo string, issueNumber int, pagination PaginationParams) (*mcp.CallToolResult, error) {
780 cache, err := deps.GetRepoAccessCache(ctx)
781 if err != nil {
782 return nil, fmt.Errorf("failed to get repo access cache: %w", err)
783 }
784 flags := deps.GetFlags(ctx)
785
786 opts := &github.IssueListCommentsOptions{
787 ListOptions: github.ListOptions{
788 Page: pagination.Page,
789 PerPage: pagination.PerPage,
790 },
791 }
792
793 comments, resp, err := client.Issues.ListComments(ctx, owner, repo, issueNumber, opts)
794 if err != nil {
795 return nil, fmt.Errorf("failed to get issue comments: %w", err)
796 }
797 defer func() { _ = resp.Body.Close() }()
798
799 if resp.StatusCode != http.StatusOK {
800 body, err := io.ReadAll(resp.Body)
801 if err != nil {
802 return nil, fmt.Errorf("failed to read response body: %w", err)
803 }
804 return ghErrors.NewGitHubAPIStatusErrorResponse(ctx, "failed to get issue comments", resp, body), nil
805 }
806 if flags.LockdownMode {
807 if cache == nil {
808 return nil, fmt.Errorf("lockdown cache is not configured")
809 }
810 filteredComments := make([]*github.IssueComment, 0, len(comments))
811 for _, comment := range comments {
812 user := comment.User
813 if user == nil {
814 continue
815 }
816 login := user.GetLogin()
817 if login == "" {
818 continue
819 }
820 isSafeContent, err := cache.IsSafeContent(ctx, login, owner, repo)
821 if err != nil {
822 return utils.NewToolResultError(fmt.Sprintf("failed to check lockdown mode: %v", err)), nil
823 }
824 if isSafeContent {
825 filteredComments = append(filteredComments, comment)
826 }
827 }
828 comments = filteredComments
829 }
830
831 minimalComments := make([]MinimalIssueComment, 0, len(comments))
832 for _, comment := range comments {
833 minimalComments = append(minimalComments, convertToMinimalIssueComment(comment))
834 }
835
836 return MarshalledTextResult(minimalComments), nil

Callers 2

IssueReadFunction · 0.85
PullRequestReadFunction · 0.85

Calls 7

NewToolResultErrorFunction · 0.92
MarshalledTextResultFunction · 0.85
CloseMethod · 0.80
IsSafeContentMethod · 0.80
GetRepoAccessCacheMethod · 0.65
GetFlagsMethod · 0.65

Tested by

no test coverage detected