Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions pkg/github/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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

Expand Down
30 changes: 25 additions & 5 deletions pkg/github/instructions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package github

import (
"os"
"strings"
"testing"
)

Expand Down Expand Up @@ -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",
Expand All @@ -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)
Expand All @@ -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)
}
})
}
}
Loading