@@ -50,10 +50,19 @@ type batchItemError struct {
5050
5151type resolvedBatchItem struct {
5252 index int
53+ ref map [string ]any
5354 nodeID string
5455 fullDatabaseID int64
5556}
5657
58+ type batchWriteOperation struct {
59+ gqlClient * githubv4.Client
60+ kind batchMutationKind
61+ projectID githubv4.ID
62+ fieldID githubv4.ID
63+ value githubv4.ProjectV2FieldValue
64+ }
65+
5766func updateProjectItemsBatch (ctx context.Context , client * github.Client , gqlClient * githubv4.Client , owner , ownerType string , projectNumber int , args map [string ]any ) (* mcp.CallToolResult , any , error ) {
5867 rawItems , exists := args ["items" ]
5968 if ! exists {
@@ -158,10 +167,16 @@ func updateProjectItemsBatch(ctx context.Context, client *github.Client, gqlClie
158167 }
159168
160169 seenTargets [nodeID ] = i
161- work = append (work , resolvedBatchItem {index : i , nodeID : nodeID , fullDatabaseID : fullDatabaseID })
170+ work = append (work , resolvedBatchItem {index : i , ref : p . ref , nodeID : nodeID , fullDatabaseID : fullDatabaseID })
162171 }
163172
164- executeBatchWrites (ctx , gqlClient , kind , projectID , githubv4 .ID (field .NodeID ), value , work , results , parsed )
173+ executeBatchWrites (ctx , batchWriteOperation {
174+ gqlClient : gqlClient ,
175+ kind : kind ,
176+ projectID : projectID ,
177+ fieldID : githubv4 .ID (field .NodeID ),
178+ value : value ,
179+ }, work , results )
165180
166181 return newUpdateProjectItemsResult (results )
167182}
@@ -230,10 +245,10 @@ func resolveItemReference(p parsedBatchItem, itemIDLookups map[int64]itemLookupR
230245
231246// Transport, cancellation, or incomplete-data ambiguity stops later chunks;
232247// GraphQL response errors do not because populated aliases still confirm writes.
233- func executeBatchWrites (ctx context.Context , gqlClient * githubv4. Client , kind batchMutationKind , projectID , fieldID githubv4. ID , value githubv4. ProjectV2FieldValue , items []resolvedBatchItem , results []batchItemResult , parsed [] parsedBatchItem ) {
248+ func executeBatchWrites (ctx context.Context , operation batchWriteOperation , items []resolvedBatchItem , results []batchItemResult ) {
234249 for start := 0 ; start < len (items ); start += batchMutationWireChunkSize {
235250 if ctx .Err () != nil {
236- markChunkUnknown (items [start :], results , parsed , ctx .Err ())
251+ markChunkUnknown (items [start :], results , ctx .Err ())
237252 return
238253 }
239254
@@ -242,23 +257,23 @@ func executeBatchWrites(ctx context.Context, gqlClient *githubv4.Client, kind ba
242257
243258 inputs := make ([]githubv4.Input , len (chunk ))
244259 for i , item := range chunk {
245- if kind == batchMutationClear {
260+ if operation . kind == batchMutationClear {
246261 inputs [i ] = githubv4.ClearProjectV2ItemFieldValueInput {
247- ProjectID : projectID ,
262+ ProjectID : operation . projectID ,
248263 ItemID : githubv4 .ID (item .nodeID ),
249- FieldID : fieldID ,
264+ FieldID : operation . fieldID ,
250265 }
251266 } else {
252267 inputs [i ] = githubv4.UpdateProjectV2ItemFieldValueInput {
253- ProjectID : projectID ,
268+ ProjectID : operation . projectID ,
254269 ItemID : githubv4 .ID (item .nodeID ),
255- FieldID : fieldID ,
256- Value : value ,
270+ FieldID : operation . fieldID ,
271+ Value : operation . value ,
257272 }
258273 }
259274 }
260275
261- outcomes , mutateErr := executeAliasedMutation (ctx , gqlClient , kind , inputs )
276+ outcomes , mutateErr := executeAliasedMutation (ctx , operation . gqlClient , operation . kind , inputs )
262277
263278 populated := 0
264279 for i , oc := range outcomes {
@@ -267,7 +282,7 @@ func executeBatchWrites(ctx context.Context, gqlClient *githubv4.Client, kind ba
267282 results [chunk [i ].index ] = batchItemResult {
268283 Index : chunk [i ].index ,
269284 Status : batchItemSucceeded ,
270- Ref : parsed [ chunk [i ]. index ].ref ,
285+ Ref : chunk [i ].ref ,
271286 Item : & batchItemIdentity {
272287 NodeID : oc .NodeID ,
273288 FullDatabaseID : oc .FullDatabaseID ,
@@ -278,45 +293,45 @@ func executeBatchWrites(ctx context.Context, gqlClient *githubv4.Client, kind ba
278293 }
279294
280295 if isGraphQLResponseError (mutateErr ) {
281- markUnpopulatedUnknown (chunk , outcomes , results , parsed , mutateErr )
296+ markUnpopulatedUnknown (chunk , outcomes , results , mutateErr )
282297 continue
283298 }
284299
285300 if mutateErr != nil {
286- markChunkUnknown (items [start :], results , parsed , mutateErr )
301+ markChunkUnknown (items [start :], results , mutateErr )
287302 return
288303 }
289304
290305 if populated != len (chunk ) {
291- markChunkUnknown (items [start :], results , parsed , fmt .Errorf ("mutation response did not include every item" ))
306+ markChunkUnknown (items [start :], results , fmt .Errorf ("mutation response did not include every item" ))
292307 return
293308 }
294309 }
295310}
296311
297- func markUnpopulatedUnknown (chunk []resolvedBatchItem , outcomes []mutationAliasOutcome , results []batchItemResult , parsed [] parsedBatchItem , err error ) {
312+ func markUnpopulatedUnknown (chunk []resolvedBatchItem , outcomes []mutationAliasOutcome , results []batchItemResult , err error ) {
298313 for i , oc := range outcomes {
299314 if oc .Populated {
300315 continue
301316 }
302317 results [chunk [i ].index ] = batchItemResult {
303318 Index : chunk [i ].index ,
304319 Status : batchItemUnknown ,
305- Ref : parsed [ chunk [i ]. index ].ref ,
320+ Ref : chunk [i ].ref ,
306321 Error : & batchItemError {Code : "mutation_unconfirmed" , Message : err .Error ()},
307322 }
308323 }
309324}
310325
311- func markChunkUnknown (chunk []resolvedBatchItem , results []batchItemResult , parsed [] parsedBatchItem , err error ) {
326+ func markChunkUnknown (chunk []resolvedBatchItem , results []batchItemResult , err error ) {
312327 for _ , item := range chunk {
313328 if results [item .index ].Status == batchItemSucceeded {
314329 continue
315330 }
316331 results [item .index ] = batchItemResult {
317332 Index : item .index ,
318333 Status : batchItemUnknown ,
319- Ref : parsed [ item . index ] .ref ,
334+ Ref : item .ref ,
320335 Error : & batchItemError {Code : "mutation_unconfirmed" , Message : err .Error ()},
321336 }
322337 }
0 commit comments