-
Notifications
You must be signed in to change notification settings - Fork 23
/
main.php
executable file
·3463 lines (3131 loc) · 92.8 KB
/
main.php
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
/**
* Main functions for the program.
*
* @package Automattic/vip-go-ci
* @author Automattic inc.
* @copyright 2017-2022 Automattic inc.
* @file main.php
* @description vip-go-ci main functions.
*/
declare(strict_types=1);
/**
* Print help message.
*
* @return void
*/
function vipgoci_help_print() :void {
global $argv;
print 'Usage: ' . $argv[0] . ' [OPTION]...' . PHP_EOL .
PHP_EOL .
"\t" . 'Options --repo-owner, --repo-name, --commit, --token, --local-git-repo are' . PHP_EOL .
"\t" . 'mandatory, while others are optional.' . PHP_EOL .
PHP_EOL .
"\t" . 'Note that if option --autoapprove is specified, --autoapprove-label needs to' . PHP_EOL .
"\t" . 'be specified as well.' . PHP_EOL .
PHP_EOL .
'General configuration:' . PHP_EOL .
"\t" . '--help Displays this message' . PHP_EOL .
"\t" . '--version Displays version number and exits.' . PHP_EOL .
"\t" . '--debug-level=NUMBER Specify minimum debug-level of messages to print' . PHP_EOL .
"\t" . ' -- higher number indicates more detailed debugging-messages.' . PHP_EOL .
"\t" . ' Default is zero' . PHP_EOL .
"\t" . '--max-exec-time=NUMBER Maximum execution time for vip-go-ci, in seconds. Will exit if exceeded.' . PHP_EOL .
"\t" . ' Only lime spent after options are initialized and during scanning is' . PHP_EOL .
"\t" . ' considered as execution time. Time initializing is excluded.' . PHP_EOL .
"\t" . '--enforce-https-urls=BOOL Check and enforce that all URLs provided to parameters' . PHP_EOL .
"\t" . ' that expect a URL are HTTPS and not HTTP. Default is true.' . PHP_EOL .
"\t" . '--skip-draft-prs=BOOL If true, skip scanning of all pull requests that are in draft mode.' . PHP_EOL .
"\t" . ' Default is false.' . PHP_EOL .
"\t" . '--skip-large-files=true=BOOL If true, skip scanning files that have number of lines higher than the skip-large-files-limit value.' . PHP_EOL .
"\t" . ' Default is true.' . PHP_EOL .
"\t" . '--skip-large-files-limit=INTEGER Defines the maximum number of lines limit per file.' . PHP_EOL .
"\t" . ' Default is ' . VIPGOCI_VALIDATION_MAXIMUM_LINES_LIMIT . ' lines.' . PHP_EOL .
"\t" . '--branches-ignore=STRING,... What branches to ignore -- useful to make sure' . PHP_EOL .
"\t" . ' some branches never get scanned. Separate branches' . PHP_EOL .
"\t" . ' with commas.' . PHP_EOL .
"\t" . '--local-git-repo=FILE The local git repository to use for direct access to code.' . PHP_EOL .
"\t" . '--name-to-use Name to use for the program in GitHub reviews and comments' . PHP_EOL .
"\t" . ' to identify the bot. Default is "' . VIPGOCI_DEFAULT_NAME_TO_USE . '".' . PHP_EOL .
PHP_EOL .
'Environmental & repo configuration:' . PHP_EOL .
"\t" . '--env-options=STRING Specifies configuration options to be read from environmental' . PHP_EOL .
"\t" . ' variables -- any variable can be specified. For instance, with' . PHP_EOL .
"\t" . ' --env-options="repo-owner=U_ROWNER,output=U_FOUTPUT" specified' . PHP_EOL .
"\t" . ' vip-go-ci will attempt to read the --repo-owner and --output' . PHP_EOL .
"\t" . ' from the $U_ROWNER and $U_FOUTPUT environmental variables,' . PHP_EOL .
"\t" . ' respectively. This is useful for environments which provide' . PHP_EOL .
"\t" . ' information via environmental variables.' . PHP_EOL .
"\t" . ' --enforce-https-urls parameter is not configurable via environment.' . PHP_EOL .
"\t" . '--repo-options=BOOL Whether to allow configuring of certain configuration parameters' . PHP_EOL .
"\t" . ' via options file ("' . VIPGOCI_OPTIONS_FILE_NAME . '") placed in' . PHP_EOL .
"\t" . ' root of the repository.' . PHP_EOL .
"\t" . '--repo-options-allowed=STRING Limits the options that can be set via repository options' . PHP_EOL .
"\t" . ' configuration file. Values are separated by commas. Default' . PHP_EOL .
"\t" . ' are all options supported (see README.md).' . PHP_EOL .
PHP_EOL .
'GitHub configuration:' . PHP_EOL .
"\t" . '--repo-owner=STRING Specify repository owner, can be an organization.' . PHP_EOL .
"\t" . '--repo-name=STRING Specify name of the repository.' . PHP_EOL .
"\t" . '--commit=STRING Specify the exact commit to scan (SHA).' . PHP_EOL .
"\t" . '--token=STRING The access-token to use to communicate with GitHub.' . PHP_EOL .
PHP_EOL .
'PHP Linting configuration:' . PHP_EOL .
"\t" . '--lint=BOOL Whether to do PHP linting. Default is true.' . PHP_EOL .
"\t" . '--lint-php-version-paths=ARRAY Array of paths to different PHP interpreter versions, comma' . PHP_EOL .
"\t" . ' separated. Version and path separated by colon. Used for linting.' . PHP_EOL .
"\t" . ' E.g.: --lint-php-version-paths=7.4:/usr/bin/php7.4,8.1:/usr/bin/php8.1' . PHP_EOL .
"\t" . '--lint-php-versions=ARRAY Array of PHP versions to lint with during run. Comma separated values.' . PHP_EOL .
"\t" . '--lint-modified-files-only=BOOL Whether to limit lint scan to run against only modified or new' . PHP_EOL .
"\t" . ' files in the PR to be scanned. Default is true. It can be ' . PHP_EOL .
"\t" . ' modified via options file ("' . VIPGOCI_OPTIONS_FILE_NAME . '") placed in' . PHP_EOL .
"\t" . ' root of the repository.' . PHP_EOL .
"\t" . '--lint-file-extensions=ARRAY Use specified file extensions to select which altered files to PHP lint.' . PHP_EOL .
"\t" . ' Default is: "' . implode( ',', VIPGOCI_LINT_FILE_EXTENSIONS_DEFAULT ) . '"' . PHP_EOL .
"\t" . '--lint-skip-folders=STRING Specify folders relative to root of the git repository in which' . PHP_EOL .
"\t" . ' files should not be PHP linted. Values are comma separated.' . PHP_EOL .
"\t" . '--lint-skip-folders-in-repo-options-file=BOOL Whether to allow specifying folders that are not' . PHP_EOL .
"\t" . ' to be PHP Linted in a file in root of repository' . PHP_EOL .
"\t" . ' (.vipgoci_lint_skip_folders). Folders should be' . PHP_EOL .
"\t" . ' separated by newlines.' . PHP_EOL .
PHP_EOL .
'PHPCS configuration:' . PHP_EOL .
"\t" . '--phpcs=BOOL Whether to run PHPCS. Default is true.' . PHP_EOL .
"\t" . '--phpcs-php-path=FILE Full path to PHP used to run PHPCS. If not specified the default in' . PHP_EOL .
"\t" . ' $PATH will be used instead.' . PHP_EOL .
"\t" . '--phpcs-path=FILE Full path to PHPCS script.' . PHP_EOL .
"\t" . '--phpcs-standard=STRING Specify which PHPCS standard(s) to use. Separate by commas.' . PHP_EOL .
"\t" . ' If nothing is specified, the \'WordPress\' standard is used.' . PHP_EOL .
"\t" . '--phpcs-standards-to-ignore PHPCS standards to ignore when searching for PHPCS standards/sniffs' . PHP_EOL .
"\t" . ' available during startup. See details in README.md.' . PHP_EOL .
"\t" . '--phpcs-severity=NUMBER Specify severity for PHPCS.' . PHP_EOL .
"\t" . '--phpcs-sniffs-include=ARRAY Specify which sniffs to include when PHPCS scanning,' . PHP_EOL .
"\t" . ' should be an array with items separated by commas.' . PHP_EOL .
"\t" . '--phpcs-sniffs-exclude=ARRAY Specify which sniffs to exclude from PHPCS scanning,' . PHP_EOL .
"\t" . ' should be an array with items separated by commas.' . PHP_EOL .
"\t" . '--phpcs-runtime-set=STRING Specify --runtime-set values passed on to PHPCS' . PHP_EOL .
"\t" . ' -- expected to be a comma-separated value string of' . PHP_EOL .
"\t" . ' key-value pairs.' . PHP_EOL .
"\t" . ' For example: --phpcs-runtime-set="key1 value1,key2 value2"' . PHP_EOL .
"\t" . '--phpcs-file-extensions=ARRAY Use specified file extensions to select which altered files to PHPCS scan.' . PHP_EOL .
"\t" . ' Default is: "' . implode( ',', VIPGOCI_PHPCS_FILE_EXTENSIONS_DEFAULT ) . '"' . PHP_EOL .
"\t" . '--phpcs-skip-scanning-via-labels-allowed=BOOL Whether to allow users to skip PHPCS' . PHP_EOL .
"\t" . ' scanning of pull requests via labels' . PHP_EOL .
"\t" . ' attached to them. The label should be' . PHP_EOL .
"\t" . ' named "skip-phpcs-scan".' . PHP_EOL .
"\t" . '--phpcs-skip-folders=STRING Specify folders relative to root of the git repository in which' . PHP_EOL .
"\t" . ' files are not to be scanned using PHPCS. Values are comma' . PHP_EOL .
"\t" . ' separated.' . PHP_EOL .
"\t" . '--phpcs-skip-folders-in-repo-options-file=BOOL Whether to allow specifying folders that are not' . PHP_EOL .
"\t" . ' to be PHPCS scanned to be specified in file in root' . PHP_EOL .
"\t" . ' of repository (.vipgoci_phpcs_skip_folders).' . PHP_EOL .
"\t" . ' Folders should be separated by newlines.' . PHP_EOL .
PHP_EOL .
'SVG scanning configuration:' . PHP_EOL .
"\t" . '--svg-checks=BOOL Enable or disable SVG checks, both auto-approval of SVG' . PHP_EOL .
"\t" . ' files and problem checking of these files. Note that if' . PHP_EOL .
"\t" . ' auto-approvals are turned off globally, no auto-approval' . PHP_EOL .
"\t" . ' is performed for SVG files.' . PHP_EOL .
"\t" . '--svg-php-path=FILE Full path to PHP used to run SVG scanner. If not specified the default in' . PHP_EOL .
"\t" . ' $PATH will be used instead.' . PHP_EOL .
"\t" . '--svg-scanner-path=FILE Path to SVG scanning tool. Should return similar output' . PHP_EOL .
"\t" . ' as PHPCS.' . PHP_EOL .
"\t" . '--svg-file-extensions=ARRAY Use specified file extensions to select which altered files to SVG scan. ' . PHP_EOL .
"\t" . ' Default is: "' . implode( ',', VIPGOCI_SVG_FILE_EXTENSIONS_DEFAULT ) . '"' . PHP_EOL .
PHP_EOL .
'WPScan API scanning configuration:' . PHP_EOL .
"\t" . '--wpscan-api=BOOL Enable or disable WPScan API scanning. Disabled by default.' . PHP_EOL .
"\t" . '--wpscan-api-dry-mode=BOOL When enabled, report WPScan API results to IRC only, not pull requests. Temporary feature.' . PHP_EOL .
"\t" . '--wpscan-api-token=STRING Access token to use to communicate with WPScan API.' . PHP_EOL .
"\t" . '--wpscan-api-paths=ARRAY Directories to scan using WPScan API scanning. Should be an array' . PHP_EOL .
"\t" . ' with items separated by commas.' . PHP_EOL .
"\t" . '--wpscan-api-skip-folders=ARRAY Directories not to scan using WPScan API scanning. Should be an' . PHP_EOL .
"\t" . ' array with items separated by commas.' . PHP_EOL .
"\t" . '--wpscan-api-skip-folders-in-repo-options-file=BOOL Whether to allow specifying folders that are not to be' . PHP_EOL .
"\t" . ' scanned via WPScan API to be specified in file in' . PHP_EOL .
"\t" . ' root of repository (.vipgoci_wpscan_api_skip_folders).' . PHP_EOL .
"\t" . ' Folders should be separated by newlines.' . PHP_EOL .
"\t" . '--wpscan-api-plugin-file-extensions=ARRAY Use specified file extensions to select which altered plugin files to scan with WPScan API.' . PHP_EOL .
"\t" . ' Default is: "' . implode( ',', VIPGOCI_WPSCAN_PLUGIN_FILE_EXTENSIONS_DEFAULT ) . '"' . PHP_EOL .
"\t" . '--wpscan-api-theme-file-extensions=ARRAY Use specified file extensions to select which altered theme files to scan with WPScan API.' . PHP_EOL .
"\t" . ' Default is: "' . implode( ',', VIPGOCI_WPSCAN_THEME_FILE_EXTENSIONS_DEFAULT ) . '"' . PHP_EOL .
"\t" . '--wpscan-api-report-end-msg=STRING Message to append to end of WPScan API reports. The "%addon_type%" placeholder' . PHP_EOL .
"\t" . ' will be replaced by either "plugin" or "theme", depending on the report. Limited' . PHP_EOL .
"\t" . ' Markdown syntax allowed.' . PHP_EOL .
PHP_EOL .
'Auto approve configuration:' . PHP_EOL .
"\t" . '--autoapprove=BOOL Whether to auto-approve pull requests that fulfil' . PHP_EOL .
"\t" . ' certain conditions -- see README.md for details.' . PHP_EOL .
"\t" . '--autoapprove-filetypes=STRING Specify what file-types can be auto-' . PHP_EOL .
"\t" . ' approved. PHP files cannot be specified.' . PHP_EOL .
"\t" . '--autoapprove-php-nonfunctional-changes=BOOL For autoapprovals, also consider' . PHP_EOL .
"\t" . ' PHP files approved that contain' . PHP_EOL .
"\t" . ' only non-functional changes, such as' . PHP_EOL .
"\t" . ' whitespacing and comment changes.' . PHP_EOL .
"\t" . '--autoapprove-php-nonfunctional-changes-file-extensions=ARRAY Use specified file extensions to select which files' . PHP_EOL .
"\t" . ' to consider for non-functional auto-approval.' . PHP_EOL .
"\t" . ' Default is: "' . implode( ',', VIPGOCI_APPROVAL_AUTOAPPROVE_NON_FUNCTIONAL_CHANGES_FILE_EXTENSIONS_DEFAULT ) . '"' . PHP_EOL .
"\t" . '--autoapprove-label=STRING String to use for labels when auto-approving.' . PHP_EOL .
PHP_EOL .
'GitHub reviews & generic comments configuration:' . PHP_EOL .
"\t" . '--report-no-issues-found=BOOL Post message indicating no issues were found during scanning.' . PHP_EOL .
"\t" . ' Enabled by default.' . PHP_EOL .
"\t" . '--review-comments-sort=BOOL Sort issues found according to severity, from high' . PHP_EOL .
"\t" . ' to low, before submitting to GitHub. Not sorted by default.' . PHP_EOL .
"\t" . '--review-comments-max=NUMBER Maximum number of inline comments to submit' . PHP_EOL .
"\t" . ' to GitHub in one review. If the number of' . PHP_EOL .
"\t" . ' comments exceed this number, additional reviews' . PHP_EOL .
"\t" . ' will be submitted.' . PHP_EOL .
"\t" . '--review-comments-total-max=NUMBER Maximum number of inline comments submitted to' . PHP_EOL .
"\t" . ' a single pull request by the program -- includes' . PHP_EOL .
"\t" . ' comments from previous executions. Includes only' . PHP_EOL .
"\t" . ' "active" comments, not obsolete ones. A value of' . PHP_EOL .
"\t" . ' \'0\' indicates no limit.' . PHP_EOL .
"\t" . '--review-comments-ignore=STRING Specify which result comments to ignore' . PHP_EOL .
"\t" . ' -- e.g. useful if one type of message is to be ignored' . PHP_EOL .
"\t" . ' rather than a whole PHPCS sniff. Should be a' . PHP_EOL .
"\t" . ' whole string with items separated by \"|||\".' . PHP_EOL .
"\t" . '--review-comments-include-severity=BOOL Whether to include severity level with' . PHP_EOL .
"\t" . ' each review comment. Default is false.' . PHP_EOL .
PHP_EOL .
"\t" . '--dismiss-stale-reviews=BOOL Dismiss any reviews associated with pull requests' . PHP_EOL .
"\t" . ' that we process which have no active comments.' . PHP_EOL .
"\t" . '--dismissed-reviews-repost-comments=BOOL When avoiding double-posting comments,' . PHP_EOL .
"\t" . ' do not take into consideration comments' . PHP_EOL .
"\t" . ' posted against reviews that have now been' . PHP_EOL .
"\t" . ' dismissed. Setting this to true entails' . PHP_EOL .
"\t" . ' that comments from dismissed reviews will' . PHP_EOL .
"\t" . ' be posted again, should the underlying issue' . PHP_EOL .
"\t" . ' be detected during the run.' . PHP_EOL .
"\t" . '--dismissed-reviews-exclude-reviews-from-team=STRING With this parameter set,' . PHP_EOL .
"\t" . ' comments that are part of reviews' . PHP_EOL .
"\t" . ' dismissed by members of the teams specified,' . PHP_EOL .
"\t" . ' would be taken into consideration when' . PHP_EOL .
"\t" . ' avoiding double-posting; they would be' . PHP_EOL .
"\t" . ' excluded. Note that this parameter' . PHP_EOL .
"\t" . ' only works in conjunction with' . PHP_EOL .
"\t" . ' --dismissed-reviews-repost-comments .' . PHP_EOL .
"\t" . ' The parameter expects a team slug, not ID.' . PHP_EOL .
"\t" . '--informational-msg=STRING Message to append to GitHub reviews and generic comments. Useful to' . PHP_EOL .
"\t" . ' explain what the bot does. Can contain HTML or Markdown.' . PHP_EOL .
"\t" . '--scan-details-msg-include=BOOL If to include additional detail about the scan, versions of' . PHP_EOL .
"\t" . ' software used, options altered and so forth. Enabled by default.' . PHP_EOL .
PHP_EOL .
"\t" . '--output=FILE Where to save results output.' . PHP_EOL .
PHP_EOL .
'Generic support comments configuration:' . PHP_EOL .
"\t" . '--post-generic-pr-support-comments=BOOL Whether to post generic comment to pull requests' . PHP_EOL .
"\t" . ' with support-related information for users. Will' . PHP_EOL .
"\t" . ' be posted only once per pull request.' . PHP_EOL .
"\t" . '--post-generic-pr-support-comments-on-drafts=BOOL Determine if to post generic comment to draft' . PHP_EOL .
"\t" . ' pull requests also. Default is true.' . PHP_EOL .
"\t" . '--post-generic-pr-support-comments-string=STRING String to use when posting support-comment.' . PHP_EOL .
"\t" . '--post-generic-pr-support-comments-skip-if-label-exists=STRING If the specified label exists on' . PHP_EOL .
"\t" . ' the pull request, do not post support' . PHP_EOL .
"\t" . ' comment.' . PHP_EOL .
"\t" . '--post-generic-pr-support-comments-branches=ARRAY Only post support-comments to pull requests' . PHP_EOL .
"\t" . ' with the target branches specified. The' . PHP_EOL .
"\t" . ' parameter can be a string with one value, or' . PHP_EOL .
"\t" . ' comma separated. A single "any" value will' . PHP_EOL .
"\t" . ' cause the message to be posted to any' . PHP_EOL .
"\t" . ' branch.' . PHP_EOL .
"\t" . '--post-generic-pr-support-comments-repo-meta-match=ARRAY Only post generic support' . PHP_EOL .
"\t" . ' messages when data from repo-meta API' . PHP_EOL .
"\t" . ' matches the criteria specified here.' . PHP_EOL .
"\t" . ' See README.md for usage.' . PHP_EOL .
PHP_EOL .
'Repo meta API configuration:' . PHP_EOL .
"\t" . '--repo-meta-api-base-url=STRING Base URL to repo-meta API, containing support level and other' . PHP_EOL .
"\t" . ' information.' . PHP_EOL .
"\t" . '--repo-meta-api-user-id=STRING Authentication detail for the repo-meta API.' . PHP_EOL .
"\t" . '--repo-meta-api-access-token=STRING Access token for the repo-meta API.' . PHP_EOL .
PHP_EOL .
'IRC API configuration:' . PHP_EOL .
"\t" . '--irc-api-url=STRING URL to IRC API to send messages.' . PHP_EOL .
"\t" . '--irc-api-token=STRING Access-token to use to communicate with the IRC' . PHP_EOL .
"\t" . ' API.' . PHP_EOL .
"\t" . '--irc-api-bot=STRING Name for the bot which is supposed to send the IRC' . PHP_EOL .
"\t" . ' messages.' . PHP_EOL .
"\t" . '--irc-api-room=STRING Name for the chatroom to which the IRC messages should' . PHP_EOL .
"\t" . ' be sent.' . PHP_EOL .
PHP_EOL .
'Pixel API configuration:' . PHP_EOL .
"\t" . '--pixel-api-url=STRING URL to Pixel API.' . PHP_EOL .
"\t" . '--pixel-api-groupprefix=STRING Group to use when sending statistics to Pixel API.' . PHP_EOL;
}
/**
* Returns options supported.
*
* @return array Recognized options.
*/
function vipgoci_options_recognized() :array {
return array(
/*
* General configuration.
*/
'help',
'version',
'debug-level:',
'max-exec-time:',
'enforce-https-urls:',
'skip-draft-prs:',
'skip-large-files:',
'skip-large-files-limit:',
'branches-ignore:',
'local-git-repo:',
'name-to-use:',
/*
* Environmental & repo configuration.
*/
'env-options:',
'repo-options:',
'repo-options-allowed:',
/*
* GitHub configuration.
*/
'repo-owner:',
'repo-name:',
'commit:',
'token:',
/*
* PHP Linting configuration.
*/
'lint:',
'lint-php-version-paths:',
'lint-php-versions:',
'lint-modified-files-only:',
'lint-file-extensions:',
'lint-skip-folders:',
'lint-skip-folders-in-repo-options-file:',
/*
* PHPCS configuration
*/
'phpcs:',
'phpcs-php-path:',
'phpcs-path:',
'phpcs-standard:',
'phpcs-standards-to-ignore:',
'phpcs-severity:',
'phpcs-sniffs-include:',
'phpcs-sniffs-exclude:',
'phpcs-runtime-set:',
'phpcs-file-extensions:',
'phpcs-skip-scanning-via-labels-allowed:',
'phpcs-skip-folders:',
'phpcs-skip-folders-in-repo-options-file:',
'output:',
/*
* SVG scanning configuration
*/
'svg-checks:',
'svg-php-path:',
'svg-scanner-path:',
'svg-file-extensions:',
/*
* WPScan API scanning configuration
*/
'wpscan-api:',
'wpscan-api-dry-mode:',
'wpscan-api-token:',
'wpscan-api-paths:',
'wpscan-api-plugin-file-extensions:',
'wpscan-api-theme-file-extensions:',
'wpscan-api-skip-folders:',
'wpscan-api-skip-folders-in-repo-options-file:',
'wpscan-api-report-end-msg:',
/*
* Auto approve configuration
*/
'autoapprove:',
'autoapprove-filetypes:',
'autoapprove-php-nonfunctional-changes:',
'autoapprove-php-nonfunctional-changes-file-extensions:',
'autoapprove-label:',
/*
* GitHub reviews & generic comments configuration
*/
'report-no-issues-found:',
'review-comments-sort:',
'review-comments-max:',
'review-comments-total-max:',
'review-comments-ignore:',
'review-comments-include-severity:',
'dismiss-stale-reviews:',
'dismissed-reviews-repost-comments:',
'dismissed-reviews-exclude-reviews-from-team:',
'informational-msg:',
'scan-details-msg-include:',
/*
* Generic support comments configuration
*/
'post-generic-pr-support-comments:',
'post-generic-pr-support-comments-on-drafts:',
'post-generic-pr-support-comments-string:',
'post-generic-pr-support-comments-skip-if-label-exists:',
'post-generic-pr-support-comments-branches:',
'post-generic-pr-support-comments-repo-meta-match:',
/*
* Repo meta API configuration.
*/
'repo-meta-api-base-url:',
'repo-meta-api-user-id:',
'repo-meta-api-access-token:',
/*
* IRC API configuration.
*/
'irc-api-url:',
'irc-api-token:',
'irc-api-bot:',
'irc-api-room:',
/*
* Pixel API configuration.
*/
'pixel-api-url:',
'pixel-api-groupprefix:',
);
}
/**
* Determine exit status.
*
* If any VIPGOCI_ISSUE_TYPE_ERROR issues were submitted to
* GitHub return with a non-zero exit-code. Same
* if any files were skipped.
*
* If we submitted nothing or only warnings, and
* no files were skipped, return with zero.
*
* @param array $results Array with results from scanning, etc.
*
* @return int Exit status as determined from $results.
*/
function vipgoci_exit_status( array $results ) :int {
foreach (
array_keys(
$results['stats']
)
as $stats_type
) {
if (
( ! isset( $results['stats'][ $stats_type ] ) ) ||
( null === $results['stats'][ $stats_type ] )
) {
// In case the type of scan was not performed, skip.
continue;
}
foreach (
array_keys(
$results['stats'][ $stats_type ]
)
as $pr_number
) {
if (
0 !== $results['stats']
[ $stats_type ]
[ $pr_number ]
[ VIPGOCI_ISSUE_TYPE_ERROR ]
) {
// Some errors were found, return non-zero.
return VIPGOCI_EXIT_CODE_ISSUES;
}
}
}
if ( ! empty( $results['skipped-files'] ) ) {
foreach ( $results['skipped-files'] as $pr_number ) {
if ( 0 < $pr_number['total'] ) {
// Results contains skipped files due issues, return non-zero.
return VIPGOCI_EXIT_CODE_ISSUES;
}
}
}
return 0;
}
/**
* Process the --env-options option,
* and read options from environment
* as determined by the option.
*
* @param array $options Array of options.
* @param array $options_recognized Array of recognized options by the program.
*
* @return void
*/
function vipgoci_run_env_options_handle(
array &$options,
array $options_recognized
) :void {
vipgoci_option_array_handle(
$options,
'env-options',
array(),
null,
',',
false
);
/*
* Try to read options from
* environmental variables.
*/
vipgoci_options_read_env(
$options,
$options_recognized
);
}
/**
* Process --max-exec-time option.
*
* @param array $options Array of options.
*
* @return void
*/
function vipgoci_run_init_options_max_exec_time( array &$options ) :void {
vipgoci_option_integer_handle(
$options,
'max-exec-time',
0,
null
);
if ( 0 > $options['max-exec-time'] ) {
vipgoci_sysexit(
'Invalid value for --max-exec-time; must be positive',
array(
'max-exec-time' => $options['max-exec-time'],
),
VIPGOCI_EXIT_USAGE_ERROR
);
}
}
/**
* Process PHPCS related options, such as --phpcs-path.
*
* @param array $options Array of options.
*
* @return void
*/
function vipgoci_run_init_options_phpcs( array &$options ) :void {
/*
* Handle boolean options related to PHPCS
*/
vipgoci_option_bool_handle( $options, 'phpcs', 'false' );
vipgoci_option_bool_handle( $options, 'phpcs-skip-folders-in-repo-options-file', 'false' );
vipgoci_option_bool_handle( $options, 'phpcs-skip-scanning-via-labels-allowed', 'false' );
/*
* This variable is not configurable, is internal only.
*/
$options['phpcs-standard-file'] = false;
/*
* Process --phpcs-php-path if to do PHPCS scan --
* expected to be a file, default value is 'php'
* (then relies on $PATH).
*/
if ( true === $options['phpcs'] ) {
vipgoci_option_file_handle(
$options,
'phpcs-php-path',
'php'
);
} else {
$options['phpcs-php-path'] = null;
}
/*
* Check --phpcs-path if to do PHPCS
* scanning, otherwise set to null.
*/
if ( true === $options['phpcs'] ) {
/*
* Process --phpcs-path -- expected to
* be a file.
*/
vipgoci_option_file_handle(
$options,
'phpcs-path',
null
);
} else {
$options['phpcs-path'] = null;
}
/*
* Process --phpcs-standard -- expected to be
* a string.
*/
if ( empty( $options['phpcs-standard'] ) ) {
$options['phpcs-standard'] = array(
'WordPress',
);
} else {
vipgoci_option_array_handle(
$options,
'phpcs-standard',
array(),
array(),
',',
false
);
}
/*
* Process --phpcs-standards-to-ignore -- expected to be
* a string.
*/
if ( empty( $options['phpcs-standards-to-ignore'] ) ) {
$options['phpcs-standards-to-ignore'] = array();
} else {
vipgoci_option_array_handle(
$options,
'phpcs-standards-to-ignore',
array(),
array(),
',',
false
);
}
/*
* Ensure that --phpcs-standard and --phpcs-standards-to-ignore
* do not intersect.
*/
if ( ! empty(
array_intersect(
$options['phpcs-standard'],
$options['phpcs-standards-to-ignore']
)
) ) {
vipgoci_sysexit(
'--phpcs-standard and --phpcs-standards-to-ignore cannot share values',
array(
'phpcs-standard' => $options['phpcs-standard'],
'phpcs-standards-to-ignore' => $options['phpcs-standards-to-ignore'],
)
);
}
/*
* Process --phpcs-sniffs-include and --phpcs-sniffs-exclude
* -- both expected to be an array.
*/
if ( empty( $options['phpcs-sniffs-include'] ) ) {
$options['phpcs-sniffs-include'] = array();
} else {
vipgoci_option_array_handle(
$options,
'phpcs-sniffs-include',
array(),
array(),
',',
false
);
}
if ( empty( $options['phpcs-sniffs-exclude'] ) ) {
$options['phpcs-sniffs-exclude'] = array();
} else {
vipgoci_option_array_handle(
$options,
'phpcs-sniffs-exclude',
array(),
array(),
',',
false
);
}
/*
* Process --phpcs-runtime-set -- expected to be an
* array of values.
*/
vipgoci_option_phpcs_runtime_set(
$options,
'phpcs-runtime-set'
);
/*
* Process --phpcs-file-extensions -- expected to be
* an array of strings.
*/
vipgoci_option_array_handle(
$options,
'phpcs-file-extensions',
VIPGOCI_PHPCS_FILE_EXTENSIONS_DEFAULT
);
/*
* Process --phpcs-skip-folders -- expected to be an
* array of values.
*/
vipgoci_option_skip_folder_handle(
$options,
'phpcs-skip-folders'
);
/*
* Process --phpcs-severity -- expected to be
* an integer-value.
*/
vipgoci_option_integer_handle(
$options,
'phpcs-severity',
1,
array( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 )
);
}
/**
* Process WPScan API related options, such as --wpscan-api.
*
* @param array $options Array of options (reference).
*
* @return void
*/
function vipgoci_run_init_options_wpscan( array &$options ) :void {
/*
* Handle boolean options related to WPScan API.
*/
vipgoci_option_bool_handle( $options, 'wpscan-api', 'false' );
vipgoci_option_bool_handle( $options, 'wpscan-api-dry-mode', 'true' );
vipgoci_option_bool_handle( $options, 'wpscan-api-skip-folders-in-repo-options-file', 'false' );
/*
* Process --wpscan-folders -- expected to be an
* array of values.
*/
vipgoci_option_skip_folder_handle(
$options,
'wpscan-api-paths'
);
/*
* Process --wpscan-api-plugin-file-extensions -- expected to be an
* array of values.
*/
vipgoci_option_array_handle(
$options,
'wpscan-api-plugin-file-extensions',
VIPGOCI_WPSCAN_PLUGIN_FILE_EXTENSIONS_DEFAULT
);
/*
* Process --wpscan-api-theme-file-extensions -- expected to be an
* array of values.
*/
vipgoci_option_array_handle(
$options,
'wpscan-api-theme-file-extensions',
VIPGOCI_WPSCAN_THEME_FILE_EXTENSIONS_DEFAULT
);
/*
* Process --wpscan-api-skip-folders -- expected to be an
* array of values.
*/
vipgoci_option_skip_folder_handle(
$options,
'wpscan-api-skip-folders'
);
/*
* Process --wpscan-api-report-end-msg -- expected to be a string.
*/
if ( empty( $options['wpscan-api-report-end-msg'] ) ) {
$options['wpscan-api-report-end-msg'] = '';
}
if (
( true === $options['wpscan-api'] ) &&
(
( empty( $options['wpscan-api-paths'] ) ) ||
( empty( $options['wpscan-api-token'] ) )
)
) {
vipgoci_sysexit(
'--wpscan-api is set to true, but --wpscan-api-paths, or --wpscan-api-token are not set or are empty',
array(
'wpscan-api-paths' => isset( $options['wpscan-api-paths'] ) ? $options['wpscan-api-paths'] : null,
'wpscan-api-token' => isset( $options['wpscan-api-token'] ) ? $options['wpscan-api-token'] : null,
),
VIPGOCI_EXIT_USAGE_ERROR
);
}
/*
* Hide WPScan API token from printed options output.
*/
vipgoci_options_sensitive_clean(
null,
array(
'wpscan-api-token',
)
);
}
/**
* Clean up from PHPCS customizations.
*
* @param array $options Array of options.
*
* @return void
*/
function vipgoci_run_cleanup_phpcs( array &$options ) :void {
/*
* Remove temporary PHPCS XML standard
* file if used.
*/
if (
( true === $options['phpcs-standard-file'] ) &&
( file_exists(
$options['phpcs-standard'][0]
) )
) {
unlink(
$options['phpcs-standard'][0]
);
}
}
/**
* Process SVG options.
*
* @param array $options Array of options.
*
* @return void
*/
function vipgoci_run_init_options_svg( array &$options ) :void {
/*
* Process --svg-checks and --svg-scanner-path -- former expected
* to be a boolean, the latter a file-path.
*/
vipgoci_option_bool_handle( $options, 'svg-checks', 'false' );
/*
* Process --svg-php-path if to do SVG scan --
* expected to be a file, default value is 'php'
* (then relies on $PATH).
*/
if ( true === $options['svg-checks'] ) {
vipgoci_option_file_handle(
$options,
'svg-php-path',
'php'
);
} else {
$options['svg-php-path'] = null;
}
/*
* If --svg-checks is set to true,
* check if a sensible scanning-tool is specified.
*
* If not set to true, set a null value.
*/
if ( true === $options['svg-checks'] ) {
vipgoci_option_file_handle(
$options,
'svg-scanner-path',
null
);
} else {
$options['svg-scanner-path'] = null;
}
/*
* Process --svg-file-extensions -- expected to be
* an array of strings.
*/
vipgoci_option_array_handle(
$options,
'svg-file-extensions',
VIPGOCI_SVG_FILE_EXTENSIONS_DEFAULT
);
}
/**
* Process auto-approve options.
*
* @param array $options Array of options.
*
* @return void
*/
function vipgoci_run_init_options_autoapprove( array &$options ) :void {
/*
* Process --autoapprove and --autoapprove-php-nonfunctional-changes
* boolean options.
*/
vipgoci_option_bool_handle( $options, 'autoapprove', 'false' );
vipgoci_option_bool_handle( $options, 'autoapprove-php-nonfunctional-changes', 'false' );
vipgoci_option_array_handle(
$options,
'autoapprove-php-nonfunctional-changes-file-extensions',
VIPGOCI_APPROVAL_AUTOAPPROVE_NON_FUNCTIONAL_CHANGES_FILE_EXTENSIONS_DEFAULT
);
/*
* Process --autoapprove-filetypes, array option.
*
* Values will be converted to lowercase.
*/
if ( true === $options['autoapprove'] ) {
vipgoci_option_array_handle(
$options,
'autoapprove-filetypes',
array(),
/**
* Cross-reference: We disallow autoapproving PHP
* linted and PHPCS scanned files here, because these
* could contain dangerous code.
*
* Also disallow autoapproving SVG files here, as there
* is a dedicated part of vip-go-ci to scan them and
* autoapprove. Similar applies to non-functional changes.
*/
array_unique(
array_merge(
$options['lint-file-extensions'],
$options['phpcs-file-extensions'],
$options['svg-file-extensions'],
$options['autoapprove-php-nonfunctional-changes-file-extensions'],
)
)
);
} else {
$options['autoapprove-filetypes'] = array();
}
/*
* Process --autoapprove-label. Set to boolean
* false if not specified, otherwise string containing
* label.
*/
if ( empty( $options['autoapprove-label'] ) ) {
$options['autoapprove-label'] = false;
} else {
$options['autoapprove-label'] = trim(
$options['autoapprove-label']
);
}
/*
* Sanity check, ensure that if we auto-approve,
* filetypes and a label are specified.
*/
if (
( true === $options['autoapprove'] ) &&
(
( empty( $options['autoapprove-filetypes'] ) ) ||
( false === $options['autoapprove-label'] )
)
) {
vipgoci_sysexit(
'To be able to auto-approve, file-types to approve ' .
'must be specified, as well as a label; see --help ' .
'for information',
array(),
VIPGOCI_EXIT_USAGE_ERROR
);
}
}
/**
* Set options relating to GitHub reviews
*
* @param array $options Array of options.
*
* @return void
*/
function vipgoci_run_init_options_reviews( array &$options ) :void {
/*
* Process --report-no-issues-found
*/
vipgoci_option_bool_handle(
$options,
'report-no-issues-found',
'true'
);
/*
* Process --review-comments-sort -- determines if to sort review comments by severity.
* Also process --review-comments-include-severity -- will include severity in comments.
*/
vipgoci_option_bool_handle(
$options,
'review-comments-sort',
'false'
);
vipgoci_option_bool_handle(
$options,
'review-comments-include-severity',
'false'
);
/*
* Maximum number of inline comments posted to
* Github with one review -- from 5 to 100.
*/
vipgoci_option_integer_handle(
$options,