Skip to content

Commit 046f994

Browse files
committed
feat: enhance UpdatePullRequest to return early if no updates or reviewers are provided
1 parent 0674183 commit 046f994

File tree

1 file changed

+6
-31
lines changed

1 file changed

+6
-31
lines changed

pkg/github/pullrequests.go

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,11 @@ func UpdatePullRequest(getClient GetClientFn, t translations.TranslationHelperFu
304304
return mcp.NewToolResultError(err.Error()), nil
305305
}
306306

307+
// If no updates and no reviewers, return error early
308+
if !updateNeeded && len(reviewers) == 0 {
309+
return mcp.NewToolResultError("No update parameters provided"), nil
310+
}
311+
307312
// Create the GitHub client
308313
client, err := getClient(ctx)
309314
if err != nil {
@@ -313,7 +318,7 @@ func UpdatePullRequest(getClient GetClientFn, t translations.TranslationHelperFu
313318
var pr *github.PullRequest
314319
var resp *http.Response
315320

316-
// First, update the PR if needed
321+
// Update the PR if needed
317322
if updateNeeded {
318323
var ghResp *github.Response
319324
pr, ghResp, err = client.PullRequests.Edit(ctx, owner, repo, pullNumber, update)
@@ -338,31 +343,6 @@ func UpdatePullRequest(getClient GetClientFn, t translations.TranslationHelperFu
338343
}
339344
return mcp.NewToolResultError(fmt.Sprintf("failed to update pull request: %s", string(body))), nil
340345
}
341-
} else {
342-
// If no update needed, just get the current PR
343-
var ghResp *github.Response
344-
pr, ghResp, err = client.PullRequests.Get(ctx, owner, repo, pullNumber)
345-
if err != nil {
346-
return ghErrors.NewGitHubAPIErrorResponse(ctx,
347-
"failed to get pull request",
348-
ghResp,
349-
err,
350-
), nil
351-
}
352-
resp = ghResp.Response
353-
defer func() {
354-
if resp != nil && resp.Body != nil {
355-
_ = resp.Body.Close()
356-
}
357-
}()
358-
359-
if resp.StatusCode != http.StatusOK {
360-
body, err := io.ReadAll(resp.Body)
361-
if err != nil {
362-
return nil, fmt.Errorf("failed to read response body: %w", err)
363-
}
364-
return mcp.NewToolResultError(fmt.Sprintf("failed to get pull request: %s", string(body))), nil
365-
}
366346
}
367347

368348
// Add reviewers if specified
@@ -398,11 +378,6 @@ func UpdatePullRequest(getClient GetClientFn, t translations.TranslationHelperFu
398378
pr = updatedPR
399379
}
400380

401-
// If no updates and no reviewers, return error
402-
if !updateNeeded && len(reviewers) == 0 {
403-
return mcp.NewToolResultError("No update parameters provided"), nil
404-
}
405-
406381
r, err := json.Marshal(pr)
407382
if err != nil {
408383
return nil, fmt.Errorf("failed to marshal response: %w", err)

0 commit comments

Comments
 (0)