50
50
},
51
51
}
52
52
53
+ discussionsOrgLevel = []map [string ]any {
54
+ {
55
+ "number" : 1 ,
56
+ "title" : "Org Discussion 1 - Community Guidelines" ,
57
+ "createdAt" : "2023-01-15T00:00:00Z" ,
58
+ "updatedAt" : "2023-01-15T00:00:00Z" ,
59
+ "author" : map [string ]any {"login" : "org-admin" },
60
+ "url" : "https://github.com/owner/.github/discussions/1" ,
61
+ "category" : map [string ]any {"name" : "Announcements" },
62
+ },
63
+ {
64
+ "number" : 2 ,
65
+ "title" : "Org Discussion 2 - Roadmap 2023" ,
66
+ "createdAt" : "2023-02-20T00:00:00Z" ,
67
+ "updatedAt" : "2023-02-20T00:00:00Z" ,
68
+ "author" : map [string ]any {"login" : "org-admin" },
69
+ "url" : "https://github.com/owner/.github/discussions/2" ,
70
+ "category" : map [string ]any {"name" : "General" },
71
+ },
72
+ {
73
+ "number" : 3 ,
74
+ "title" : "Org Discussion 3 - Roadmap 2024" ,
75
+ "createdAt" : "2023-02-20T00:00:00Z" ,
76
+ "updatedAt" : "2023-02-20T00:00:00Z" ,
77
+ "author" : map [string ]any {"login" : "org-admin" },
78
+ "url" : "https://github.com/owner/.github/discussions/3" ,
79
+ "category" : map [string ]any {"name" : "General" },
80
+ },
81
+ {
82
+ "number" : 4 ,
83
+ "title" : "Org Discussion 4 - Roadmap 2025" ,
84
+ "createdAt" : "2023-02-20T00:00:00Z" ,
85
+ "updatedAt" : "2023-02-20T00:00:00Z" ,
86
+ "author" : map [string ]any {"login" : "org-admin" },
87
+ "url" : "https://github.com/owner/.github/discussions/4" ,
88
+ "category" : map [string ]any {"name" : "General" },
89
+ },
90
+
91
+ }
92
+
53
93
// Ordered mock responses
54
94
discussionsOrderedCreatedAsc = []map [string ]any {
55
95
discussionsAll [0 ], // Discussion 1 (created 2023-01-01)
@@ -139,6 +179,22 @@ var (
139
179
},
140
180
},
141
181
})
182
+
183
+ mockResponseOrgLevel = githubv4mock .DataResponse (map [string ]any {
184
+ "repository" : map [string ]any {
185
+ "discussions" : map [string ]any {
186
+ "nodes" : discussionsOrgLevel ,
187
+ "pageInfo" : map [string ]any {
188
+ "hasNextPage" : false ,
189
+ "hasPreviousPage" : false ,
190
+ "startCursor" : "" ,
191
+ "endCursor" : "" ,
192
+ },
193
+ "totalCount" : 4 ,
194
+ },
195
+ },
196
+ })
197
+
142
198
mockErrorRepoNotFound = githubv4mock .ErrorResponse ("repository not found" )
143
199
)
144
200
@@ -151,7 +207,7 @@ func Test_ListDiscussions(t *testing.T) {
151
207
assert .Contains (t , toolDef .InputSchema .Properties , "repo" )
152
208
assert .Contains (t , toolDef .InputSchema .Properties , "orderBy" )
153
209
assert .Contains (t , toolDef .InputSchema .Properties , "direction" )
154
- assert .ElementsMatch (t , toolDef .InputSchema .Required , []string {"owner" , "repo" })
210
+ assert .ElementsMatch (t , toolDef .InputSchema .Required , []string {"owner" })
155
211
156
212
// Variables matching what GraphQL receives after JSON marshaling/unmarshaling
157
213
varsListAll := map [string ]interface {}{
@@ -204,6 +260,13 @@ func Test_ListDiscussions(t *testing.T) {
204
260
"after" : (* string )(nil ),
205
261
}
206
262
263
+ varsOrgLevel := map [string ]interface {}{
264
+ "owner" : "owner" ,
265
+ "repo" : ".github" , // This is what gets set when repo is not provided
266
+ "first" : float64 (30 ),
267
+ "after" : (* string )(nil ),
268
+ }
269
+
207
270
tests := []struct {
208
271
name string
209
272
reqParams map [string ]interface {}
@@ -314,6 +377,15 @@ func Test_ListDiscussions(t *testing.T) {
314
377
expectError : true ,
315
378
errContains : "repository not found" ,
316
379
},
380
+ {
381
+ name : "list org-level discussions (no repo provided)" ,
382
+ reqParams : map [string ]interface {}{
383
+ "owner" : "owner" ,
384
+ // repo is not provided, it will default to ".github"
385
+ },
386
+ expectError : false ,
387
+ expectedCount : 4 ,
388
+ },
317
389
}
318
390
319
391
// Define the actual query strings that match the implementation
@@ -351,6 +423,9 @@ func Test_ListDiscussions(t *testing.T) {
351
423
case "repository not found error" :
352
424
matcher := githubv4mock .NewQueryMatcher (qBasicNoOrder , varsRepoNotFound , mockErrorRepoNotFound )
353
425
httpClient = githubv4mock .NewMockedHTTPClient (matcher )
426
+ case "list org-level discussions (no repo provided)" :
427
+ matcher := githubv4mock .NewQueryMatcher (qBasicNoOrder , varsOrgLevel , mockResponseOrgLevel )
428
+ httpClient = githubv4mock .NewMockedHTTPClient (matcher )
354
429
}
355
430
356
431
gqlClient := githubv4 .NewClient (httpClient )
0 commit comments