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

Function GetPullRequest

pkg/github/pullrequests.go:163–218  ·  view source on GitHub ↗
(ctx context.Context, client *github.Client, deps ToolDependencies, owner, repo string, pullNumber int)

Source from the content-addressed store, hash-verified

161}
162
163func GetPullRequest(ctx context.Context, client *github.Client, deps ToolDependencies, owner, repo string, pullNumber int) (*mcp.CallToolResult, error) {
164 cache, err := deps.GetRepoAccessCache(ctx)
165 if err != nil {
166 return nil, fmt.Errorf("failed to get repo access cache: %w", err)
167 }
168 ff := deps.GetFlags(ctx)
169
170 pr, resp, err := client.PullRequests.Get(ctx, owner, repo, pullNumber)
171 if err != nil {
172 return ghErrors.NewGitHubAPIErrorResponse(ctx,
173 "failed to get pull request",
174 resp,
175 err,
176 ), nil
177 }
178 defer func() { _ = resp.Body.Close() }()
179
180 if resp.StatusCode != http.StatusOK {
181 body, err := io.ReadAll(resp.Body)
182 if err != nil {
183 return nil, fmt.Errorf("failed to read response body: %w", err)
184 }
185 return ghErrors.NewGitHubAPIStatusErrorResponse(ctx, "failed to get pull request", resp, body), nil
186 }
187
188 // sanitize title/body on response
189 if pr != nil {
190 if pr.Title != nil {
191 pr.Title = github.Ptr(sanitize.Sanitize(*pr.Title))
192 }
193 if pr.Body != nil {
194 pr.Body = github.Ptr(sanitize.Sanitize(*pr.Body))
195 }
196 }
197
198 if ff.LockdownMode {
199 if cache == nil {
200 return nil, fmt.Errorf("lockdown cache is not configured")
201 }
202 login := pr.GetUser().GetLogin()
203 if login != "" {
204 isSafeContent, err := cache.IsSafeContent(ctx, login, owner, repo)
205 if err != nil {
206 return nil, fmt.Errorf("failed to check content removal: %w", err)
207 }
208
209 if !isSafeContent {
210 return utils.NewToolResultError("access to pull request is restricted by lockdown mode"), nil
211 }
212 }
213 }
214
215 minimalPR := convertToMinimalPullRequest(pr)
216
217 return MarshalledTextResult(minimalPR), nil
218}
219
220func GetPullRequestDiff(ctx context.Context, client *github.Client, owner, repo string, pullNumber int) (*mcp.CallToolResult, error) {

Callers 1

PullRequestReadFunction · 0.85

Calls 8

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

Tested by

no test coverage detected