diff --git a/pkg/github/instructions.go b/pkg/github/instructions.go index 338b8b987..3a5fb54bb 100644 --- a/pkg/github/instructions.go +++ b/pkg/github/instructions.go @@ -22,7 +22,7 @@ func GenerateInstructions(enabledToolsets []string) string { // Individual toolset instructions for _, toolset := range enabledToolsets { - if inst := getToolsetInstructions(toolset); inst != "" { + if inst := getToolsetInstructions(toolset, enabledToolsets); inst != "" { instructions = append(instructions, inst) } } @@ -48,12 +48,18 @@ Tool usage guidance: } // getToolsetInstructions returns specific instructions for individual toolsets -func getToolsetInstructions(toolset string) string { +func getToolsetInstructions(toolset string, enabledToolsets []string) string { switch toolset { case "pull_requests": - return `## Pull Requests + pullRequestInstructions := `## Pull Requests PR review workflow: Always use 'pull_request_review_write' with method 'create' to create a pending review, then 'add_comment_to_pending_review' to add comments, and finally 'pull_request_review_write' with method 'submit_pending' to submit the review for complex reviews with line-specific comments.` + if slices.Contains(enabledToolsets, "repos") { + pullRequestInstructions += ` + +Before creating a pull request, search for pull request templates in the repository. Template files are called pull_request_template.md or they're located in '.github/PULL_REQUEST_TEMPLATE' directory. Use the template content to structure the PR description and then call create_pull_request tool.` + } + return pullRequestInstructions case "issues": return `## Issues diff --git a/pkg/github/instructions_test.go b/pkg/github/instructions_test.go index f00e0ac74..b8ad2ba8c 100644 --- a/pkg/github/instructions_test.go +++ b/pkg/github/instructions_test.go @@ -2,6 +2,7 @@ package github import ( "os" + "strings" "testing" ) @@ -128,12 +129,23 @@ func TestGenerateInstructionsWithDisableFlag(t *testing.T) { func TestGetToolsetInstructions(t *testing.T) { tests := []struct { - toolset string - expectedEmpty bool + toolset string + expectedEmpty bool + enabledToolsets []string + expectedToContain string + notExpectedToContain string }{ { - toolset: "pull_requests", - expectedEmpty: false, + toolset: "pull_requests", + expectedEmpty: false, + enabledToolsets: []string{"pull_requests", "repos"}, + expectedToContain: "pull_request_template.md", + }, + { + toolset: "pull_requests", + expectedEmpty: false, + enabledToolsets: []string{"pull_requests"}, + notExpectedToContain: "pull_request_template.md", }, { toolset: "issues", @@ -151,7 +163,7 @@ func TestGetToolsetInstructions(t *testing.T) { for _, tt := range tests { t.Run(tt.toolset, func(t *testing.T) { - result := getToolsetInstructions(tt.toolset) + result := getToolsetInstructions(tt.toolset, tt.enabledToolsets) if tt.expectedEmpty { if result != "" { t.Errorf("Expected empty result for toolset '%s', but got: %s", tt.toolset, result) @@ -161,6 +173,14 @@ func TestGetToolsetInstructions(t *testing.T) { t.Errorf("Expected non-empty result for toolset '%s', but got empty", tt.toolset) } } + + if tt.expectedToContain != "" && !strings.Contains(result, tt.expectedToContain) { + t.Errorf("Expected result to contain '%s' for toolset '%s', but it did not. Result: %s", tt.expectedToContain, tt.toolset, result) + } + + if tt.notExpectedToContain != "" && strings.Contains(result, tt.notExpectedToContain) { + t.Errorf("Did not expect result to contain '%s' for toolset '%s', but it did. Result: %s", tt.notExpectedToContain, tt.toolset, result) + } }) } }