Skip to content

Commit f21928a

Browse files
authored
Add support for structured issue queries
1 parent d7c32ff commit f21928a

File tree

5 files changed

+352
-177
lines changed

5 files changed

+352
-177
lines changed

pkg/github/find_closing_prs_integration_test.go

Lines changed: 51 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,44 @@ func TestFindClosingPullRequestsIntegration(t *testing.T) {
3737
// Test cases with known GitHub issues that were closed by PRs
3838
testCases := []struct {
3939
name string
40-
issues []string
40+
owner string
41+
repo string
42+
issueNumbers []int
43+
issueReferences []string
4144
expectedResults int
4245
expectSomeClosingPRs bool
4346
expectSpecificIssue string
4447
expectSpecificPRNumber int
4548
}{
4649
{
47-
name: "Single issue - VS Code well-known closed issue",
48-
issues: []string{"microsoft/vscode#123456"}, // This is a made-up issue for testing
50+
name: "Single issue using issue_numbers - VS Code well-known closed issue",
51+
owner: "microsoft",
52+
repo: "vscode",
53+
issueNumbers: []int{123456}, // This is a made-up issue for testing
4954
expectedResults: 1,
5055
expectSomeClosingPRs: false, // We expect this to not exist or have no closing PRs
5156
},
5257
{
53-
name: "Multiple issues with mixed results",
54-
issues: []string{"octocat/Hello-World#1", "microsoft/vscode#999999"},
58+
name: "Multiple issues using issue_numbers with mixed results",
59+
owner: "microsoft",
60+
repo: "vscode",
61+
issueNumbers: []int{1, 999999},
5562
expectedResults: 2,
5663
expectSomeClosingPRs: false, // These are likely non-existent or have no closing PRs
5764
},
5865
{
59-
name: "Issue from a popular repo - React",
60-
issues: []string{"facebook/react#1"}, // Very first issue in React repo
66+
name: "Issue from a popular repo using issue_numbers - React",
67+
owner: "facebook",
68+
repo: "react",
69+
issueNumbers: []int{1}, // Very first issue in React repo
6170
expectedResults: 1,
6271
},
72+
{
73+
name: "Cross-repository queries using issue_references",
74+
issueReferences: []string{"octocat/Hello-World#1", "facebook/react#1"},
75+
expectedResults: 2,
76+
expectSomeClosingPRs: false, // These might have closing PRs
77+
},
6378
}
6479

6580
ctx := context.Background()
@@ -68,8 +83,16 @@ func TestFindClosingPullRequestsIntegration(t *testing.T) {
6883
t.Run(tc.name, func(t *testing.T) {
6984
// Create request arguments
7085
args := map[string]interface{}{
71-
"issues": tc.issues,
72-
"limit": 5,
86+
"limit": 5,
87+
}
88+
89+
// Add appropriate parameters based on test case
90+
if len(tc.issueNumbers) > 0 {
91+
args["owner"] = tc.owner
92+
args["repo"] = tc.repo
93+
args["issue_numbers"] = tc.issueNumbers
94+
} else if len(tc.issueReferences) > 0 {
95+
args["issue_references"] = tc.issueReferences
7396
}
7497

7598
// Create mock request
@@ -101,7 +124,7 @@ func TestFindClosingPullRequestsIntegration(t *testing.T) {
101124

102125
// Parse JSON response
103126
var response struct {
104-
Results []FindClosingPRsResult `json:"results"`
127+
Results []map[string]interface{} `json:"results"`
105128
}
106129
err := json.Unmarshal([]byte(textResult), &response)
107130
require.NoError(t, err, "Failed to parse JSON response")
@@ -110,35 +133,28 @@ func TestFindClosingPullRequestsIntegration(t *testing.T) {
110133
assert.Len(t, response.Results, tc.expectedResults, "Expected specific number of results")
111134

112135
for i, result := range response.Results {
113-
t.Logf("Issue %d: %s", i+1, result.Issue)
114-
t.Logf(" Owner: %s, Repo: %s, Number: %d", result.Owner, result.Repo, result.IssueNumber)
115-
t.Logf(" Total closing PRs: %d", result.TotalCount)
116-
t.Logf(" Error: %s", result.Error)
136+
t.Logf("Issue %d:", i+1)
137+
t.Logf(" Owner: %v, Repo: %v, Number: %v", result["owner"], result["repo"], result["issue_number"])
138+
t.Logf(" Total closing PRs: %v", result["total_count"])
117139

118-
// Verify basic structure
119-
assert.NotEmpty(t, result.Issue, "Issue reference should not be empty")
120-
assert.NotEmpty(t, result.Owner, "Owner should not be empty")
121-
assert.NotEmpty(t, result.Repo, "Repo should not be empty")
122-
assert.Greater(t, result.IssueNumber, 0, "Issue number should be positive")
123-
124-
// Log closing PRs if any
125-
for j, pr := range result.ClosingPullRequests {
126-
t.Logf(" PR %d: #%d - %s", j+1, pr.Number, pr.Title)
127-
t.Logf(" State: %s, Merged: %t", pr.State, pr.Merged)
128-
t.Logf(" URL: %s", pr.URL)
140+
if errorMsg, hasError := result["error"]; hasError {
141+
t.Logf(" Error: %v", errorMsg)
129142
}
130143

131-
// Check for expected specific results
132-
if tc.expectSpecificIssue != "" && result.Issue == tc.expectSpecificIssue {
133-
if tc.expectSpecificPRNumber > 0 {
134-
found := false
135-
for _, pr := range result.ClosingPullRequests {
136-
if pr.Number == tc.expectSpecificPRNumber {
137-
found = true
138-
break
139-
}
144+
// Verify basic structure
145+
assert.NotEmpty(t, result["owner"], "Owner should not be empty")
146+
assert.NotEmpty(t, result["repo"], "Repo should not be empty")
147+
assert.NotNil(t, result["issue_number"], "Issue number should not be nil")
148+
149+
// Check closing PRs if any
150+
if closingPRs, ok := result["closing_pull_requests"].([]interface{}); ok {
151+
t.Logf(" Found %d closing PRs", len(closingPRs))
152+
for j, pr := range closingPRs {
153+
if prMap, ok := pr.(map[string]interface{}); ok {
154+
t.Logf(" PR %d: #%v - %v", j+1, prMap["number"], prMap["title"])
155+
t.Logf(" State: %v, Merged: %v", prMap["state"], prMap["merged"])
156+
t.Logf(" URL: %v", prMap["url"])
140157
}
141-
assert.True(t, found, "Expected to find specific PR number")
142158
}
143159
}
144160
}

0 commit comments

Comments
 (0)