Skip to content

Commit 56b2276

Browse files
cagesellchenCopilot
andcommitted
refactor(pull-requests): simplify GHES resolution gate
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 683b550 commit 56b2276

4 files changed

Lines changed: 22 additions & 21 deletions

File tree

pkg/github/granular_tools_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ func TestGranularToolSnaps(t *testing.T) {
5656
GranularSubmitPendingPullRequestReview,
5757
GranularDeletePendingPullRequestReview,
5858
GranularAddPullRequestReviewComment,
59-
func(t translations.TranslationHelperFunc) inventory.ServerTool {
60-
return GranularResolveReviewThread(t)
61-
},
59+
GranularResolveReviewThread,
6260
GranularUnresolveReviewThread,
6361
GranularAddPullRequestReviewCommentReaction,
6462
}

pkg/github/pullrequests.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,18 +1771,22 @@ type PullRequestReviewWriteParams struct {
17711771
ResolutionReason *string
17721772
}
17731773

1774-
func PullRequestReviewWrite(t translations.TranslationHelperFunc, opts ...ToolOption) inventory.ServerTool {
1775-
return pullRequestReviewWrite(t, false, newToolConfig(opts))
1774+
func PullRequestReviewWrite(t translations.TranslationHelperFunc) inventory.ServerTool {
1775+
return pullRequestReviewWrite(t, false, toolConfig{})
17761776
}
17771777

17781778
// PullRequestReviewWriteWithResolutionReason creates the feature-gated review write variant with resolution reasons.
17791779
func PullRequestReviewWriteWithResolutionReason(t translations.TranslationHelperFunc, opts ...ToolOption) inventory.ServerTool {
1780-
return pullRequestReviewWrite(t, true, newToolConfig(opts))
1780+
cfg := newToolConfig(opts)
1781+
st := pullRequestReviewWrite(t, true, cfg)
1782+
if cfg.hostType == utils.HostTypeGHES {
1783+
st.Enabled = func(context.Context) (bool, error) { return false, nil }
1784+
}
1785+
return st
17811786
}
17821787

17831788
func pullRequestReviewWrite(t translations.TranslationHelperFunc, withResolutionReason bool, cfg toolConfig) inventory.ServerTool {
1784-
available := !withResolutionReason || cfg.hostType != utils.HostTypeGHES
1785-
withResolutionReason = withResolutionReason && available
1789+
withResolutionReason = withResolutionReason && cfg.hostType != utils.HostTypeGHES
17861790

17871791
schema := &jsonschema.Schema{
17881792
Type: "object",
@@ -1899,9 +1903,6 @@ Available methods:
18991903
st.FeatureFlagDisable = append(st.FeatureFlagDisable, FeatureFlagThreadResolutionReason)
19001904
}
19011905
}
1902-
if !available {
1903-
st.Enabled = func(context.Context) (bool, error) { return false, nil }
1904-
}
19051906
return st
19061907
}
19071908

pkg/github/pullrequests_granular.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -671,18 +671,22 @@ func GranularAddPullRequestReviewComment(t translations.TranslationHelperFunc) i
671671
}
672672

673673
// GranularResolveReviewThread creates a tool to resolve a review thread.
674-
func GranularResolveReviewThread(t translations.TranslationHelperFunc, opts ...ToolOption) inventory.ServerTool {
675-
return granularResolveReviewThread(t, false, newToolConfig(opts))
674+
func GranularResolveReviewThread(t translations.TranslationHelperFunc) inventory.ServerTool {
675+
return granularResolveReviewThread(t, false, toolConfig{})
676676
}
677677

678678
// GranularResolveReviewThreadWithResolutionReason creates the feature-gated variant with resolution reasons.
679679
func GranularResolveReviewThreadWithResolutionReason(t translations.TranslationHelperFunc, opts ...ToolOption) inventory.ServerTool {
680-
return granularResolveReviewThread(t, true, newToolConfig(opts))
680+
cfg := newToolConfig(opts)
681+
st := granularResolveReviewThread(t, true, cfg)
682+
if cfg.hostType == utils.HostTypeGHES {
683+
st.Enabled = func(context.Context) (bool, error) { return false, nil }
684+
}
685+
return st
681686
}
682687

683688
func granularResolveReviewThread(t translations.TranslationHelperFunc, withResolutionReason bool, cfg toolConfig) inventory.ServerTool {
684-
available := !withResolutionReason || cfg.hostType != utils.HostTypeGHES
685-
withResolutionReason = withResolutionReason && available
689+
withResolutionReason = withResolutionReason && cfg.hostType != utils.HostTypeGHES
686690

687691
properties := map[string]*jsonschema.Schema{
688692
"threadID": {
@@ -750,9 +754,6 @@ func granularResolveReviewThread(t translations.TranslationHelperFunc, withResol
750754
} else if cfg.hostType != utils.HostTypeGHES {
751755
st.FeatureFlagDisable = []string{FeatureFlagThreadResolutionReason}
752756
}
753-
if !available {
754-
st.Enabled = func(context.Context) (bool, error) { return false, nil }
755-
}
756757
return st
757758
}
758759

pkg/github/tools.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ func newToolConfig(opts []ToolOption) toolConfig {
210210
// AllTools returns all tools with their embedded toolset metadata.
211211
// Tool functions return ServerTool directly with toolset info.
212212
func AllTools(t translations.TranslationHelperFunc, opts ...ToolOption) []inventory.ServerTool {
213+
cfg := newToolConfig(opts)
213214
return withCSVOutput([]inventory.ServerTool{
214215
// Context tools
215216
GetMe(t),
@@ -272,7 +273,7 @@ func AllTools(t translations.TranslationHelperFunc, opts ...ToolOption) []invent
272273
UpdatePullRequestBranch(t),
273274
CreatePullRequest(t),
274275
UpdatePullRequest(t),
275-
PullRequestReviewWrite(t, opts...),
276+
pullRequestReviewWrite(t, false, cfg),
276277
PullRequestReviewWriteWithResolutionReason(t, opts...),
277278
AddCommentToPendingReview(t),
278279
AddReplyToPullRequestComment(t),
@@ -372,7 +373,7 @@ func AllTools(t translations.TranslationHelperFunc, opts ...ToolOption) []invent
372373
GranularSubmitPendingPullRequestReview(t),
373374
GranularDeletePendingPullRequestReview(t),
374375
GranularAddPullRequestReviewComment(t),
375-
GranularResolveReviewThread(t, opts...),
376+
granularResolveReviewThread(t, false, cfg),
376377
GranularResolveReviewThreadWithResolutionReason(t, opts...),
377378
GranularUnresolveReviewThread(t),
378379
GranularAddPullRequestReviewCommentReaction(t),

0 commit comments

Comments
 (0)