forked from danger/danger-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
danger.d.ts
1682 lines (1496 loc) · 45.1 KB
/
danger.d.ts
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
//
// Autogenerated from scripts/danger-dts.ts
//
import { Octokit as GitHub } from "@octokit/rest"
import { Gitlab, Types } from "@gitbeaker/node"
import { File } from "parse-diff"
type MarkdownString = string
// TODO: extract out from BitBucket specifically, or create our own type
interface BitBucketCloudJSONDSL {
/** The pull request and repository metadata */
metadata: RepoMetaData
/** The PR metadata */
pr: BitBucketCloudPRDSL
/** The commits associated with the pull request */
commits: BitBucketCloudCommit[]
/** The comments on the pull request */
comments: BitBucketCloudPRComment[]
/** The activities such as OPENING, CLOSING, MERGING or UPDATING a pull request */
activities: BitBucketCloudPRActivity[]
}
interface BitBucketCloudDSL extends BitBucketCloudJSONDSL {}
interface BitBucketCloudPagedResponse<T> {
pagelen: number
size: number
page: number
next: string | undefined
previous: string | undefined
values: T[]
}
interface BitBucketCloudPRDSL {
/** The PR's ID */
id: number
/** Title of the pull request. */
title: string
/** The text describing the PR */
description: string
/** The pull request's current status. */
state: "OPEN" | "MERGED" | "DECLINED" | "SUPERSEDED"
/** When the pr was created, in ISO 8601 format */
created_on: string
/** When the pr was updated, in ISO 8601 format */
updated_on: string
/** The PR's source, The repo Danger is running on */
source: BitBucketCloudMergeRef
/** The PR's destination */
destination: BitBucketCloudMergeRef
/** The creator of the PR */
author: BitBucketCloudUser
/** People requested as reviewers */
reviewers: BitBucketCloudUser[]
/** People who have participated in the PR */
participants: BitBucketCloudPRParticipant[]
/** Misc links for hypermedia conformance */
links: BitBucketCloudLinks<
"decline" | "commits" | "self" | "comments" | "merge" | "html" | "activity" | "diff" | "approve" | "statuses"
>
}
interface BitBucketCloudMergeRef {
commit: {
hash: string
}
branch: {
name: string
}
repository: BitBucketCloudRepo
}
type BitBucketCloudLinks<Names extends string> = {
[key in Names]: {
href: string
}
}
interface BitBucketCloudPRParticipant {
/*The user who participated in this PR */
user: BitBucketCloudUser
/** How did they contribute */
role: "REVIEWER" | "PARTICIPANT"
/** Did they approve of the PR? */
approved: boolean
}
interface BitBucketCloudRepo {
name: string
full_name: string
uuid: string
}
interface BitBucketCloudUser {
/** The uuid of the commit author */
uuid: string
/** The display name of the commit author */
display_name: string
/** The nick name of the commit author */
nickname: string
/** The acount id of the commit author */
account_id: string
}
/** A BitBucketCloud specific implementation of a git commit. */
interface BitBucketCloudCommit {
/** The SHA for the commit */
hash: string
/** The author of the commit, assumed to be the person who wrote the code. */
author: {
/** Format: `Foo Bar <foo@bar.com>` */
raw: string
user: BitBucketCloudUser
}
/** When the commit was committed to the project, in ISO 8601 format */
date: string
/** The commit's message */
message: string
/** The commit's parents */
parents: {
/** The full SHA */
hash: string
}[]
/** The commit's links */
links: BitBucketCloudLinks<"html">
}
interface BitBucketCloudContent {
raw: string
markup: string
html: string
type: "rendered"
}
interface BitBucketCloudPRComment {
deleted: boolean
links: BitBucketCloudLinks<"self" | "html">
pullrequest: {
id: number
links: BitBucketCloudLinks<"self" | "html">
title: string
}
content: BitBucketCloudContent
/** When the comment was created, in ISO 8601 format */
created_on: string
user: BitBucketCloudUser
/** When the comment was updated, in ISO 8601 format */
updated_on: string
type: string
id: number
inline?: {
to: number | null
from: number
path: string
}
}
interface BitBucketCloudPRActivity {
comment?: BitBucketCloudPRComment
pull_request: {
id: number
title: string
}
}
/** Key details about a repo */
interface RepoMetaData {
/** A path like "artsy/eigen" */
repoSlug: string
/** The ID for the pull/merge request "11" */
pullRequestID: string
}
// This is `danger.bitbucket_server` inside the JSON
interface BitBucketServerJSONDSL {
/** The pull request and repository metadata */
metadata: RepoMetaData
/** The related JIRA issues */
issues: JIRAIssue[]
/** The PR metadata */
pr: BitBucketServerPRDSL
/** The commits associated with the pull request */
commits: BitBucketServerCommit[]
/** The comments on the pull request */
comments: BitBucketServerPRActivity[]
/** The activities such as OPENING, CLOSING, MERGING or UPDATING a pull request */
activities: BitBucketServerPRActivity[]
}
interface BitBucketServerAPIDSL {
/** Gets the contents of a file from a repo (defaults to yours) */
getFileContents(filePath: string, repoSlug?: string, refspec?: string): Promise<string>
/** Make a get call against the bitbucket server API */
get(path: string, headers: any, suppressErrors?: boolean): Promise<any>
/** Make a post call against the bitbucket server API */
post(path: string, headers: any, body: any, suppressErrors?: boolean): Promise<any>
/** Make a put call against the bitbucket server API */
put(path: string, headers: any, body: any): Promise<any>
/** Make a delete call against the bitbucket server API */
delete(path: string, headers: any, body: any): Promise<any>
}
// This is `danger.bitbucket_server`
/** The BitBucketServer metadata for your PR */
interface BitBucketServerDSL extends BitBucketServerJSONDSL {
/**
* An authenticated API so you can extend danger's behavior.
*/
api: BitBucketServerAPIDSL
}
/**
* This is `danger.bitbucket_server.issues` It refers to the issues that are linked to the Pull Request.
*/
interface JIRAIssue {
/** The unique key for the issue e.g. JRA-11 */
key: string
/** The user-facing URL for that issue */
url: string
}
// This is `danger.bitbucket_server.pr`
//
// References:
// - https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/pullrequests/%7Bpull_request_id%7D
// - https://docs.atlassian.com/bitbucket-server/javadoc/4.3.2/api/reference/classes.html
/**
* 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 BitBucket Server send
* will still be inside the JS object.
*/
interface BitBucketServerPRDSL {
/** The PR's ID */
id: number
/** The API version */
version: number
/** Title of the pull request. */
title: string
/** The text describing the PR */
description: string
/** The pull request's current status. */
state: "OPEN" | "MERGED" | "DECLINED" | "SUPERSEDED"
/** Is the PR open? */
open: boolean
/** Is the PR closed? */
closed: boolean
/** Date PR created as number of milliseconds since the unix epoch */
createdDate: number
/** Date PR updated as number of milliseconds since the unix epoch */
updatedDate: number
/** The PR submitter's reference */
fromRef: BitBucketServerMergeRef
/** The repo Danger is running on */
toRef: BitBucketServerMergeRef
/** Was this PR locked? */
locked: boolean
/** The creator of the PR */
author: BitBucketServerPRParticipant & { role: "AUTHOR" }
/** People requested as reviewers */
reviewers: (BitBucketServerPRParticipant & { role: "REVIEWER" })[]
/** People who have participated in the PR */
participants: (BitBucketServerPRParticipant & { role: "PARTICIPANT" })[]
/** Misc links for hypermedia conformance */
links: BitBucketServerLinks<"self">
}
// These are the individual subtypes of objects inside the larger DSL objects above.
/** A BitBucketServer specific implementation of a git commit. */
interface BitBucketServerCommit {
/** The SHA for the commit */
id: string
/** The shortened SHA for the commit */
displayId: string
/** The author of the commit, assumed to be the person who wrote the code. */
author: {
/** The id of the commit author */
name: string
/** The display name of the commit author */
displayName: string
/** The email of the commit author */
emailAddress: string
}
/** The UNIX timestamp for when the commit was authored */
authorTimestamp: number
/** The author of the commit, assumed to be the person who committed/merged the code into a project. */
committer: {
/** The id of the commit committer */
name: string
/** The display name of the commit committer */
displayName: string
/** The email of the commit committer */
emailAddress: string
}
/** When the commit was committed to the project */
committerTimestamp: number
/** The commit's message */
message: string
/** The commit's parents */
parents: {
/** The full SHA */
id: string
/** The simplified sha */
displayId: string
}[]
}
interface BitBucketServerDiff {
/** The file reference when moved */
destination?: BitBucketServerFile
/** The original file reference */
source?: BitBucketServerFile
/** A set of diff changes */
hunks: BitBucketServerHunk[]
/** If the hunk is massive, then it will be truncated */
truncated: boolean
/** The commit SHA which changed this hunk */
toHash: string
/** Last SHA where this hunk was changed */
fromHash: string
/** The settings for the whitespace */
whitespace: "SHOW" | "IGNORE_ALL"
}
interface BitBucketServerFile {
components: string[]
name: string
parent: string
toString: string
}
interface BitBucketServerHunk {
destinationLine: number
destinationSpan: number
segments: BitBucketServerSegment[]
sourceLine: number
sourceSpan: number
truncated: boolean
}
interface BitBucketServerSegment {
lines: BitBucketServerLine[]
truncated: boolean
type: "ADDED" | "REMOVED" | "CONTEXT"
}
interface BitBucketServerLine {
source: number
destination: number
line: string
truncated: boolean
conflictMarker?: "OURS"
commentIds?: number[]
}
interface BitBucketServerPRParticipant {
/*The user for */
user: BitBucketServerUser
/** How did they contribute */
role: "AUTHOR" | "REVIEWER" | "PARTICIPANT"
/** Did they approve of the PR? */
approved: boolean
/** Their review feedback */
status: "APPROVED" | "UNAPPROVED" | "NEEDS_WORK"
}
/**
* A BitBucketServer user account.
*/
interface BitBucketServerUser {
/** The name of the user */
name: string
/** The email for the user */
emailAddress: string
/** The unique user ID */
id: number
/** The name to use when referencing the user */
displayName: string
/** Is the account active */
active: boolean
/** The user's slug for URLs */
slug: string
/** The type of a user, "NORMAL" being a typical user3 */
type: "NORMAL" | "SERVICE"
}
/**
* A BitBucket Server Repo
*/
interface BitBucketServerRepo {
/** The slug for the repo */
slug: string
/** The repo name */
name?: string
/** The type of SCM tool, probably "git" */
scmId: string
/** Is the repo public? */
public: boolean
/** Can someone fork this repo? */
forkable: boolean
/** Links for the projects */
links: BitBucketServerLinks<"self" | "clone">
/** An abstraction for grouping repos */
project: {
/** The project unique id */
id: number
/** The project's human readable project key */
key: string
/** Is the project publicly available */
public: boolean
/** The name of the project */
name: string
/** The project's type */
type: string
/** Hyperlinks for the project */
links: BitBucketServerLinks<"self">
}
}
type BitBucketServerLinks<Names> = {
[key in keyof Names]: {
href: string
name?: string
}[]
}
interface BitBucketServerMergeRef {
id: string
displayId: string
latestCommit: string
repository: BitBucketServerRepo
}
interface BitBucketServerPRActivity {
action: "COMMENTED" | "OPENED" | "MERGED" | "DECLINED" | "UPDATED"
comment?: BitBucketServerPRComment
commentAction?: "ADDED" | "UPDATED"
commentAnchor?: {
diffType: "COMMIT" | "EFFECTIVE" | "REQUIRED" | "RANGE"
line: number
lineType: "CONTEXT" | "ADDED" | "REMOVED"
fileType: "FROM" | "TO"
fromHash: string
path: string
srcPath: string
toHash: string
}
createdDate: number
id: number
user: BitBucketServerUser
}
interface BitBucketServerPRComment {
author: BitBucketServerUser
comments: BitBucketServerPRActivity[]
createdDate: number
updatedDate: number
id: number
permittedOperations: {
deletable: boolean
editable: boolean
}
text: string
version: number
parent?: {
id: number
}
}
interface BitBucketServerPagedResponse<T> {
size: number
limit: number
isLastPage: boolean
start: number
filter: never | null // TODO: remove never
nextPageStart: number | null
values: T
}
interface BitBucketServerChangesValueAddCopyModifyDelete {
type: "ADD" | "COPY" | "MODIFY" | "DELETE" | "UNKNOWN"
path: {
toString: string
}
}
interface BitBucketServerChangesValueMove {
type: "MOVE"
path: {
toString: string
}
srcPath: {
toString: string
}
}
// prettier-ignore
type BitBucketServerChangesValue = BitBucketServerChangesValueAddCopyModifyDelete | BitBucketServerChangesValueMove
/** A platform agnostic reference to a Git commit */
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 */
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.
*/
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.
*/
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 time-frame,
* 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, you can also get this as the first
* argument in a default function. Deprecated, use a default export
* function. I'll remove this sometime.
*/
data?: any
}
/**
* The root of the Danger JSON DSL.
*/
interface DangerDSLJSONType {
/** The data only version of Git DSL */
git: GitJSONDSL
/** The data only version of GitHub DSL */
github?: GitHubDSL
/** The data only version of BitBucket Server DSL */
bitbucket_server?: BitBucketServerJSONDSL
/** The data only version of BitBucket Cloud DSL */
bitbucket_cloud?: BitBucketCloudJSONDSL
/** The data only version of GitLab DSL */
gitlab?: GitLabDSL
/**
* 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-implementing 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 | undefined
/** 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.
*/
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.
*/
readonly 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.
*
* Strictly speaking, `github` is a nullable type, if you are not using
* GitHub then it will be undefined. For the DSL convenience sake though, it
* is classed as non-nullable
*
* Provides an authenticated API so you can work directly
* with the GitHub API. This is an instance of the "@octokit/rest" npm
* module.
*
* Finally, if running through Peril on an event other than a PR
* this is the full JSON from the webhook. [github-webhook-event-types](https://github.com/orta/github-webhook-event-types) has the full
* typings for those webhooks.
*/
readonly github: GitHubDSL
/**
* The BitBucket Server metadata. This covers things like PR info,
* comments and reviews on the PR, related issues, commits, comments
* and activities.
*
* Strictly speaking, `bitbucket_server` is a nullable type, if you are not using
* BitBucket Server then it will be undefined. For the DSL convenience sake though, it
* is classed as non-nullable
*/
readonly bitbucket_server: BitBucketServerDSL
/**
* The BitBucket Cloud metadata. This covers things like PR info,
* comments and reviews on the PR, commits, comments, and activities.
*
* Strictly speaking, `bitbucket_cloud` is a nullable type, if you are not using
* BitBucket Cloud then it will be undefined. For the DSL convenience sake though, it
* is classed as non-nullable
*/
readonly bitbucket_cloud: BitBucketCloudDSL
/**
* The GitLab metadata. This covers things like PR info,
* comments and reviews on the MR, commits, comments
* and activities.
*
* Strictly speaking, `gitlab` is a nullable type, if you are not using
* GitLab then it will be undefined. For the DSL convenience sake though, it
* is classed as non-nullable
*/
readonly gitlab: GitLabDSL
/**
* Functions which are globally useful in most Dangerfiles. Right
* now, these functions are around making sentences of arrays, or
* for making a like of href links easily.
*/
readonly utils: DangerUtilsDSL
}
/**
* The representation of what running a Dangerfile generates.
* This needs to be passed between processes, so data only please.
*/
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: Violation[]
github?: {
/**
* Markdown text which gets added as a summary in the first
* page which you see when you click through to the PR results.
*
* https://github.blog/2022-05-09-supercharging-github-actions-with-job-summaries/ */
stepSummary?: string
}
/** Meta information about the runtime evaluation */
meta?: {
/** E.g. "dangerJS", or "Danger Swift" */
runtimeName: string
/** e.g. "https://danger.systems/js" */
runtimeHref: string
}
}
interface DangerRuntimeContainer extends DangerResults {
/**
* Asynchronous functions to be run after parsing
*/
scheduled?: any[]
}
interface DangerInlineResults {
/**
* Path to the file
*/
file: string
/**
* Line in the file
*/
line: number
/**
* Failed messages
*/
fails: string[]
/**
* Messages for info
*/
warnings: string[]
/**
* A set of messages to show inline
*/
messages: string[]
/**
* Markdown messages to attach at the bottom of the comment
*/
markdowns: string[]
}
/**
* The Danger Utils DSL contains utility functions
* that are specific to universal Danger use-cases.
*/
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 */
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
}
/** Git diff sliced into chunks */
interface StructuredDiff {
/** Git diff chunks */
chunks: File["chunks"]
}
/** The results of running a JSON patch */
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 */
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 */
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 */
interface JSONDiff {
[name: string]: JSONDiffValue
}
// This is `danger.git`
/**
*
* The Git Related Metadata which is available inside the Danger DSL JSON
*
* @namespace JSONDSL
*/
interface GitJSONDSL {
/**
* Filepaths with changes relative to the git root
*/
readonly modified_files: string[]
/**
* Newly created filepaths relative to the git root
*/
readonly created_files: string[]
/**
* Removed filepaths relative to the git root
*/
readonly deleted_files: string[]
/** The Git commit metadata */
readonly commits: GitCommit[]
}
/** The shape of the Chainsmoker response */
type GitMatchResult = {
/** Did any file paths match from the git modified list? */
modified: any
/** Did any file paths match from the git created list? */
created: any
/** Did any file paths match from the combination of the git modified and created list? */
edited: any
/** Did any file paths match from the git deleted list? */
deleted: any
}
/** The git specific metadata for a PR */
interface GitDSL extends GitJSONDSL {
/**
* The git commit Danger is comparing from.
*/
base: string
/**
* The git commit Danger is comparing to.
*/
head: string
/**
* A Chainsmoker object to help match paths as an elegant DSL. It
* lets you write a globbed string and then get booleans on whether
* there are matches within a certain part of the git DSL.
*
* Use this to create an object which has booleans set on 4 keys
* `modified`, `created`, `edited` (created + modified) and `deleted`.
*
* @example
* const packageJSON = danger.git.fileMatch("package.json")
* const lockfile = danger.git.fileMatch("yarn.lock")
*
* if (packageJSON.modified && !lockfile.modified) {
* warn("You might have forgotten to run `yarn`.")
* }
*
* @example
* const needsSchemaChange = danger.git.fileMatch("src/app/analytics/*.ts")
* const schema = danger.git.fileMatch("src/app/analytics/schema.ts")
*
* if (needsSchemaChange.edited && !schema.modified) {
* fail("Changes to the analytics files need to edit update the schema.")
* }
*/
fileMatch: Chainsmoker<GitMatchResult>
/**
* Offers the diff for a specific file
*
* @param {string} filename the path to the json file
*/
diffForFile(filename: string): Promise<TextDiff | null>
/**
* Offers the structured diff for a specific file
*
* @param {string} filename the path to the json file
*/
structuredDiffForFile(filename: string): Promise<StructuredDiff | 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 unwieldy 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>
/**
* Offers the overall lines of code added/removed in the diff
*
* @param {string} pattern an option glob pattern to filer files that will considered for lines of code.
*/
linesOfCode(pattern?: string): Promise<number | null>
}
// This is `danger.github` inside the JSON
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