/
fixtures.spec.ts.snap
942 lines (809 loc) · 22.1 KB
/
fixtures.spec.ts.snap
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
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`handles the danger.d.ts correctly 1`] = `
"import * as GitHub from \\"@octokit/rest\\";
declare module \\"danger\\" {
declare type MarkdownString = string;
/**
* A platform agnostic reference to a Git commit
*/
declare interface GitCommit {
/**
* The SHA for the commit
*/
sha: string;
/**
* Who wrote the commit
*/
author: GitCommitAuthor;
/**
* Who deployed the commit
*/
committer: GitCommitAuthor;
/**
* The commit message
*/
message: string;
/**
* Potential parent commits, and other assorted metadata
*/
tree: any;
/**
* SHAs for the commit's parents
*/
parents?: string[];
/**
* Link to the commit
*/
url: string;
}
/**
* An author of a commit
*/
declare interface GitCommitAuthor {
/**
* The display name for the author
*/
name: string;
/**
* The authors email
*/
email: string;
/**
* ISO6801 date string
*/
date: string;
}
/**
* The shape of the JSON passed between Danger and a subprocess. It's built
* to be expanded in the future.
*/
declare interface DangerJSON {
danger: DangerDSLJSONType;
}
/**
* The available Peril interface, it is possible that this is not
* always up to date with true DSL in Peril, but I'll be giving it
* a good shot.
*/
declare interface PerilDSL {
/**
* A set of key:value string based on ENV vars that have
* been set to be exposed to your Peril config
*/
env: any;
/**
* Allows you to schedule a task declared in your Peril config to run in a certain timeframe,
* e.g \`runTask(\\"reminder_pr_merge\\", \\"in 2 days\\", { number: 2 })\`. For more details on how this
* works, see the Peril documentation.
* @param taskName the name found in your Peril config
* @param time the time interval (uses human-internal module)
* @param data data which will be passed through to the script
*/
runTask: (taskName: string, time: string, data: any) => void;
/**
* When running a task, the data passed in when the task
* was originally scheduled.
*/
data?: any;
}
/**
* The root of the Danger JSON DSL.
*/
declare interface DangerDSLJSONType {
/**
* The data only version of Git DSL
*/
git: GitJSONDSL;
/**
* The data only version of GitHub DSL
*/
github: GitHubDSL;
/**
* Used in the Danger JSON DSL to pass metadata between
* processes. It will be undefined when used inside the Danger DSL
*/
settings: {
/**
* Saves each client re-implmenting logic to grab these vars
* for their API clients
*/
github: {
/**
* API token for the GitHub client to use
*/
accessToken: string,
/**
* Optional URL for enterprise GitHub
*/
baseURL: string | void,
/**
* Optional headers to add to a request
*/
additionalHeaders: any,
...
},
/**
* This is still a bit of a WIP, but this should
* pass args/opts from the original CLI call through
* to the process.
*/
cliArgs: CliArgs,
...
};
}
/**
* The Danger DSL provides the metadata for introspection
* in order to create your own rules.
*/
declare interface DangerDSLType {
/**
* Details specific to the git changes within the code changes.
* Currently, this is just the raw file paths that have been
* added, removed or modified.
*/
+git: GitDSL;
/**
* The GitHub metadata. This covers things like PR info,
* comments and reviews on the PR, label metadata, commits with
* GitHub user identities and some useful utility functions
* for displaying links to files.
*
* Provides an authenticated API so you can work directly
* with the GitHub API. This is an instance of the \\"@ocktokit/rest\\" npm
* module.
*
* Finally, if running through Peril on an event other than a PR
* this is the full JSON from the webhook. You can find the full
* typings for those webhooks [at github-webhook-event-types](https://github.com/orta/github-webhook-event-types).
*/
+github: GitHubDSL;
/**
* Functions which are globally useful in most Dangerfiles. Right
* now, these functions are around making sentences of arrays, or
* for making hrefs easily.
*/
+utils: DangerUtilsDSL;
}
/**
* The representation of what running a Dangerfile generates.
*
* In the future I'd like this to be cross process, so please
* do not add functions, only data to this interface.
*/
declare interface DangerResults {
/**
* Failed messages
*/
fails: Violation[];
/**
* Messages for info
*/
warnings: Violation[];
/**
* A set of messages to show inline
*/
messages: Violation[];
/**
* Markdown messages to attach at the bottom of the comment
*/
markdowns: MarkdownString[];
}
declare type DangerRuntimeContainer = {
/**
* Asynchronous functions to be run after parsing
*/
scheduled?: any[],
...
} & DangerResults;
/**
* The Danger Utils DSL contains utility functions
* that are specific to universal Danger use-cases.
*/
declare interface DangerUtilsDSL {
/**
* Creates a link using HTML.
*
* If \`href\` and \`text\` are falsy, null is returned.
* If \`href\` is falsy and \`text\` is truthy, \`text\` is returned.
* If \`href\` is truthy and \`text\` is falsy, an <a> tag is returned with \`href\` as its href and text value.
* Otherwise, if \`href\` and \`text\` are truthy, an <a> tag is returned with the \`href\` and \`text\` inserted as expected.
* @param {string} href The HTML link's destination.
* @param {string} text The HTML link's text.
* @returns {string | null} The HTML <a> tag.
*/
href(href: string, text: string): string | null;
/**
* Converts an array of strings into a sentence.
* @param {string[]} array The array of strings.
* @returns {string} The sentence.
*/
sentence(array: string[]): string;
}
/**
* All Text diff values will be this shape
*/
declare interface TextDiff {
/**
* The value before the PR's applied changes
*/
before: string;
/**
* The value after the PR's applied changes
*/
after: string;
/**
* A string containing the full set of changes
*/
diff: string;
/**
* A string containing just the added lines
*/
added: string;
/**
* A string containing just the removed lines
*/
removed: string;
}
/**
* The results of running a JSON patch
*/
declare interface JSONPatch {
/**
* The JSON in a file at the PR merge base
*/
before: any;
/**
* The JSON in a file from the PR submitter
*/
after: any;
/**
* The set of operations to go from one JSON to another JSON
*/
diff: JSONPatchOperation[];
}
/**
* An individual operation inside an rfc6902 JSON Patch
*/
declare interface JSONPatchOperation {
/**
* An operation type
*/
op: string;
/**
* The JSON keypath which the operation applies on
*/
path: string;
/**
* The changes for applied
*/
value: string;
}
/**
* All JSON diff values will be this shape
*/
declare interface JSONDiffValue {
/**
* The value before the PR's applied changes
*/
before: any;
/**
* The value after the PR's applied changes
*/
after: any;
/**
* If both before & after are arrays, then you optionally get what is added. Empty if no additional objects.
*/
added?: any[];
/**
* If both before & after are arrays, then you optionally get what is removed. Empty if no removed objects.
*/
removed?: any[];
}
/**
* A map of string keys to JSONDiffValue
*/
declare interface JSONDiff {
[name: string]: JSONDiffValue;
}
/**
* The Git Related Metadata which is available inside the Danger DSL JSON
* @namespace JSONDSL
*/
declare interface GitJSONDSL {
/**
* Filepaths with changes relative to the git root
*/
+modified_files: string[];
/**
* Newly created filepaths relative to the git root
*/
+created_files: string[];
/**
* Removed filepaths relative to the git root
*/
+deleted_files: string[];
/**
* The Git commit metadata
*/
+commits: GitCommit[];
}
/**
* The git specific metadata for a PR
*/
declare type GitDSL = {
/**
* Offers the diff for a specific file
* @param {string} filename the path to the json file
*/
diffForFile(filename: string): Promise<TextDiff | null>,
/**
* Provides a JSON patch (rfc6902) between the two versions of a JSON file,
* returns null if you don't have any changes for the file in the diff.
*
* Note that if you are looking to just see changes like: before, after, added or removed - you
* should use \`JSONDiffForFile\` instead, as this can be a bit unweildy for a Dangerfile.
* @param {string} filename the path to the json file
*/
JSONPatchForFile(filename: string): Promise<JSONPatch | null>,
/**
* Provides a simplified JSON diff between the two versions of a JSON file. This will always
* be an object whose keys represent what has changed inside a JSON file.
*
* Any changed values will be represented with the same path, but with a different object instead.
* This object will always show a \`before\` and \`after\` for the changes. If both values are arrays or
* objects the \`before\` and \`after\`, then there will also be \`added\` and \`removed\` inside the object.
*
* In the case of two objects, the \`added\` and \`removed\` will be an array of keys rather than the values.
*
* This object is represented as \`JSONDiffValue\` but I don't know how to make TypeScript force
* declare that kind of type structure.
*
* This should make it really easy to do work when specific keypaths have changed inside a JSON file.
* @param {string} filename the path to the json file
*/
JSONDiffForFile(filename: string): Promise<JSONDiff>,
...
} & GitJSONDSL;
declare interface GitHubJSONDSL {
/**
* The issue metadata for a code review session
*/
issue: GitHubIssue;
/**
* The PR metadata for a code review session
*/
pr: GitHubPRDSL;
/**
* The PR metadata specifically formatted for using with the GitHub API client
*/
thisPR: GitHubAPIPR;
/**
* The github commit metadata for a code review session
*/
commits: GitHubCommit[];
/**
* The reviews left on this pull request
*/
reviews: GitHubReview[];
/**
* The people requested to review this PR
*/
requested_reviewers: GitHubUser[];
}
/**
* The GitHub metadata for your PR
*/
declare type GitHubDSL = {
/**
* An authenticated API so you can extend danger's behavior by using the [GitHub v3 API](https://developer.github.com/v3/).
*
* A set up instance of the \\"github\\" npm module. You can get the full [API here](https://octokit.github.io/node-github/).
*/
api: GitHub,
/**
* A scope for useful functions related to GitHub
*/
utils: GitHubUtilsDSL,
...
} & GitHubJSONDSL;
/**
* Useful functions for GitHub related work
*/
declare interface GitHubUtilsDSL {
/**
* Creates HTML for a sentence of clickable links for an array of paths.
* This uses the source of the PR as the target, not the destination repo.
* You can manually set the target repo and branch however, to make it work how you want.
* @param {string} paths A list of strings representing file paths
* @param {string} useBasename Show either the file name, or the full path - defaults to just file name e.g. true.
* @param {string} repoSlug An optional override for the repo slug, ex: \\"orta/ORStackView\\"
* @param {string} branch An optional override for the branch, ex: \\"v3\\"
* @returns {string} A HTML string of <a>'s built as a sentence.
*/
fileLinks(
paths: string[],
useBasename?: boolean,
repoSlug?: string,
branch?: string
): string;
/**
* Downloads a file's contents via the GitHub API. You'll want to use
* this instead of \`fs.readFile\` when aiming to support working with Peril.
* @param {string} path The path fo the file that exists
* @param {string} repoSlug An optional reference to the repo's slug: e.g. danger/danger-js
* @param {string} ref An optional reference to a branch/sha
*/
fileContents(
path: string,
repoSlug?: string,
ref?: string
): Promise<string>;
}
/**
* This is \`danger.github.issue\` It refers to the issue that makes up the Pull Request.
* GitHub treats all pull requests as a special type of issue. This DSL contains only parts of the issue that are
* not found in the PR DSL, however it does contain the full JSON structure.
*
* A GitHub Issue
*/
declare interface GitHubIssue {
/**
* The labels associated with this issue
*/
labels: GitHubIssueLabel[];
}
declare interface GitHubIssueLabel {
/**
* The identifying number of this label
*/
id: number;
/**
* The URL that links to this label
*/
url: string;
/**
* The name of the label
*/
name: string;
/**
* The color associated with this label
*/
color: string;
}
/**
* An exact copy of the PR's reference JSON. This interface has type'd the majority
* of it for tooling's sake, but any extra metadata which GitHub send will still be
* inside the JS object.
*/
declare interface GitHubPRDSL {
/**
* The UUID for the PR
*/
number: number;
/**
* The state for the PR
*/
state: \\"closed\\" | \\"open\\" | \\"locked\\" | \\"merged\\";
/**
* Has the PR been locked to contributors only?
*/
locked: boolean;
/**
* The title of the PR
*/
title: string;
/**
* The markdown body message of the PR
*/
body: string;
/**
* ISO6801 Date string for when PR was created
*/
created_at: string;
/**
* ISO6801 Date string for when PR was updated
*/
updated_at: string;
/**
* optional ISO6801 Date string for when PR was closed
*/
closed_at: string | null;
/**
* Optional ISO6801 Date string for when PR was merged.
* Danger probably shouldn't be running in this state.
*/
merged_at: string | null;
/**
* Merge reference for the _other_ repo.
*/
head: GitHubMergeRef;
/**
* Merge reference for _this_ repo.
*/
base: GitHubMergeRef;
/**
* The User who submitted the PR
*/
user: GitHubUser;
/**
* The User who is assigned the PR
*/
assignee: GitHubUser;
/**
* The Users who are assigned to the PR
*/
assignees: GitHubUser[];
/**
* Has the PR been merged yet?
*/
merged: boolean;
/**
* The number of comments on the PR
*/
comments: number;
/**
* The number of review-specific comments on the PR
*/
review_comments: number;
/**
* The number of commits in the PR
*/
commits: number;
/**
* The number of additional lines in the PR
*/
additions: number;
/**
* The number of deleted lines in the PR
*/
deletions: number;
/**
* The number of changed files in the PR
*/
changed_files: number;
}
/**
* A GitHub specific implmentation of a git commit, it has GitHub user names instead of an email.
*/
declare interface GitHubCommit {
/**
* The raw commit metadata
*/
commit: GitCommit;
/**
* The SHA for the commit
*/
sha: string;
/**
* the url for the commit on GitHub
*/
url: string;
/**
* The GitHub user who wrote the code
*/
author: GitHubUser;
/**
* The GitHub user who shipped the code
*/
committer: GitHubUser;
/**
* An array of parent commit shas
*/
parents: any[];
}
/**
* A GitHub user account.
*/
declare interface GitHubUser {
/**
* Generic UUID
*/
id: number;
/**
* The handle for the user/org
*/
login: string;
/**
* Whether the user is an org, or a user
*/
type: \\"User\\" | \\"Organization\\";
/**
* The url for a users's image
*/
avatar_url: string;
}
/**
* A GitHub Repo
*/
declare interface GitHubRepo {
/**
* Generic UUID
*/
id: number;
/**
* The name of the repo, e.g. \\"Danger-JS\\"
*/
name: string;
/**
* The full name of the owner + repo, e.g. \\"Danger/Danger-JS\\"
*/
full_name: string;
/**
* The owner of the repo
*/
owner: GitHubUser;
/**
* Is the repo publicly accessible?
*/
private: boolean;
/**
* The textual description of the repo
*/
description: string;
/**
* Is the repo a fork?
*/
fork: boolean;
/**
* Is someone assigned to this PR?
*/
assignee: GitHubUser;
/**
* Are there people assigned to this PR?
*/
assignees: GitHubUser[];
/**
* The root web URL for the repo, e.g. https://github.com/artsy/emission
*/
html_url: string;
}
declare interface GitHubMergeRef {
/**
* The human display name for the merge reference, e.g. \\"artsy:master\\"
*/
label: string;
/**
* The reference point for the merge, e.g. \\"master\\"
*/
ref: string;
/**
* The reference point for the merge, e.g. \\"704dc55988c6996f69b6873c2424be7d1de67bbe\\"
*/
sha: string;
/**
* The user that owns the merge reference e.g. \\"artsy\\"
*/
user: GitHubUser;
/**
* The repo from whch the reference comes from
*/
repo: GitHubRepo;
}
/**
* GitHubReview
* While a review is pending, it will only have a user. Once a review is complete, the rest of
* the review attributes will be present
* @export
* @interface GitHubReview
*/
declare interface GitHubReview {
/**
* The user requested to review, or the user who has completed the review
*/
user: GitHubUser;
/**
* If there is a review, this provides the ID for it
*/
id?: number;
/**
* If there is a review, the body of the review
*/
body?: string;
/**
* If there is a review, the commit ID this review was made on
*/
commit_id?: string;
/**
* The state of the review
* APPROVED, REQUEST_CHANGES, COMMENT or PENDING
*/
state?: \\"APPROVED\\" | \\"REQUEST_CHANGES\\" | \\"COMMENT\\" | \\"PENDING\\";
}
/**
* Provides the current PR in an easily used way for params in \`github.api\` calls
*/
declare interface GitHubAPIPR {
/**
* The repo owner
*/
owner: string;
/**
* The repo name
*/
repo: string;
/**
* The PR number
*/
number: number;
}
/**
* The result of user doing warn, message or fail, built this way for
* expansion later.
*/
declare interface Violation {
/**
* The string representation
*/
message: string;
}
/**
* Describes the possible arguments that
* could be used when calling the CLI
*/
declare interface CliArgs {
base: string;
verbose: string;
externalCiProvider: string;
textOnly: string;
dangerfile: string;
id: string;
}
/**
* A function with a callback function, which Danger wraps in a Promise
*/
declare type CallbackableFn = (callback: (done: any) => void) => void;
/**
* Types of things which Danger will schedule for you, it's recommended that you
* just throw in an \`async () => { [...] }\` function. Can also handle a function
* that has a single 'done' arg.
*/
declare type Scheduleable = Promise<any> | Promise<void> | CallbackableFn;
/**
* A Dangerfile, in Peril, is evaluated as a script, and so async code does not work
* out of the box. By using the \`schedule\` function you can now register a
* section of code to evaluate across multiple tick cycles.
*
* \`schedule\` currently handles two types of arguments, either a promise or a function with a resolve arg.
* @param {Function} asyncFunction the function to run asynchronously
*/
declare function schedule(asyncFunction: Scheduleable): void;
/**
* Fails a build, outputting a specific reason for failing into a HTML table.
* @param {MarkdownString} message the String to output
*/
declare function fail(message: MarkdownString): void;
/**
* Highlights low-priority issues, but does not fail the build. Message
* is shown inside a HTML table.
* @param {MarkdownString} message the String to output
*/
declare function warn(message: MarkdownString): void;
/**
* Adds a message to the Danger table, the only difference between this
* and warn is the emoji which shows in the table.
* @param {MarkdownString} message the String to output
*/
declare function message(message: MarkdownString): void;
/**
* Adds raw markdown into the Danger comment, under the table
* @param {MarkdownString} message the String to output
*/
declare function markdown(message: MarkdownString): void;
/**
* The root Danger object. This contains all of the metadata you
* will be looking for in order to generate useful rules.
*/
declare var danger: DangerDSLType;
/**
* When Peril is running your Dangerfile, the Danger DSL is
* extended with additional options.
*/
declare var peril: PerilDSL;
/**
* The current results of a Danger run, this can be useful if you
* are wanting to introspect on whether a build has already failed.
*/
declare var results: DangerRuntimeContainer;
}
"
`;