-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGitHubAbilities.php
More file actions
5202 lines (4576 loc) · 178 KB
/
Copy pathGitHubAbilities.php
File metadata and controls
5202 lines (4576 loc) · 178 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* GitHub Abilities
*
* Core business logic for GitHub API interactions: listing issues, PRs,
* repos, reading repo source files, and managing issues (update, close,
* comment). All GitHub operations — CLI, REST, chat tools, fetch handler —
* route through here.
*
* Auth: Uses either github_pat or GitHub App settings stored in Data Machine PluginSettings.
*
* @package DataMachineCode\Abilities
* @since 0.1.0
*/
namespace DataMachineCode\Abilities;
use DataMachineCode\Support\PermissionHelper;
use DataMachineCode\Support\PluginSettings;
use DataMachineCode\GitHub\PrReviewEscalationPolicy;
use DataMachineCode\Support\GitHubCredentialResolver;
use DataMachineCode\Support\RunArtifactBundleFileWriter;
use DataMachineCode\Support\RunArtifactPrSectionRenderer;
use DataMachineCode\Workspace\Workspace;
defined('ABSPATH') || exit;
if ( ! class_exists(AbilityRegistry::class) ) {
require_once __DIR__ . '/AbilityRegistry.php';
}
if ( ! class_exists(GitHubCredentialResolver::class) ) {
include_once dirname(__DIR__) . '/Support/GitHubCredentialResolver.php';
}
if ( ! class_exists(PrReviewEscalationPolicy::class) ) {
include_once dirname(__DIR__) . '/GitHub/PrReviewEscalationPolicy.php';
}
if ( ! class_exists(RunArtifactBundleFileWriter::class) ) {
include_once dirname(__DIR__) . '/Support/RunArtifactBundleFileWriter.php';
}
if ( ! class_exists(RunArtifactPrSectionRenderer::class) ) {
include_once dirname(__DIR__) . '/Support/RunArtifactPrSectionRenderer.php';
}
if ( ! class_exists(Workspace::class) ) {
include_once dirname(__DIR__) . '/Workspace/Workspace.php';
}
class GitHubAbilities {
private static bool $registered = false;
private static ?\WP_Error $last_auth_error = null;
/**
* Map of resolved tokens → auth mode ('pat' | 'app').
*
* Lets getHeaders() pick the right Authorization scheme without
* re-resolving the credential. Populated by getPat() / getCredential()
* each time a credential is resolved.
*
* @var array<string,string>
*/
private static array $token_modes = array();
/**
* GitHub API base URL.
*/
const API_BASE = 'https://api.github.com';
/**
* Default per_page for API requests.
*/
const DEFAULT_PER_PAGE = 30;
/**
* Maximum per_page for API requests.
*/
const MAX_PER_PAGE = 100;
public function __construct() {
if ( self::$registered ) {
return;
}
if ( ! function_exists('wp_register_ability') ) {
add_action(
'wp_abilities_api_init', function (): void {
if ( self::$registered || ! function_exists('wp_register_ability') ) {
return;
}
$this->registerAbilities();
self::$registered = true;
}
);
return;
}
$this->registerAbilities();
self::$registered = true;
}
private function registerAbilities(): void {
$register_callback = function () {
AbilityRegistry::register(
'datamachine-code/list-github-issues',
array(
'label' => 'List GitHub Issues',
'description' => 'List issues from a GitHub repository with optional filters',
'category' => 'datamachine-code-github',
'input_schema' => array(
'type' => 'object',
'required' => array( 'repo' ),
'properties' => array(
'repo' => array(
'type' => 'string',
'description' => 'Repository in owner/repo format.',
),
'state' => array(
'type' => 'string',
'description' => 'Issue state: open, closed, all (default: open).',
),
'labels' => array(
'type' => 'string',
'description' => 'Comma-separated list of label names to filter by.',
),
'assignee' => array(
'type' => 'string',
'description' => 'Filter by assignee username.',
),
'since' => array(
'type' => 'string',
'description' => 'ISO 8601 timestamp to filter issues updated after this date.',
),
'per_page' => array(
'type' => 'integer',
'description' => 'Results per page (default: 30, max: 100).',
),
'page' => array(
'type' => 'integer',
'description' => 'Page number for pagination (default: 1).',
),
),
),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'issues' => array( 'type' => 'array' ),
'count' => array( 'type' => 'integer' ),
'error' => array( 'type' => 'string' ),
),
),
'execute_callback' => array( self::class, 'listIssues' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => false ),
)
);
AbilityRegistry::register(
'datamachine-code/get-github-issue',
array(
'label' => 'Get GitHub Issue',
'description' => 'Get a single GitHub issue with full details',
'category' => 'datamachine-code-github',
'input_schema' => array(
'type' => 'object',
'required' => array( 'repo', 'issue_number' ),
'properties' => array(
'repo' => array(
'type' => 'string',
'description' => 'Repository in owner/repo format.',
),
'issue_number' => array(
'type' => 'integer',
'description' => 'Issue number.',
),
),
),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'issue' => array( 'type' => 'object' ),
'error' => array( 'type' => 'string' ),
),
),
'execute_callback' => array( self::class, 'getIssue' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => false ),
)
);
AbilityRegistry::register(
'datamachine-code/update-github-issue',
array(
'label' => 'Update GitHub Issue',
'description' => 'Update a GitHub issue (title, body, labels, assignees, state)',
'category' => 'datamachine-code-github',
'input_schema' => array(
'type' => 'object',
'required' => array( 'repo', 'issue_number' ),
'properties' => array(
'repo' => array(
'type' => 'string',
'description' => 'Repository in owner/repo format.',
),
'issue_number' => array(
'type' => 'integer',
'description' => 'Issue number.',
),
'title' => array(
'type' => 'string',
'description' => 'New issue title.',
),
'body' => array(
'type' => 'string',
'description' => 'New issue body.',
),
'state' => array(
'type' => 'string',
'description' => 'Issue state: open or closed.',
),
'labels' => array(
'type' => 'array',
'items' => array( 'type' => 'string' ),
'description' => 'Labels to set on the issue (replaces existing).',
),
'assignees' => array(
'type' => 'array',
'items' => array( 'type' => 'string' ),
'description' => 'Assignees to set on the issue (replaces existing).',
),
),
),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'issue' => array( 'type' => 'object' ),
'error' => array( 'type' => 'string' ),
),
),
'execute_callback' => array( self::class, 'updateIssue' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => false ),
)
);
AbilityRegistry::register(
'datamachine-code/create-github-issue',
array(
'label' => 'Create GitHub Issue',
'description' => 'Create a new GitHub issue with optional labels, assignees, and milestone',
'category' => 'datamachine-code-github',
'input_schema' => array(
'type' => 'object',
'required' => array( 'repo', 'title' ),
'properties' => array(
'repo' => array(
'type' => 'string',
'description' => 'Repository in owner/repo format.',
),
'title' => array(
'type' => 'string',
'description' => 'Issue title (required).',
),
'body' => array(
'type' => 'string',
'description' => 'Issue body (supports GitHub Markdown).',
),
'labels' => array(
'type' => 'array',
'items' => array( 'type' => 'string' ),
'description' => 'Labels to attach to the issue.',
),
'assignees' => array(
'type' => 'array',
'items' => array( 'type' => 'string' ),
'description' => 'GitHub usernames to assign to the issue.',
),
'milestone' => array(
'type' => array( 'integer', 'null' ),
'description' => 'Milestone number to attach to the issue.',
),
),
),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'issue' => array( 'type' => 'object' ),
'error' => array( 'type' => 'string' ),
),
),
'execute_callback' => array( self::class, 'createIssue' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => false ),
)
);
AbilityRegistry::register(
'datamachine-code/create-github-pull-request',
array(
'label' => 'Create GitHub Pull Request',
'description' => 'Open a new GitHub pull request from a head branch into a base branch',
'category' => 'datamachine-code-github',
'input_schema' => array(
'type' => 'object',
'required' => array( 'repo', 'title', 'head' ),
'properties' => array(
'repo' => array(
'type' => 'string',
'description' => 'Repository in owner/repo format.',
),
'title' => array(
'type' => 'string',
'description' => 'Pull request title (required).',
),
'head' => array(
'type' => 'string',
'description' => 'Branch where changes are implemented (required). Use owner:branch for cross-fork PRs.',
),
'base' => array(
'type' => 'string',
'description' => 'Branch to merge into. Defaults to the repository default branch.',
),
'body' => array(
'type' => 'string',
'description' => 'Pull request description (supports GitHub Markdown).',
),
'draft' => array(
'type' => 'boolean',
'description' => 'Whether to open the pull request as a draft. Default: false.',
),
'labels' => array(
'type' => 'array',
'items' => array( 'type' => 'string' ),
'description' => 'Labels to attach to the pull request after creation.',
),
'maintainer_can_modify' => array(
'type' => 'boolean',
'description' => 'Whether maintainers can modify the pull request. Default: true.',
),
),
),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'kind' => array( 'type' => 'string' ),
'repo' => array( 'type' => 'string' ),
'number' => array( 'type' => 'integer' ),
'pull_number' => array( 'type' => 'integer' ),
'url' => array( 'type' => 'string' ),
'html_url' => array( 'type' => 'string' ),
'reused' => array( 'type' => 'boolean' ),
'pull_request' => array( 'type' => 'object' ),
'labeling' => array( 'type' => 'object' ),
'error' => array( 'type' => 'string' ),
),
),
'execute_callback' => array( self::class, 'createPullRequest' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => false ),
)
);
AbilityRegistry::register(
'datamachine-code/comment-github-issue',
array(
'label' => 'Comment on GitHub Issue',
'description' => 'Add a comment to a GitHub issue',
'category' => 'datamachine-code-github',
'input_schema' => array(
'type' => 'object',
'required' => array( 'repo', 'issue_number', 'body' ),
'properties' => array(
'repo' => array(
'type' => 'string',
'description' => 'Repository in owner/repo format.',
),
'issue_number' => array(
'type' => 'integer',
'description' => 'Issue number.',
),
'body' => array(
'type' => 'string',
'description' => 'Comment body (supports GitHub Markdown).',
),
'allow_repeat_automation_comment' => array(
'type' => 'boolean',
'description' => 'Allow commenting when the latest issue comment is already from this automation actor. Default: false.',
),
),
),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'comment' => array( 'type' => 'object' ),
'error' => array( 'type' => 'string' ),
),
),
'execute_callback' => array( self::class, 'commentOnIssue' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => false ),
)
);
AbilityRegistry::register(
'datamachine-code/comment-github-pull-request',
array(
'label' => 'Comment on GitHub Pull Request',
'description' => 'Add a comment to a GitHub pull request without broader issue-management permissions',
'category' => 'datamachine-code-github',
'input_schema' => array(
'type' => 'object',
'required' => array( 'repo', 'pull_number', 'body' ),
'properties' => array(
'repo' => array(
'type' => 'string',
'description' => 'Repository in owner/repo format.',
),
'pull_number' => array(
'type' => 'integer',
'description' => 'Pull request number.',
),
'body' => array(
'type' => 'string',
'description' => 'Comment body (supports GitHub Markdown).',
),
'marker' => array(
'type' => 'string',
'description' => 'Optional stable marker appended as an HTML comment for future update-by-marker support.',
),
),
),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'comment' => array( 'type' => 'object' ),
'error' => array( 'type' => 'string' ),
),
),
'execute_callback' => array( self::class, 'commentOnPullRequest' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => false ),
)
);
AbilityRegistry::register(
'datamachine-code/add-github-labels',
array(
'label' => 'Add GitHub Labels',
'description' => 'Add one or more labels to a GitHub issue or pull request without replacing existing labels.',
'category' => 'datamachine-code-github',
'input_schema' => array(
'type' => 'object',
'required' => array( 'repo', 'issue_number', 'labels' ),
'properties' => array(
'repo' => array(
'type' => 'string',
'description' => 'Repository in owner/repo format.',
),
'issue_number' => array(
'type' => 'integer',
'description' => 'Issue or pull request number.',
),
'labels' => array(
'type' => 'array',
'items' => array( 'type' => 'string' ),
'description' => 'Labels to add.',
),
),
),
'output_schema' => array( 'type' => 'object' ),
'execute_callback' => array( self::class, 'addLabels' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => false ),
)
);
AbilityRegistry::register(
'datamachine-code/remove-github-label',
array(
'label' => 'Remove GitHub Label',
'description' => 'Remove a single label from a GitHub issue or pull request without touching other labels.',
'category' => 'datamachine-code-github',
'input_schema' => array(
'type' => 'object',
'required' => array( 'repo', 'issue_number', 'label' ),
'properties' => array(
'repo' => array(
'type' => 'string',
'description' => 'Repository in owner/repo format.',
),
'issue_number' => array(
'type' => 'integer',
'description' => 'Issue or pull request number.',
),
'label' => array(
'type' => 'string',
'description' => 'Label to remove.',
),
),
),
'output_schema' => array( 'type' => 'object' ),
'execute_callback' => array( self::class, 'removeLabel' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => false ),
)
);
AbilityRegistry::register(
'datamachine-code/upsert-github-pull-review-comment',
array(
'label' => 'Upsert GitHub Pull Request Review Comment',
'description' => 'Create or update one managed bot-authored GitHub pull request review comment identified by a hidden marker',
'category' => 'datamachine-code-github',
'input_schema' => array(
'type' => 'object',
'required' => array( 'repo', 'pull_number', 'body' ),
'properties' => array(
'repo' => array(
'type' => 'string',
'description' => 'Repository in owner/repo format.',
),
'pull_number' => array(
'type' => 'integer',
'description' => 'Pull request number.',
),
'body' => array(
'type' => 'string',
'description' => 'Review comment body (supports GitHub Markdown). Hidden marker text is appended automatically.',
),
'marker' => array(
'type' => 'string',
'description' => 'Hidden HTML comment marker used to find the managed comment. Default: <!-- datamachine-pr-review -->.',
),
'head_sha' => array(
'type' => 'string',
'description' => 'Optional pull request head SHA. Required to separate comments when mode is per_head_sha.',
),
'mode' => array(
'type' => 'string',
'description' => 'Comment policy: update_existing or per_head_sha. Default: update_existing.',
),
),
),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'action' => array( 'type' => 'string' ),
'comment_id' => array( 'type' => 'integer' ),
'html_url' => array( 'type' => 'string' ),
'error' => array( 'type' => 'string' ),
),
),
'execute_callback' => array( self::class, 'upsertPullReviewComment' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => false ),
)
);
AbilityRegistry::register(
'datamachine-code/merge-github-pull-request',
array(
'label' => 'Merge GitHub Pull Request',
'description' => 'Merge an open GitHub pull request after verifying the expected head SHA',
'category' => 'datamachine-code-github',
'input_schema' => array(
'type' => 'object',
'required' => array( 'repo', 'pull_number', 'expected_head_sha' ),
'properties' => array(
'repo' => array(
'type' => 'string',
'description' => 'Repository in owner/repo format.',
),
'pull_number' => array(
'type' => 'integer',
'description' => 'Pull request number.',
),
'expected_head_sha' => array(
'type' => 'string',
'description' => 'Exact pull request head SHA expected immediately before merge.',
),
'merge_method' => array(
'type' => 'string',
'enum' => array( 'merge', 'squash', 'rebase' ),
'description' => 'GitHub merge method. Default: squash.',
),
'delete_branch' => array(
'type' => 'boolean',
'description' => 'Delete the pull request head branch through the GitHub API after a successful merge when the branch is in the same repository.',
),
),
),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'repo' => array( 'type' => 'string' ),
'pull_number' => array( 'type' => 'integer' ),
'merged' => array( 'type' => 'boolean' ),
'sha' => array( 'type' => 'string' ),
'message' => array( 'type' => 'string' ),
'html_url' => array( 'type' => 'string' ),
'local_worktree_cleanup' => array( 'type' => 'object' ),
'error' => array( 'type' => 'string' ),
),
),
'execute_callback' => array( self::class, 'mergePullRequest' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => false ),
)
);
AbilityRegistry::register(
'datamachine-code/cleanup-github-pull-request',
array(
'label' => 'Cleanup GitHub Pull Request',
'description' => 'Delete a merged pull request head branch through the GitHub API without checking out local branches',
'category' => 'datamachine-code-github',
'input_schema' => array(
'type' => 'object',
'required' => array( 'repo', 'pull_number' ),
'properties' => array(
'repo' => array(
'type' => 'string',
'description' => 'Repository in owner/repo format.',
),
'pull_number' => array(
'type' => 'integer',
'description' => 'Pull request number.',
),
'dry_run' => array(
'type' => 'boolean',
'description' => 'Preview the cleanup decision without deleting the branch.',
),
'local_only' => array(
'type' => 'boolean',
'description' => 'Finalize and remove the matching local DMC worktree without deleting the remote branch.',
),
),
),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'repo' => array( 'type' => 'string' ),
'pull_number' => array( 'type' => 'integer' ),
'head_branch' => array( 'type' => 'string' ),
'branch_deleted' => array( 'type' => 'boolean' ),
'branch_already_deleted' => array( 'type' => 'boolean' ),
'dry_run' => array( 'type' => 'boolean' ),
'message' => array( 'type' => 'string' ),
'local_worktree_cleanup' => array( 'type' => 'object' ),
'error' => array( 'type' => 'string' ),
),
),
'execute_callback' => array( self::class, 'cleanupPullRequest' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => false ),
)
);
AbilityRegistry::register(
'datamachine-code/list-github-pulls',
array(
'label' => 'List GitHub Pull Requests',
'description' => 'List pull requests from a GitHub repository',
'category' => 'datamachine-code-github',
'input_schema' => array(
'type' => 'object',
'required' => array( 'repo' ),
'properties' => array(
'repo' => array(
'type' => 'string',
'description' => 'Repository in owner/repo format.',
),
'state' => array(
'type' => 'string',
'description' => 'PR state: open, closed, all (default: open).',
),
'per_page' => array(
'type' => 'integer',
'description' => 'Results per page (default: 30, max: 100).',
),
'page' => array(
'type' => 'integer',
'description' => 'Page number (default: 1).',
),
),
),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'pulls' => array( 'type' => 'array' ),
'count' => array( 'type' => 'integer' ),
'error' => array( 'type' => 'string' ),
),
),
'execute_callback' => array( self::class, 'listPulls' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => false ),
)
);
AbilityRegistry::register(
'datamachine-code/get-github-pull',
array(
'label' => 'Get GitHub Pull Request',
'description' => 'Get a single GitHub pull request with normalized metadata',
'category' => 'datamachine-code-github',
'input_schema' => array(
'type' => 'object',
'required' => array( 'repo', 'pull_number' ),
'properties' => array(
'repo' => array(
'type' => 'string',
'description' => 'Repository in owner/repo format.',
),
'pull_number' => array(
'type' => 'integer',
'description' => 'Pull request number.',
),
),
),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'pull' => array( 'type' => 'object' ),
'error' => array( 'type' => 'string' ),
),
),
'execute_callback' => array( self::class, 'getPull' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => false ),
)
);
AbilityRegistry::register(
'datamachine-code/list-github-pull-files',
array(
'label' => 'List GitHub Pull Request Files',
'description' => 'List changed files for a GitHub pull request',
'category' => 'datamachine-code-github',
'input_schema' => array(
'type' => 'object',
'required' => array( 'repo', 'pull_number' ),
'properties' => array(
'repo' => array(
'type' => 'string',
'description' => 'Repository in owner/repo format.',
),
'pull_number' => array(
'type' => 'integer',
'description' => 'Pull request number.',
),
'per_page' => array(
'type' => 'integer',
'description' => 'Results per page (default: 100, max: 100).',
),
'page' => array(
'type' => 'integer',
'description' => 'Page number (default: 1).',
),
),
),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'files' => array( 'type' => 'array' ),
'count' => array( 'type' => 'integer' ),
'error' => array( 'type' => 'string' ),
),
),
'execute_callback' => array( self::class, 'listPullFiles' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => false ),
)
);
AbilityRegistry::register(
'datamachine-code/get-github-check-runs',
array(
'label' => 'Get GitHub Check Runs',
'description' => 'Get GitHub check runs for a commit SHA or ref with an overall summary',
'category' => 'datamachine-code-github',
'input_schema' => array(
'type' => 'object',
'required' => array( 'repo', 'sha' ),
'properties' => array(
'repo' => array(
'type' => 'string',
'description' => 'Repository in owner/repo format.',
),
'sha' => array(
'type' => 'string',
'description' => 'Commit SHA, branch, or tag ref.',
),
'per_page' => array(
'type' => 'integer',
'description' => 'Results per page (default: 30, max: 100).',
),
'include_check_output' => array(
'type' => 'boolean',
'description' => 'Whether to include bounded check output summaries and text.',
),
),
),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'sha' => array( 'type' => 'string' ),
'summary' => array( 'type' => 'object' ),
'check_runs' => array( 'type' => 'array' ),
'count' => array( 'type' => 'integer' ),
'error' => array( 'type' => 'string' ),
),
),
'execute_callback' => array( self::class, 'getCheckRuns' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => false ),
)
);
AbilityRegistry::register(
'datamachine-code/get-github-commit-statuses',
array(
'label' => 'Get GitHub Commit Statuses',
'description' => 'Get unmanaged GitHub commit statuses for a commit SHA or ref',
'category' => 'datamachine-code-github',
'input_schema' => array(
'type' => 'object',
'required' => array( 'repo', 'sha' ),
'properties' => array(
'repo' => array(
'type' => 'string',
'description' => 'Repository in owner/repo format.',
),
'sha' => array(
'type' => 'string',
'description' => 'Commit SHA, branch, or tag ref.',
),
),
),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'sha' => array( 'type' => 'string' ),
'summary' => array( 'type' => 'object' ),
'statuses' => array( 'type' => 'array' ),
'count' => array( 'type' => 'integer' ),
'error' => array( 'type' => 'string' ),
),
),
'execute_callback' => array( self::class, 'getCommitStatuses' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => false ),
)
);
AbilityRegistry::register(
'datamachine-code/get-github-actions-artifact',
array(
'label' => 'Get GitHub Actions Artifact',
'description' => 'Download a GitHub Actions artifact for a pull request or commit SHA and optionally parse JSON files from the ZIP',
'category' => 'datamachine-code-github',
'input_schema' => array(
'type' => 'object',
'required' => array( 'repo', 'artifact_name' ),
'properties' => array(
'repo' => array(
'type' => 'string',
'description' => 'Repository in owner/repo format.',
),
'head_sha' => array(
'type' => 'string',
'description' => 'Pull request head SHA or commit SHA to match artifacts against.',
),
'pull_number' => array(
'type' => 'integer',
'description' => 'Pull request number. Used to resolve head_sha when head_sha is omitted.',
),
'artifact_name' => array(
'type' => 'string',
'description' => 'GitHub Actions artifact name.',
),
'max_artifact_bytes' => array(
'type' => 'integer',
'description' => 'Maximum artifact ZIP bytes to download. Default: 2000000.',
),
'include_json' => array(
'type' => 'boolean',
'description' => 'Parse and include JSON files from the artifact ZIP. Default: true.',
),
),
),
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'repo' => array( 'type' => 'string' ),
'head_sha' => array( 'type' => 'string' ),
'pull_number' => array( 'type' => 'integer' ),
'artifact' => array( 'type' => 'object' ),
'json_files' => array( 'type' => 'object' ),
'error' => array( 'type' => 'string' ),
),
),
'execute_callback' => array( self::class, 'getActionsArtifact' ),
'permission_callback' => fn() => PermissionHelper::can_manage(),
'meta' => array( 'show_in_rest' => false ),
)
);
AbilityRegistry::register(
'datamachine-code/get-github-pull-review-context',
array(
'label' => 'Get GitHub Pull Request Review Context',
'description' => 'Get a review-ready payload for a GitHub pull request and its changed files',
'category' => 'datamachine-code-github',
'input_schema' => array(
'type' => 'object',
'required' => array( 'repo', 'pull_number' ),
'properties' => array(
'repo' => array(
'type' => 'string',
'description' => 'Repository in owner/repo format.',
),
'pull_number' => array(
'type' => 'integer',
'description' => 'Pull request number.',
),
'head_sha' => array(
'type' => 'string',
'description' => 'Optional expected pull request head SHA.',
),
'max_patch_chars' => array(
'type' => 'integer',
'description' => 'Maximum cumulative patch characters to include (default: 200000).',
),
'include_file_contents' => array(
'type' => 'boolean',
'description' => 'Whether to include bounded full-file contents for changed files.',
),
'include_base_contents' => array(
'type' => 'boolean',
'description' => 'Whether to include bounded base-file contents for changed files.',
),
'context_paths' => array(
'type' => array( 'array', 'string' ),
'description' => 'Additional repository paths to include from the PR head ref, as an array or comma/newline-separated string.',
),
'max_file_content_chars' => array(
'type' => 'integer',
'description' => 'Maximum characters included per expanded file content block (default: 20000).',
),
'max_context_files' => array(
'type' => 'integer',
'description' => 'Maximum number of files included in expanded PR review context (default: 10).',
),
'max_total_context_chars' => array(
'type' => 'integer',
'description' => 'Maximum cumulative characters included across expanded PR review context files (default: 100000).',
),
'include_checks' => array(
'type' => 'boolean',
'description' => 'Whether to include GitHub check runs for the PR head SHA.',
),
'include_statuses' => array(
'type' => 'boolean',
'description' => 'Whether to include classic commit statuses for the PR head SHA.',
),
'max_check_runs' => array(
'type' => 'integer',
'description' => 'Maximum check runs to include (default: 30, max: 100).',
),
'include_check_output' => array(
'type' => 'boolean',
'description' => 'Whether to include bounded check output summaries and text.',
),
'artifact_name' => array(
'type' => 'string',
'description' => 'Optional GitHub Actions artifact name to include through generic artifact consumers.',
),
),