-
-
Notifications
You must be signed in to change notification settings - Fork 2
788 lines (656 loc) · 40.5 KB
/
issues-scan.yml
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
# #
# @type github workflow
# @desc pull request autoscan
# scans all of the files related to a particular pull request
# if the code in the files being submitted contains code that is forbidden,
# a report is generated and posted as a comment in the PR.
# @author Aetherinox
# @url https://github.com/Aetherinox
# #
name: "🎫 Issues › Scan"
run-name: "🎫 Issues › Scan"
# #
# triggers
# #
on:
pull_request_target:
branches:
- main
- master
# #
# environment variables
# #
env:
LABEL_CHECK_STATUS_FAILED: AC › Failed
LABEL_CHECK_REVIEW_READY: AC › Passed
LABEL_CHECK_CHANGES_REQ: AC › Changes Required
LABEL_CHECK_REVIEW_REQ: AC › Review Required
LABEL_CHECK_REBASE_REQ: AC › Needs Rebase
LABEL_CHECK_SECURITY_ERR: AC › Security Warning
LABEL_CHECK_STATUS_CHGMADE: AC › Changes Made
LABEL_CHECK_SCAN_SKIPPED: AC › Skipped Scan
LABEL_TYPE_PR: Type ◦ Pull Request
LABEL_TYPE_DEPENDENCY: Type ◦ Dependency
LABEL_TYPE_GITACTION: Type ◦ Git Action
BOT_NAME_1: AdminServ
BOT_NAME_2: AdminServX
BOT_NAME_3: EuropaServ
BOT_NAME_DEPENDABOT: dependabot[bot]
LABELS_JSON: |
[
{ "name": "AC › Changes Made", "color": "8F1784", "description": "Requested changes have been made and are pending a re-scan" },
{ "name": "AC › Changes Required", "color": "8F1784", "description": "Requires changes to be made to the package before being accepted" },
{ "name": "AC › Failed", "color": "a61f2d", "description": "Autocheck failed to run through a complete cycle, requires investigation" },
{ "name": "AC › Needs Rebase", "color": "8F1784", "description": "Due to the permissions on the requesting repo, this pull request must be rebased by the author" },
{ "name": "AC › Passed", "color": "146b4a", "description": "Ready to be reviewed" },
{ "name": "AC › Review Required", "color": "8F1784", "description": "PR needs to be reviewed by another person, after the requested changes have been made" },
{ "name": "AC › Security Warning", "color": "761620", "description": "Does not conform to developer policies, or includes potentially dangerous code" },
{ "name": "AC › Skipped Scan", "color": "8F1784", "description": "Author has skipped code scan" },
{ "name": "Status 𐄂 Duplicate", "color": "75536b", "description": "Issue or pull request already exists" },
{ "name": "Status 𐄂 Accepted", "color": "2e7539", "description": "This pull request has been accepted" },
{ "name": "Status 𐄂 Autoclosed", "color": "3E0915", "description": "Originally stale and was autoclosed for no activity" },
{ "name": "Status 𐄂 Denied", "color": "ba4058", "description": "Pull request has been denied" },
{ "name": "Status 𐄂 Locked", "color": "550F45", "description": "Automatically locked by AdminServ for a prolonged period of inactivity" },
{ "name": "Status 𐄂 Need Info", "color": "2E3C4C", "description": "Not enough information to resolve" },
{ "name": "Status 𐄂 No Action", "color": "030406", "description": "Closed without any action being taken" },
{ "name": "Status 𐄂 Pending", "color": "984b12", "description": "Pending pull request" },
{ "name": "Status 𐄂 Released", "color": "1b6626", "description": "Issues or PR has been implemented and is now live" },
{ "name": "Status 𐄂 Reopened", "color": "8a6f14", "description": "A previously closed PR which has been re-opened" },
{ "name": "Status 𐄂 Review", "color": "9e1451", "description": "Currently pending review" },
{ "name": "Status 𐄂 Stale", "color": "928282", "description": "Has not had any activity in over 30 days" },
{ "name": "Type ◦ Bug", "color": "9a2c2c", "description": "Something isn't working" },
{ "name": "Type ◦ Dependency", "color": "243759", "description": "Item is associated to dependency" },
{ "name": "Type ◦ Docs", "color": "0e588d", "description": "Improvements or modifications to docs" },
{ "name": "Type ◦ Feature", "color": "3c4e93", "description": "Feature request" },
{ "name": "Type ◦ Git Action", "color": "030406", "description": "GitHub Action / workflow" },
{ "name": "Type ◦ Pull Request", "color": "8F1784", "description": "Normal pull request" },
{ "name": "Type ◦ Roadmap", "color": "8F1784", "description": "Feature or bug currently planned for implementation" },
{ "name": "Type ◦ Internal", "color": "A51994", "description": "Assigned items are for internal developer use" },
{ "name": "Build ◦ Desktop", "color": "c7ca4a", "description": "Specific to desktop" },
{ "name": "Build ◦ Linux", "color": "c7ca4a", "description": "Specific to Linux" },
{ "name": "Build ◦ MacOS", "color": "c7ca4a", "description": "Specific to MacOS" },
{ "name": "Build ◦ Mobile", "color": "c7ca4a", "description": "Specific to mobile" },
{ "name": "Build ◦ Web", "color": "c7ca4a", "description": "Specific to web" },
{ "name": "Build ◦ Windows", "color": "c7ca4a", "description": "Specific to Windows" },
{ "name": "› API", "color": "F99B50", "description": "Plugin API, CLI, browser JS API" },
{ "name": "› Auto-type", "color": "9141E0", "description": "Auto-type functionality in desktop apps" },
{ "name": "› Browser", "color": "9141E0", "description": "Browser plugins and passing data to <=> from app" },
{ "name": "› Customization", "color": "E3F0FC", "description": "Customizations: plugins, themes, configs" },
{ "name": "› Design", "color": "FA70DE", "description": "Design related queries" },
{ "name": "› Dist", "color": "FA70DE", "description": "Installers and other forms of software distribution" },
{ "name": "› Enterprise", "color": "11447a", "description": "Issues about collaboration, administration, and so on" },
{ "name": "› Hardware", "color": "5a7503", "description": "YubiKey, other tokens, biometrics" },
{ "name": "› Import/Export", "color": "F5FFCC", "description": "Import from and export to different file formats" },
{ "name": "› Improvement", "color": "185c98", "description": "Enhance an existing feature" },
{ "name": "› Performance", "color": "006b75", "description": "Web and desktop performance issues" },
{ "name": "› Plugin Request", "color": "FCE9CA", "description": "Requested changes should be implemented as a plugin" },
{ "name": "› Security", "color": "F75D39", "description": "Security issues" },
{ "name": "› Self-Hosting", "color": "fad8c7", "description": "Self-hosting installations and configs" },
{ "name": "› Storage", "color": "5319e7", "description": "Storage providers: Dropbox, Google, WebDAV, etc." },
{ "name": "› Updater", "color": "1BADDE", "description": "Auto-updater issues" },
{ "name": "› UX", "color": "1BADDE", "description": "UX and usability" },
{ "name": "› Website", "color": "fef2c0", "description": "Website related issues" },
{ "name": "⚠ Urgent", "color": "a8740e", "description": "Requires urgent attention" },
{ "name": "⚠ Announcement", "color": "DB4712", "description": "Announcements" },
{ "name": "📰 Progress Report", "color": "392297", "description": "Development updates" },
{ "name": "📦 Release", "color": "277542", "description": "Release announcements" },
{ "name": "✔️ Poll", "color": "972255", "description": "Community polls" },
{ "name": "❔ Question", "color": "FFFFFF", "description": "All questions" }
]
# #
# jobs
# #
jobs:
# #
# Job [ Autoscan ]
# #
pr-autoscan:
runs-on: ubuntu-latest
permissions:
contents: read
actions: read
issues: write
pull-requests: read
steps:
# #
# action needed if using 'pull_request' and 'issue_comment'
# to get the pull request, you would normally use ${{ github.event.number }}
# however this isnt available for 'issue_comment'
# #
- name: >-
🏷️ Verify Existing Labels
id: task_autocheck_labels_verify
uses: actions/github-script@v7
with:
github-token: ${{ secrets.ADMINSERV_TOKEN_CL || github.token }}
script: |
const labels = JSON.parse( process.env.LABELS_JSON );
for ( const label of labels )
{
try
{
await github.rest.issues.createLabel(
{
owner: context.repo.owner,
repo: context.repo.repo,
name: label.name,
description: label.description || '',
color: label.color
});
}
catch ( err )
{
if ( err.status === 422 )
{
console.log( `Label '${label.name}' already exists. Skipping.` );
}
else
{
console.error( `Error creating label '${label.name}': ${err}` );
}
}
}
# #
# set issue number
# #
- name: >-
#️⃣ Issue number › Set
uses: actions/github-script@v7
id: task_autocheck_issue_num_set
with:
github-token: ${{ secrets.ADMINSERV_TOKEN_CL || github.token }}
script: |
if ( context.issue.number )
{
// Return issue number if present
return context.issue.number;
}
else
{
// Otherwise return issue number from commit
return (
await github.rest.repos.listPullRequestsAssociatedWithCommit(
{
commit_sha: context.sha,
owner: context.repo.owner,
repo: context.repo.repo,
})
).data[ 0 ].number;
}
result-encoding: string
# #
# print issue number
# #
- name: >-
#️⃣ Issue number › Print
id: task_autocheck_issue_num_get
run: |
echo '${{ steps.task_autocheck_issue_num_set.outputs.result }}'
# #
# checkout
# #
- name: >-
☑️ Checkout
id: task_autoscan_checkout
uses: actions/checkout@v4
if: |
( github.event_name == 'pull_request_target' ) || ( github.event_name == 'pull_request' ) || ( github.event_name == 'issue_comment' && contains( github.event.comment.html_url, '/pull/' ) && contains( github.event.comment.body, '/rescan' ) )
with:
fetch-depth: 0
ref: "refs/pull/${{ steps.task_autocheck_issue_num_set.outputs.result }}/merge"
# #
# nodejs
# #
- name: >-
⚙️ Setup Node
id: task_autocheck_nodejs
uses: actions/setup-node@v4
# #
# get list of changed files
#
# Effortlessly track all changed files and directories relative to a target branch,
# the current branch (preceding commit or the last remote commit), multiple branches,
# or custom commits returning relative paths from the project root using this
# GitHub action.
# #
- name: >-
📄 Get changed files
id: task_autocheck_changed_files_get
uses: tj-actions/changed-files@v45
with:
separator: ","
# #
# list of changed files
# #
- name: >-
📄 List all added files
id: task_autocheck_added_files_get
run: |
for file in ${CHANGED_FILES}; do
echo "$file was changed"
done
env:
ADDED_FILES: ${{ steps.task_autocheck_changed_files_get.outputs.added_files }}
MODIFIED_FILES: ${{ steps.task_autocheck_changed_files_get.outputs.modified_files }}
CHANGED_FILES: ${{ steps.task_autocheck_changed_files_get.outputs.all_changed_files }}
COUNT_ADDED: ${{ steps.task_autocheck_changed_files_get.outputs.added_files_count }}
COUNT_MODIFIED: ${{ steps.task_autocheck_changed_files_get.outputs.modified_files_count }}
COUNT_DELETED: ${{ steps.task_autocheck_changed_files_get.outputs.deleted_files_count }}
COUNT_RENAMED: ${{ steps.task_autocheck_changed_files_get.outputs.renamed_files_count }}
COUNT_COPIED: ${{ steps.task_autocheck_changed_files_get.outputs.copied_files_count }}
# #
# List directories
# #
- name: >-
📂 List Directories
id: task_autocheck_dirs_list
run: |
ls
# #
# Run autocheck
# #
- name: >-
☑️ Run Autocheck
id: task_autocheck_run
uses: actions/github-script@v7
with:
github-token: ${{ secrets.ADMINSERV_TOKEN_CL || github.token }}
script: |
const fs = require( 'fs' );
const escape_html = ( unsafe ) => unsafe.replace( /&/g, '&' ).replace( /</g, '<' ).replace( />/g, '>' ).replace( /"/g, '"' ).replace( /'/g, ''' );
const labels = [];
const files_List = `${{ steps.task_autocheck_changed_files_get.outputs.all_changed_files }}` || ''
const files_Array = files_List.split(',')
const branch_ref = `${ context.payload.pull_request.head.ref }`
let message = [ "\n<br />\n" ]
message.push ( "## Automatic Self-Check - #" + context.issue.number + "\n" );
message.push ( `The details of our automated scan for your pull request are listed below. If our scan detected errors, they must be corrected before this pull request will be advanced to the review stage:\n` );
message.push ( "\n<br />\n\n---\n\n<br />\n\n" );
message.push ( "### About\nThis pull request includes the following information:" );
let bHasError = false;
let bHasWarning = false;
let date = new Date( `${ context.payload.pull_request.created_at }` );
date.toISOString( )
const actor = '${{ github.actor }}';
const dateTimeformat = ( date ) =>
{
let month = date.getMonth( ) + 1;
month = month.toString( ).padStart( 2, '0' );
let day = date.getDate( ).toString( ).padStart( 2, '0' );
let year = date.getFullYear( ).toString( ).padStart( 2, '0' );
let hours = date.getHours();
let minutes = date.getMinutes();
let x = hours >= 12 ? 'PM' : 'AM';
hours = hours % 12;
hours = hours ? hours : 12;
minutes = minutes.toString( ).padStart( 2, '0' );
let mergeTime = month + '.' + day + '.' + year + ' ' + hours + ':' + minutes + ' ' + x;
return mergeTime;
}
let date_created = dateTimeformat( date ) + " UTC";
/*
context.payload.pull_request.base.repo.owner.login
*/
let md_table =
`
| Category | Value |
| --- | --- |
| Title | [ ` + context.payload.pull_request.title + ` ](https://github.com/` + context.repo.owner + `/` + context.repo.repo + `/pull/` + context.payload.pull_request.number + `) |
| Created | [ ` + date_created + ` ](https://worldtimebuddy.com) |
| ID | ` + context.payload.pull_request.html_url + ` |
| Author | [ ` + context.payload.pull_request.user.login + ` ](https://github.com/` + context.repo.owner + `/) |
| Repo | [ ` + context.repo.repo + ` ](https://github.com/` + context.repo.owner + `/` + context.repo.repo + `) |
| Branch | [ ` + context.payload.pull_request.head.ref + `](https://github.com/` + context.repo.owner + `/` + context.repo.repo + `/tree/` + context.payload.pull_request.head.ref + `) ⇁ [ ` + context.payload.pull_request.base.ref + `](https://github.com/` + context.repo.owner + `/` + context.repo.repo + `/tree/` + context.payload.pull_request.base.ref + `) |
| Added Files | ${{ steps.task_autocheck_changed_files_get.outputs.added_files_count }} |
| Modified Files | ${{ steps.task_autocheck_changed_files_get.outputs.all_modified_files_count }} |
| Renamed Files | ${{ steps.task_autocheck_changed_files_get.outputs.renamed_files_count }} |
| Copied Files | ${{ steps.task_autocheck_changed_files_get.outputs.deleted_files_count }} |
| Deleted Files | ${{ steps.task_autocheck_changed_files_get.outputs.deleted_files_count }} |
`;
message.push ( md_table );
let error_Generic = "\n" +
"- `MyPlugin`\n" +
"- `MyPluginSettings`\n" +
"- `SampleSettings`\n" +
"- `SampleSettingTab`\n" +
"- `SampleModal`\n"
let warn_BadWords = "\n" +
"- `General`\n" +
"- `Settings`\n"
/*
Loop files
*/
const files_skipped = [];
/*
List of files to skip check
Entries are CASE sensitive
For folders, append / at the end of the parent directory
*/
const type_dependency =
[
"dependabot/npm_and_yarn"
];
const type_gitaction =
[
"dependabot/github_actions"
];
const files_skipList =
[
".github",
".gitea",
".gitignore",
"LICENSE",
".md",
".yml",
"plugins.json",
"package.json",
"package-lock.json",
"rollup.config.js",
"index.js",
"gistr.js",
"Docs/",
"tests/"
];
for ( const file of files_Array )
{
const errors = [];
const addError = ( error ) =>
{
errors.push ( `:x: ${error}` );
console.log ( 'Found Issues: ' + error );
bHasError = true;
};
const warnings = [];
const addWarning = ( warning ) =>
{
warnings.push ( `:warning: ${warning}` );
console.log ( 'Found Warnings: ' + warning );
bHasWarning = true;
}
/*
Regex Searches
*/
const file_current = file;
const filesData = fs.readFileSync( file_current, 'utf8' );
const bContainsStyle = /([A-Za-z]+\.style\.[A-Za-z]+)/gi.test( filesData );
const bFuncFetch = /(fetch)\((.*)\)(\[([^\]]*)\])?/gim.test( filesData );
const bVar = /^(?:var|)\s(\w+)\s*=\s*/gm.test( filesData );
const bLookBehind = /\(\?<[=!].*?\)/gmi.test( filesData );
const bMarkdownHtmlNode = /new\s+NodeHtmlMarkdown/gmi.test( filesData );
const bAsTFile = /as\s+TFile/g.test( filesData );
const bAsTFolder = /as\s+TFolder/g.test( filesData );
const bAsAny = /\((.*? as Any\s*)\)/gi.test( filesData );
const bInnerHTML = /^\s?.*[a-zA-Z0-9_]+\.innerHTML*\s?.*$/gm.test( filesData );
const bOuterHTML = /^\s?.*[a-zA-Z0-9_]+\.outerHTML*\s?.*$/gm.test( filesData );
// const bFuncConsoleLog = /(console.log)\((.*)\)(\[([^\]]*)\])?/gim.test( filesData );
const bFuncSetTimeout = /(setTimeout)\((.*)\)(\[([^\]]*)\])?/gim.test( filesData );
const bFuncFS_Chk1 = /(require)\s?\((\s?(?:'|")fs(?:'|"))\s?\)?/gim.test( filesData );
const bFuncFS_Chk2 = /from\s+(?:'|")fs(?:'|")\s?/gim.test( filesData );
const bFuncFS_ExistsSync = /(fs.existsSync)\((.*)\)(\[([^\]]*)\])?/gm.test( filesData );
const bFuncFS_MkdirSync = /(fs.mkdirSync)\((.*)\)(\[([^\]]*)\])?/gm.test( filesData );
const bFoundBadWord = /(?:'|").*(Settings|General).*(?:'|")?/gmi.test( filesData );
const bContainsGeneric = /(?:^|(?<= ))(MyPlugin|MyPluginSettings|SampleSettings|SampleSettingTab|SampleModal|Sample Plugin|my-plugin)(?:(?= )|$)/gim.test( filesData );
const check_depGetUnpinnedLeaf = "app.workspace.getUnpinnedLeaf"
const bFileSkip = files_skipList.some( s => s.includes( file_current ) || file_current.includes( s ) );
if ( bFileSkip == true )
{
files_skipped.push( file_current );
continue;
}
/*
Header
*/
message.push ( "\n<br />\n\n---\n\n<br />\n" );
message.push ( "### 📄 " + file_current + "\n" );
message = message.concat( warnings );
/*
Skip File
all contents in the array below will be skipped.
E.g: any file which resides in the .github folder will be skipped.
any file which ends in .yml will be skipped.
*/
/*
( Deprecated ) app.workspace.getUnpinnedLeaf
@usage : obsidian.md
*/
/*
if ( filesData.toLowerCase( ).includes( check_depGetUnpinnedLeaf.toLowerCase( ) ) )
{
addError( "This function is deprecated, use `this.app.workspace.getLeaf( false )` instead" );
}
*/
/*
Using inline style
*/
if ( bContainsStyle == true )
{
addError( "Avoid assigning `inline styles` via JavaScript or in HTML. Move these styles to CSS so that they are adaptable by themes and other plugins." );
}
/*
Using fetch
*/
if ( bFuncFetch == true )
{
addError( "Do not handle http data with `fetch( )`. Use the Obsidian API -> `requestUrl` method instead, which will make sure that network requests work on every platform." );
}
/*
Using var
*/
if ( bVar == true )
{
addError( "Change all instances of `var` to **const** or **let**. var has function-level scope, and leads to bugs." );
}
/*
Using lookbehind
*/
if ( bLookBehind == true )
{
addError( "Lookbehinds are not supported in iOS < 16.4" );
}
/*
Using HTML Node
*/
if ( bMarkdownHtmlNode == true )
{
addError( "Do not use `NodeHtmlMarkdown`. Use Obsidian API -> `htmlToMarkdown` instead." );
}
/*
As TFile
*/
if ( bAsTFile == true )
{
addError( "Do not cast `as TFile`, use `instanceof` instead to check if the item is actually a file / folder" );
}
/*
As TFolder
*/
if ( bAsTFolder == true )
{
addError( "Do not cast `as TFolder`, use `instanceof` instead to check if the item is actually a file / folder" );
}
/*
Casting to Any
*/
if ( bAsAny == true )
{
addError( "Do not cast to `Any`" );
}
/*
innerHTML
*/
if ( bInnerHTML == true )
{
addError( `Using \`innerHTML\` is a security risk.` );
}
/*
outerHTML
*/
if ( bOuterHTML == true )
{
addError( `Using \`outerHTML\` is a security risk.` );
}
/*
setTimeout
*/
if ( bFuncSetTimeout == true )
{
addError( "Do not utilize `setTimeout`, utilize Obsidian API -> `sleep`. E.g: `await sleep( X )`" );
}
/*
require("fs")
*/
if ( bFuncFS_Chk1 == true || bFuncFS_Chk2 == true )
{
addError( "`fs` import only available from Node.js runtime, this will throw errors for users running on mobile" );
}
/*
require("fs") / fs.existsSync
*/
if ( bFuncFS_ExistsSync == true )
{
addError( "`fs` import only available from Node.js runtime, this will throw errors for users running on mobile." );
}
/*
require("fs") / fs.mkdirSync
*/
if ( bFuncFS_MkdirSync == true )
{
addError( "`fs` import only available from Node.js runtime, this will throw errors for users running on mobile." );
}
/*
Generic Calls
*/
if ( bContainsGeneric == true )
{
addError( "Rename sample classes to something that makes sense. You are not allowed to have names such as: " + error_Generic );
}
/*
console.log found
*/
/*
if ( bFuncConsoleLog == true )
{
addWarning( "Avoid unnecessary logging or ensure logging only occurs in development environment." );
}
*/
/*
Bad words found
*/
if ( bFoundBadWord == true && file != "package.json" && file != "manifest.json" )
{
addWarning( "A restricted word was found in your code. Generic words are not allowed in strings such as: " + warn_BadWords );
}
if ( errors.length > 0 || warnings.length > 0 )
{
/*
Errors
*/
if ( errors.length > 0 )
{
message.push ( "\n\n\n> [!CAUTION]\n> Errors must be fixed prior to a pull request being reviewed and accepted.<br />The file `" + file + "` contains the following errors:\n\n<br>\n\n" );
message = message.concat( errors );
}
/*
Warnings
*/
if ( warnings.length > 0 )
{
if ( errors.length > 0 )
{
message.push ( "\n<br />\n<br />\n" )
}
message.push ( "\n\n\n> [!WARNING]\n> Warnings are suggestions that do not require fixing, but are recommended before this pull request is reviewed and accepted.<br />The file `" + file + "` contains the following warnings:\n\n<br>\n\n" );
message = message.concat( warnings );
}
}
else
{
message.push ( "\n\n\n> [!NOTE]\n> The file `" + file + "` contains no errors\n\n<br>\n\n" );
}
}
if ( files_skipped.length > 0 )
{
message.push ( "\n<br />\n\n---\n<br />\n" );
message.push ( "### ❌ Skipped Files\n" );
message.push ( "\n\n\n> [!TIP]\n> The following file(s) have been skipped:\n\n<br>\n\n" );
for ( const file_skipped of files_skipped )
{
message.push ( "- " + file_skipped );
}
}
/*
footer
*/
message.push ( "\n<br />\n\n---\n<br />\n" );
message.push ( `<sup>This check was done automatically. Do <b>NOT</b> open a new PR for re-validation. Instead, to trigger this check again, make a change to your PR and wait a few minutes, or close and re-open it.</sup>` );
/*
Has Errors
*/
if ( bHasError == true )
{
labels.push( "${{ env.LABEL_CHECK_STATUS_FAILED }}" );
core.setFailed( "Pull Request Failed Autocheck: " + context.issue.number + ": " + context.payload.pull_request.title + "." );
}
/*
No Errors
*/
if ( bHasError == false )
{
/*
change pr title
*/
const pr_title = `${ context.payload.pull_request.title }`;
const pr_title_append = `PR ${ context.issue.number }:`;
if ( !pr_title.startsWith( pr_title_append ) )
{
await github.rest.pulls.update(
{
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
title: `${ pr_title_append } ${ context.payload.pull_request.title }`
} );
}
if ( !context.payload.pull_request.labels.filter( label => label.name === "${{ env.LABEL_CHECK_CHANGES_REQ }}" ).length > 0 )
labels.push( "${{ env.LABEL_CHECK_REVIEW_READY }}" );
}
/*
Determine Labels
*/
const bGitaction = type_gitaction.some( s => s.includes( branch_ref ) || branch_ref.includes( s ) );
const bDependency = type_dependency.some( s => s.includes( branch_ref ) || branch_ref.includes( s ) );
if ( actor == "${{ env.BOT_NAME_DEPENDABOT }}" && bDependency )
labels.push( "${{ env.LABEL_TYPE_DEPENDENCY }}" );
else if ( actor == "${{ env.BOT_NAME_DEPENDABOT }}" && bGitaction )
labels.push( "${{ env.LABEL_TYPE_GITACTION }}" );
if ( context.payload.pull_request.labels.filter( label => label.name === "${{ env.LABEL_CHECK_CHANGES_REQ }}" ).length > 0 )
labels.push( "${{ env.LABEL_CHECK_CHANGES_REQ }}" );
if (context.payload.pull_request.labels.filter(label => label.name === "${{ env.LABEL_CHECK_REBASE_REQ }}" ).length > 0 )
labels.push( "${{ env.LABEL_CHECK_REBASE_REQ }}" );
if ( context.payload.pull_request.labels.filter(label => label.name === "${{ env.LABEL_CHECK_SECURITY_ERR }}" ).length > 0 )
labels.push( "${{ env.LABEL_CHECK_SECURITY_ERR }}" );
if (context.payload.pull_request.labels.filter( label => label.name === "${{ env.LABEL_CHECK_STATUS_CHGMADE }}" ).length > 0 )
labels.push( "${{ env.LABEL_CHECK_STATUS_CHGMADE }}" );
if ( context.payload.pull_request.labels.filter( label => label.name === "${{ env.LABEL_CHECK_SCAN_SKIPPED }}" ).length > 0 )
labels.push( "${{ env.LABEL_CHECK_SCAN_SKIPPED }}" );
labels.push( "${{ env.LABEL_TYPE_PR }}" );
/*
Set Label
*/
await github.rest.issues.setLabels(
{
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels,
} );
/*
Create Comment
*/
await github.rest.issues.createComment(
{
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: message.join('\n'),
} );