UNPKG

49.1 kBTypeScriptView Raw
1//
2// Autogenerated from scripts/danger-dts.ts
3//
4
5import { Octokit as GitHub } from "@octokit/rest"
6
7type MarkdownString = string
8// TODO: extract out from BitBucket specifically, or create our own type
9
10interface BitBucketCloudJSONDSL {
11 /** The pull request and repository metadata */
12 metadata: RepoMetaData
13 /** The PR metadata */
14 pr: BitBucketCloudPRDSL
15 /** The commits associated with the pull request */
16 commits: BitBucketCloudCommit[]
17 /** The comments on the pull request */
18 comments: BitBucketCloudPRComment[]
19 /** The activities such as OPENING, CLOSING, MERGING or UPDATING a pull request */
20 activities: BitBucketCloudPRActivity[]
21}
22
23interface BitBucketCloudDSL extends BitBucketCloudJSONDSL {}
24
25interface BitBucketCloudPagedResponse<T> {
26 pagelen: number
27 size: number
28 page: number
29 next: string | undefined
30 previous: string | undefined
31 values: T[]
32}
33interface BitBucketCloudPRDSL {
34 /** The PR's ID */
35 id: number
36 /** Title of the pull request. */
37 title: string
38 /** The text describing the PR */
39 description: string
40 /** The pull request's current status. */
41 state: "OPEN" | "MERGED" | "DECLINED" | "SUPERSEDED"
42 /** Date PR created as number of milliseconds since the unix epoch */
43 created_on: number
44 /** Date PR updated as number of milliseconds since the unix epoch */
45 updated_on: number
46 /** The PR's source, The repo Danger is running on */
47 source: BitBucketCloudMergeRef
48 /** The PR's destination */
49 destination: BitBucketCloudMergeRef
50 /** The creator of the PR */
51 author: BitBucketCloudUser
52 /** People requested as reviewers */
53 reviewers: BitBucketCloudUser[]
54 /** People who have participated in the PR */
55 participants: BitBucketCloudPRParticipant[]
56 /** Misc links for hypermedia conformance */
57 links: BitBucketCloudLinks<
58 "decline" | "commits" | "self" | "comments" | "merge" | "html" | "activity" | "diff" | "approve" | "statuses"
59 >
60}
61
62interface BitBucketCloudMergeRef {
63 commit: {
64 hash: string
65 }
66 branch: {
67 name: string
68 }
69 repository: BitBucketCloudRepo
70}
71
72type BitBucketCloudLinks<Names extends string> = {
73 [key in Names]: {
74 href: string
75 }
76}
77
78interface BitBucketCloudPRParticipant {
79 /*The user who participated in this PR */
80 user: BitBucketCloudUser
81
82 /** How did they contribute */
83 role: "REVIEWER" | "PARTICIPANT"
84
85 /** Did they approve of the PR? */
86 approved: boolean
87}
88
89interface BitBucketCloudRepo {
90 name: string
91 full_name: string
92 uuid: string
93}
94
95interface BitBucketCloudUser {
96 /** The uuid of the commit author */
97 uuid: string
98
99 /** The display name of the commit author */
100 display_name: string
101
102 /** The nick name of the commit author */
103 nickname: string
104
105 /** The acount id of the commit author */
106 account_id: string
107}
108
109/** A BitBucketCloud specific implementation of a git commit. */
110interface BitBucketCloudCommit {
111 /** The SHA for the commit */
112 hash: string
113
114 /** The author of the commit, assumed to be the person who wrote the code. */
115 author: {
116 /** Format: `Foo Bar <foo@bar.com>` */
117 raw: string
118 user: BitBucketCloudUser
119 }
120
121 /** When the commit was committed to the project, in ISO 8601 format */
122 date: string
123 /** The commit's message */
124 message: string
125 /** The commit's parents */
126 parents: {
127 /** The full SHA */
128 hash: string
129 }[]
130
131 /** The commit's links */
132 links: BitBucketCloudLinks<"html">
133}
134
135interface BitBucketCloudContent {
136 raw: string
137 markup: string
138 html: string
139 type: "rendered"
140}
141
142interface BitBucketCloudPRComment {
143 deleted: boolean
144 links: BitBucketCloudLinks<"self" | "html">
145
146 pullrequest: {
147 id: number
148 links: BitBucketCloudLinks<"self" | "html">
149 title: string
150 }
151 content: BitBucketCloudContent
152
153 /** When the comment was created, in ISO 8601 format */
154 created_on: string
155 user: BitBucketCloudUser
156
157 /** When the comment was updated, in ISO 8601 format */
158 updated_on: string
159 type: string
160 id: number
161
162 inline?: {
163 to: number | null
164 from: number
165 path: string
166 }
167}
168
169interface BitBucketCloudPRActivity {
170 comment?: BitBucketCloudPRComment
171 pull_request: {
172 id: number
173 title: string
174 }
175}
176/** Key details about a repo */
177interface RepoMetaData {
178 /** A path like "artsy/eigen" */
179 repoSlug: string
180 /** The ID for the pull/merge request "11" */
181 pullRequestID: string
182}
183
184// This is `danger.bitbucket_server` inside the JSON
185
186interface BitBucketServerJSONDSL {
187 /** The pull request and repository metadata */
188 metadata: RepoMetaData
189 /** The related JIRA issues */
190 issues: JIRAIssue[]
191 /** The PR metadata */
192 pr: BitBucketServerPRDSL
193 /** The commits associated with the pull request */
194 commits: BitBucketServerCommit[]
195 /** The comments on the pull request */
196 comments: BitBucketServerPRActivity[]
197 /** The activities such as OPENING, CLOSING, MERGING or UPDATING a pull request */
198 activities: BitBucketServerPRActivity[]
199}
200
201interface BitBucketServerAPIDSL {
202 /** Gets the contents of a file from a repo (defaults to yours) */
203 getFileContents(filePath: string, repoSlug?: string, refspec?: string): Promise<string>
204
205 /** Make a get call against the bitbucket server API */
206 get(path: string, headers: any, suppressErrors?: boolean): Promise<any>
207
208 /** Make a post call against the bitbucket server API */
209 post(path: string, headers: any, body: any, suppressErrors?: boolean): Promise<any>
210
211 /** Make a put call against the bitbucket server API */
212 put(path: string, headers: any, body: any): Promise<any>
213
214 /** Make a delete call against the bitbucket server API */
215 delete(path: string, headers: any, body: any): Promise<any>
216}
217
218// This is `danger.bitbucket_server`
219
220/** The BitBucketServer metadata for your PR */
221interface BitBucketServerDSL extends BitBucketServerJSONDSL {
222 /**
223 * An authenticated API so you can extend danger's behavior.
224 */
225 api: BitBucketServerAPIDSL
226}
227
228/**
229 * This is `danger.bitbucket_server.issues` It refers to the issues that are linked to the Pull Request.
230 */
231interface JIRAIssue {
232 /** The unique key for the issue e.g. JRA-11 */
233 key: string
234 /** The user-facing URL for that issue */
235 url: string
236}
237
238// This is `danger.bitbucket_server.pr`
239//
240// References:
241// - https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/pullrequests/%7Bpull_request_id%7D
242// - https://docs.atlassian.com/bitbucket-server/javadoc/4.3.2/api/reference/classes.html
243
244/**
245 * An exact copy of the PR's reference JSON. This interface has type'd the majority
246 * of it for tooling's sake, but any extra metadata which BitBucket Server send
247 * will still be inside the JS object.
248 */
249
250interface BitBucketServerPRDSL {
251 /** The PR's ID */
252 id: number
253 /** The API version */
254 version: number
255 /** Title of the pull request. */
256 title: string
257 /** The text describing the PR */
258 description: string
259 /** The pull request's current status. */
260 state: "OPEN" | "MERGED" | "DECLINED" | "SUPERSEDED"
261 /** Is the PR open? */
262 open: boolean
263 /** Is the PR closed? */
264 closed: boolean
265 /** Date PR created as number of milliseconds since the unix epoch */
266 createdDate: number
267 /** Date PR updated as number of milliseconds since the unix epoch */
268 updatedDate: number
269 /** The PR submitter's reference */
270 fromRef: BitBucketServerMergeRef
271 /** The repo Danger is running on */
272 toRef: BitBucketServerMergeRef
273 /** Was this PR locked? */
274 locked: boolean
275 /** The creator of the PR */
276 author: BitBucketServerPRParticipant & { role: "AUTHOR" }
277 /** People requested as reviewers */
278 reviewers: (BitBucketServerPRParticipant & { role: "REVIEWER" })[]
279 /** People who have participated in the PR */
280 participants: (BitBucketServerPRParticipant & { role: "PARTICIPANT" })[]
281 /** Misc links for hypermedia conformance */
282 links: BitBucketServerLinks<"self">
283}
284
285// These are the individual subtypes of objects inside the larger DSL objects above.
286
287/** A BitBucketServer specific implementation of a git commit. */
288interface BitBucketServerCommit {
289 /** The SHA for the commit */
290 id: string
291 /** The shortened SHA for the commit */
292 displayId: string
293 /** The author of the commit, assumed to be the person who wrote the code. */
294 author: {
295 /** The id of the commit author */
296 name: string
297 /** The display name of the commit author */
298 displayName: string
299 /** The email of the commit author */
300 emailAddress: string
301 }
302 /** The UNIX timestamp for when the commit was authored */
303 authorTimestamp: number
304 /** The author of the commit, assumed to be the person who committed/merged the code into a project. */
305 committer: {
306 /** The id of the commit committer */
307 name: string
308 /** The display name of the commit committer */
309 displayName: string
310 /** The email of the commit committer */
311 emailAddress: string
312 }
313 /** When the commit was committed to the project */
314 committerTimestamp: number
315 /** The commit's message */
316 message: string
317 /** The commit's parents */
318 parents: {
319 /** The full SHA */
320 id: string
321 /** The simplified sha */
322 displayId: string
323 }[]
324}
325
326interface BitBucketServerDiff {
327 /** The file reference when moved */
328 destination?: BitBucketServerFile
329 /** The original file reference */
330 source?: BitBucketServerFile
331 /** A set of diff changes */
332 hunks: BitBucketServerHunk[]
333 /** If the hunk is massive, then it will be truncated */
334 truncated: boolean
335 /** The commit SHA which changed this hunk */
336 toHash: string
337 /** Last SHA where this hunk was changed */
338 fromHash: string
339 /** The settings for the whitespace */
340 whitespace: "SHOW" | "IGNORE_ALL"
341}
342
343interface BitBucketServerFile {
344 components: string[]
345 name: string
346 parent: string
347 toString: string
348}
349
350interface BitBucketServerHunk {
351 destinationLine: number
352 destinationSpan: number
353 segments: BitBucketServerSegment[]
354 sourceLine: number
355 sourceSpan: number
356 truncated: boolean
357}
358
359interface BitBucketServerSegment {
360 lines: BitBucketServerLine[]
361 truncated: boolean
362 type: "ADDED" | "REMOVED" | "CONTEXT"
363}
364
365interface BitBucketServerLine {
366 source: number
367 destination: number
368 line: string
369 truncated: boolean
370 conflictMarker?: "OURS"
371 commentIds?: number[]
372}
373
374interface BitBucketServerPRParticipant {
375 /*The user for */
376 user: BitBucketServerUser
377 /** How did they contribute */
378 role: "AUTHOR" | "REVIEWER" | "PARTICIPANT"
379 /** Did they approve of the PR? */
380 approved: boolean
381 /** Their review feedback */
382 status: "APPROVED" | "UNAPPROVED" | "NEEDS_WORK"
383}
384
385/**
386 * A BitBucketServer user account.
387 */
388interface BitBucketServerUser {
389 /** The name of the user */
390 name: string
391 /** The email for the user */
392 emailAddress: string
393 /** The unique user ID */
394 id: number
395 /** The name to use when referencing the user */
396 displayName: string
397 /** Is the account active */
398 active: boolean
399 /** The user's slug for URLs */
400 slug: string
401 /** The type of a user, "NORMAL" being a typical user3 */
402 type: "NORMAL" | "SERVICE"
403}
404
405/**
406 * A BitBucket Server Repo
407 */
408interface BitBucketServerRepo {
409 /** The slug for the repo */
410 slug: string
411 /** The repo name */
412 name?: string
413 /** The type of SCM tool, probably "git" */
414 scmId: string
415 /** Is the repo public? */
416 public: boolean
417 /** Can someone fork this repo? */
418 forkable: boolean
419 /** Links for the projects */
420 links: BitBucketServerLinks<"self" | "clone">
421 /** An abstraction for grouping repos */
422 project: {
423 /** The project unique id */
424 id: number
425 /** The project's human readable project key */
426 key: string
427 /** Is the project publicly available */
428 public: boolean
429 /** The name of the project */
430 name: string
431 /** The project's type */
432 type: string
433 /** Hyperlinks for the project */
434 links: BitBucketServerLinks<"self">
435 }
436}
437
438type BitBucketServerLinks<Names> = {
439 [key in keyof Names]: {
440 href: string
441 name?: string
442 }[]
443}
444
445interface BitBucketServerMergeRef {
446 id: string
447 displayId: string
448 latestCommit: string
449 repository: BitBucketServerRepo
450}
451
452interface BitBucketServerPRActivity {
453 action: "COMMENTED" | "OPENED" | "MERGED" | "DECLINED" | "UPDATED"
454 comment?: BitBucketServerPRComment
455 commentAction?: "ADDED" | "UPDATED"
456 commentAnchor?: {
457 diffType: "COMMIT" | "EFFECTIVE" | "REQUIRED" | "RANGE"
458 line: number
459 lineType: "CONTEXT" | "ADDED" | "REMOVED"
460 fileType: "FROM" | "TO"
461 fromHash: string
462 path: string
463 srcPath: string
464 toHash: string
465 }
466 createdDate: number
467 id: number
468 user: BitBucketServerUser
469}
470
471interface BitBucketServerPRComment {
472 author: BitBucketServerUser
473 comments: BitBucketServerPRActivity[]
474 createdDate: number
475 updatedDate: number
476 id: number
477 permittedOperations: {
478 deletable: boolean
479 editable: boolean
480 }
481 text: string
482 version: number
483 parent?: {
484 id: number
485 }
486}
487
488interface BitBucketServerPagedResponse<T> {
489 size: number
490 limit: number
491 isLastPage: boolean
492 start: number
493 filter: never | null // TODO: remove never
494 nextPageStart: number | null
495 values: T
496}
497
498interface BitBucketServerChangesValueAddCopyModifyDelete {
499 type: "ADD" | "COPY" | "MODIFY" | "DELETE" | "UNKNOWN"
500 path: {
501 toString: string
502 }
503}
504
505interface BitBucketServerChangesValueMove {
506 type: "MOVE"
507 path: {
508 toString: string
509 }
510 srcPath: {
511 toString: string
512 }
513}
514
515// prettier-ignore
516type BitBucketServerChangesValue = BitBucketServerChangesValueAddCopyModifyDelete | BitBucketServerChangesValueMove
517
518/** A platform agnostic reference to a Git commit */
519interface GitCommit {
520 /** The SHA for the commit */
521 sha: string
522 /** Who wrote the commit */
523 author: GitCommitAuthor
524 /** Who deployed the commit */
525 committer: GitCommitAuthor
526 /** The commit message */
527 message: string
528 /** Potential parent commits, and other assorted metadata */
529 tree: any
530 /** SHAs for the commit's parents */
531 parents?: string[]
532 /** Link to the commit */
533 url: string
534}
535
536/** An author of a commit */
537interface GitCommitAuthor {
538 /** The display name for the author */
539 name: string
540 /** The authors email */
541 email: string
542 /** ISO6801 date string */
543 date: string
544}
545/**
546 * The shape of the JSON passed between Danger and a subprocess. It's built
547 * to be expanded in the future.
548 */
549interface DangerJSON {
550 danger: DangerDSLJSONType
551}
552
553/**
554 * The available Peril interface, it is possible that this is not
555 * always up to date with true DSL in Peril, but I'll be giving it
556 * a good shot.
557 */
558
559interface PerilDSL {
560 /**
561 * A set of key:value string based on ENV vars that have
562 * been set to be exposed to your Peril config
563 */
564 env: any
565
566 /**
567 * Allows you to schedule a task declared in your Peril config to run in a certain time-frame,
568 * e.g `runTask("reminder_pr_merge", "in 2 days", { number: 2 })`. For more details on how this
569 * works, see the Peril documentation.
570 * @param taskName the name found in your Peril config
571 * @param time the time interval (uses human-internal module)
572 * @param data data which will be passed through to the script
573 */
574 runTask: (taskName: string, time: string, data: any) => void
575
576 /**
577 * When running a task, the data passed in when the task
578 * was originally scheduled, you can also get this as the first
579 * argument in a default function. Deprecated, use a default export
580 * function. I'll remove this sometime.
581 */
582 data?: any
583}
584
585/**
586 * The root of the Danger JSON DSL.
587 */
588
589interface DangerDSLJSONType {
590 /** The data only version of Git DSL */
591 git: GitJSONDSL
592 /** The data only version of GitHub DSL */
593 github?: GitHubDSL
594 /** The data only version of BitBucket Server DSL */
595 bitbucket_server?: BitBucketServerJSONDSL
596 /** The data only version of BitBucket Cloud DSL */
597 bitbucket_cloud?: BitBucketCloudJSONDSL
598 /** The data only version of GitLab DSL */
599 gitlab?: GitLabDSL
600 /**
601 * Used in the Danger JSON DSL to pass metadata between
602 * processes. It will be undefined when used inside the Danger DSL
603 */
604 settings: {
605 /**
606 * Saves each client re-implementing logic to grab these vars
607 * for their API clients
608 */
609 github: {
610 /** API token for the GitHub client to use */
611 accessToken: string
612 /** Optional URL for enterprise GitHub */
613 baseURL: string | undefined
614 /** Optional headers to add to a request */
615 additionalHeaders: any
616 }
617 /**
618 * This is still a bit of a WIP, but this should
619 * pass args/opts from the original CLI call through
620 * to the process.
621 */
622 cliArgs: CliArgs
623 }
624}
625
626/**
627 * The Danger DSL provides the metadata for introspection
628 * in order to create your own rules.
629 */
630interface DangerDSLType {
631 /**
632 * Details specific to the git changes within the code changes.
633 * Currently, this is just the raw file paths that have been
634 * added, removed or modified.
635 */
636 readonly git: GitDSL
637 /**
638 * The GitHub metadata. This covers things like PR info,
639 * comments and reviews on the PR, label metadata, commits with
640 * GitHub user identities and some useful utility functions
641 * for displaying links to files.
642 *
643 * Strictly speaking, `github` is a nullable type, if you are not using
644 * GitHub then it will be undefined. For the DSL convenience sake though, it
645 * is classed as non-nullable
646 *
647 * Provides an authenticated API so you can work directly
648 * with the GitHub API. This is an instance of the "@octokit/rest" npm
649 * module.
650 *
651 * Finally, if running through Peril on an event other than a PR
652 * this is the full JSON from the webhook. [github-webhook-event-types](https://github.com/orta/github-webhook-event-types) has the full
653 * typings for those webhooks.
654 */
655 readonly github: GitHubDSL
656
657 /**
658 * The BitBucket Server metadata. This covers things like PR info,
659 * comments and reviews on the PR, related issues, commits, comments
660 * and activities.
661 *
662 * Strictly speaking, `bitbucket_server` is a nullable type, if you are not using
663 * BitBucket Server then it will be undefined. For the DSL convenience sake though, it
664 * is classed as non-nullable
665 */
666 readonly bitbucket_server: BitBucketServerDSL
667
668 /**
669 * The BitBucket Cloud metadata. This covers things like PR info,
670 * comments and reviews on the PR, commits, comments, and activities.
671 *
672 * Strictly speaking, `bitbucket_cloud` is a nullable type, if you are not using
673 * BitBucket Cloud then it will be undefined. For the DSL convenience sake though, it
674 * is classed as non-nullable
675 */
676 readonly bitbucket_cloud: BitBucketCloudDSL
677 /**
678 * The GitLab metadata. This covers things like PR info,
679 * comments and reviews on the MR, commits, comments
680 * and activities.
681 *
682 * Strictly speaking, `gitlab` is a nullable type, if you are not using
683 * GitLab then it will be undefined. For the DSL convenience sake though, it
684 * is classed as non-nullable
685 */
686 readonly gitlab: GitLabDSL
687
688 /**
689 * Functions which are globally useful in most Dangerfiles. Right
690 * now, these functions are around making sentences of arrays, or
691 * for making a like of href links easily.
692 */
693 readonly utils: DangerUtilsDSL
694}
695/**
696 * The representation of what running a Dangerfile generates.
697 * This needs to be passed between processes, so data only please.
698 */
699interface DangerResults {
700 /**
701 * Failed messages
702 */
703 fails: Violation[]
704
705 /**
706 * Messages for info
707 */
708 warnings: Violation[]
709
710 /**
711 * A set of messages to show inline
712 */
713 messages: Violation[]
714
715 /**
716 * Markdown messages to attach at the bottom of the comment
717 */
718 markdowns: Violation[]
719
720 /** Meta information about the runtime evaluation */
721 meta?: {
722 /** E.g. "dangerJS", or "Danger Swift" */
723 runtimeName: string
724 /** e.g. "https://danger.systems/js" */
725 runtimeHref: string
726 }
727}
728
729interface DangerRuntimeContainer extends DangerResults {
730 /**
731 * Asynchronous functions to be run after parsing
732 */
733 scheduled?: any[]
734}
735
736interface DangerInlineResults {
737 /**
738 * Path to the file
739 */
740 file: string
741
742 /**
743 * Line in the file
744 */
745 line: number
746
747 /**
748 * Failed messages
749 */
750 fails: string[]
751
752 /**
753 * Messages for info
754 */
755 warnings: string[]
756
757 /**
758 * A set of messages to show inline
759 */
760 messages: string[]
761
762 /**
763 * Markdown messages to attach at the bottom of the comment
764 */
765 markdowns: string[]
766}
767/**
768 * The Danger Utils DSL contains utility functions
769 * that are specific to universal Danger use-cases.
770 */
771interface DangerUtilsDSL {
772 /**
773 * Creates a link using HTML.
774 *
775 * If `href` and `text` are falsy, null is returned.
776 * If `href` is falsy and `text` is truthy, `text` is returned.
777 * If `href` is truthy and `text` is falsy, an <a> tag is returned with `href` as its href and text value.
778 * Otherwise, if `href` and `text` are truthy, an <a> tag is returned with the `href` and `text` inserted as expected.
779 *
780 * @param {string} href The HTML link's destination.
781 * @param {string} text The HTML link's text.
782 * @returns {string|null} The HTML <a> tag.
783 */
784 href(href: string, text: string): string | null
785
786 /**
787 * Converts an array of strings into a sentence.
788 *
789 * @param {string[]} array The array of strings.
790 * @returns {string} The sentence.
791 */
792 sentence(array: string[]): string
793}
794/** All Text diff values will be this shape */
795interface TextDiff {
796 /** The value before the PR's applied changes */
797 before: string
798 /** The value after the PR's applied changes */
799 after: string
800 /** A string containing the full set of changes */
801 diff: string
802 /** A string containing just the added lines */
803 added: string
804 /** A string containing just the removed lines */
805 removed: string
806}
807
808/** Git diff sliced into chunks */
809interface StructuredDiff {
810 /** Git diff chunks */
811 chunks: any[]
812}
813
814/** The results of running a JSON patch */
815interface JSONPatch {
816 /** The JSON in a file at the PR merge base */
817 before: any
818 /** The JSON in a file from the PR submitter */
819 after: any
820 /** The set of operations to go from one JSON to another JSON */
821 diff: JSONPatchOperation[]
822}
823
824/** An individual operation inside an rfc6902 JSON Patch */
825interface JSONPatchOperation {
826 /** An operation type */
827 op: string
828 /** The JSON keypath which the operation applies on */
829 path: string
830 /** The changes for applied */
831 value: string
832}
833
834/** All JSON diff values will be this shape */
835interface JSONDiffValue {
836 /** The value before the PR's applied changes */
837 before: any
838 /** The value after the PR's applied changes */
839 after: any
840 /** If both before & after are arrays, then you optionally get what is added. Empty if no additional objects. */
841 added?: any[]
842 /** If both before & after are arrays, then you optionally get what is removed. Empty if no removed objects. */
843 removed?: any[]
844}
845
846/** A map of string keys to JSONDiffValue */
847interface JSONDiff {
848 [name: string]: JSONDiffValue
849}
850
851// This is `danger.git`
852
853/**
854 *
855 * The Git Related Metadata which is available inside the Danger DSL JSON
856 *
857 * @namespace JSONDSL
858 */
859
860interface GitJSONDSL {
861 /**
862 * Filepaths with changes relative to the git root
863 */
864 readonly modified_files: string[]
865
866 /**
867 * Newly created filepaths relative to the git root
868 */
869 readonly created_files: string[]
870
871 /**
872 * Removed filepaths relative to the git root
873 */
874 readonly deleted_files: string[]
875
876 /** The Git commit metadata */
877 readonly commits: GitCommit[]
878}
879
880/** The shape of the Chainsmoker response */
881type GitMatchResult = {
882 /** Did any file paths match from the git modified list? */
883 modified: any
884 /** Did any file paths match from the git created list? */
885 created: any
886 /** Did any file paths match from the combination of the git modified and created list? */
887 edited: any
888 /** Did any file paths match from the git deleted list? */
889 deleted: any
890}
891
892/** The git specific metadata for a PR */
893interface GitDSL extends GitJSONDSL {
894 /**
895 * A Chainsmoker object to help match paths as an elegant DSL. It
896 * lets you write a globbed string and then get booleans on whether
897 * there are matches within a certain part of the git DSL.
898 *
899 * Use this to create an object which has booleans set on 4 keys
900 * `modified`, `created`, `edited` (created + modified) and `deleted`.
901 *
902 * @example
903 * const packageJSON = danger.git.fileMatch("package.json")
904 * const lockfile = danger.git.fileMatch("yarn.lock")
905 *
906 * if (packageJSON.modified && !lockfile.modified) {
907 * warn("You might have forgotten to run `yarn`.")
908 * }
909 *
910 * @example
911 * const needsSchemaChange = danger.git.fileMatch("src/app/analytics/*.ts")
912 * const schema = danger.git.fileMatch("src/app/analytics/schema.ts")
913 *
914 * if (needsSchemaChange.edited && !schema.modified) {
915 * fail("Changes to the analytics files need to edit update the schema.")
916 * }
917 */
918 fileMatch: Chainsmoker<GitMatchResult>
919
920 /**
921 * Offers the diff for a specific file
922 *
923 * @param {string} filename the path to the json file
924 */
925 diffForFile(filename: string): Promise<TextDiff | null>
926
927 /**
928 * Offers the structured diff for a specific file
929 *
930 * @param {string} filename the path to the json file
931 */
932 structuredDiffForFile(filename: string): Promise<StructuredDiff | null>
933
934 /**
935 * Provides a JSON patch (rfc6902) between the two versions of a JSON file,
936 * returns null if you don't have any changes for the file in the diff.
937 *
938 * Note that if you are looking to just see changes like: before, after, added or removed - you
939 * should use `JSONDiffForFile` instead, as this can be a bit unwieldy for a Dangerfile.
940 *
941 * @param {string} filename the path to the json file
942 */
943 JSONPatchForFile(filename: string): Promise<JSONPatch | null>
944
945 /**
946 * Provides a simplified JSON diff between the two versions of a JSON file. This will always
947 * be an object whose keys represent what has changed inside a JSON file.
948 *
949 * Any changed values will be represented with the same path, but with a different object instead.
950 * This object will always show a `before` and `after` for the changes. If both values are arrays or
951 * objects the `before` and `after`, then there will also be `added` and `removed` inside the object.
952 *
953 * In the case of two objects, the `added` and `removed` will be an array of keys rather than the values.
954 *
955 * This object is represented as `JSONDiffValue` but I don't know how to make TypeScript force
956 * declare that kind of type structure.
957 *
958 * This should make it really easy to do work when specific keypaths have changed inside a JSON file.
959 *
960 * @param {string} filename the path to the json file
961 */
962 JSONDiffForFile(filename: string): Promise<JSONDiff>
963
964 /**
965 * Offers the overall lines of code added/removed in the diff
966 */
967 linesOfCode(): Promise<number | null>
968}
969// This is `danger.github` inside the JSON
970
971interface GitHubJSONDSL {
972 /** The issue metadata for a code review session */
973 issue: GitHubIssue
974 /** The PR metadata for a code review session */
975 pr: GitHubPRDSL
976 /** The PR metadata specifically formatted for using with the GitHub API client */
977 thisPR: GitHubAPIPR
978 /** The github commit metadata for a code review session */
979 commits: GitHubCommit[]
980 /** The reviews left on this pull request */
981 reviews: GitHubReview[]
982 /** The people/teams requested to review this PR */
983 requested_reviewers: GitHubReviewers
984}
985
986// This is `danger.github`
987
988/** The GitHub metadata for your PR */
989interface GitHubDSL extends GitHubJSONDSL {
990 /**
991 * An authenticated API so you can extend danger's behavior by using the [GitHub v3 API](https://developer.github.com/v3/).
992 *
993 * A set up instance of the "github" npm module. You can get the full [API here](https://octokit.github.io/node-github/).
994 */
995 api: GitHub
996 /** A scope for useful functions related to GitHub */
997 utils: GitHubUtilsDSL
998}
999
1000/** Useful functions for GitHub related work */
1001interface GitHubUtilsDSL {
1002 /**
1003 * Creates HTML for a sentence of clickable links for an array of paths.
1004 * This uses the source of the PR as the target, not the destination repo.
1005 * You can manually set the target repo and branch however, to make it work how you want.
1006 *
1007 * @param {string} paths A list of strings representing file paths
1008 * @param {string} useBasename Show either the file name, or the full path - defaults to just file name e.g. true.
1009 * @param {string} repoSlug An optional override for the repo slug, ex: "orta/ORStackView"
1010 * @param {string} branch An optional override for the branch, ex: "v3"
1011 * @returns {string} A HTML string of <a>'s built as a sentence.
1012 */
1013 fileLinks(paths: string[], useBasename?: boolean, repoSlug?: string, branch?: string): string
1014
1015 /**
1016 * Downloads a file's contents via the GitHub API. You'll want to use
1017 * this instead of `fs.readFile` when aiming to support working with Peril.
1018 *
1019 * @param {string} path The path fo the file that exists
1020 * @param {string} repoSlug An optional reference to the repo's slug: e.g. danger/danger-js
1021 * @param {string} ref An optional reference to a branch/sha
1022 */
1023 fileContents(path: string, repoSlug?: string, ref?: string): Promise<string>
1024
1025 /**
1026 * An API for creating, updating and closing an issue. Basically
1027 * this is really useful for reporting back via a separate
1028 * issue that you may want to keep up to date at all times.
1029 *
1030 * @param {string} id The unique ID for the message to create, close
1031 * @param {string} content the content of the message
1032 * @param {any} config settings for the issue
1033 * @returns {string} A HTML string of <a>'s built as a sentence.
1034 */
1035 createUpdatedIssueWithID: (
1036 id: string,
1037 content: string,
1038 config: { title: string; open: boolean; owner: string; repo: string }
1039 ) => Promise<string>
1040
1041 /**
1042 * An API for creating, or setting a label to an issue. Usable from Peril
1043 * by adding an additional param for settings about a repo.
1044 *
1045 * @param {obj} labelConfig The config for the label
1046 * @param {obj | undefined} Optional: the config for the issue
1047 * @returns {Promise<undefined>} No return value.
1048 */
1049 createOrAddLabel: (
1050 labelConfig: { name: string; color: string; description: string },
1051 repoConfig?: { owner: string; repo: string; id: number }
1052 ) => Promise<void>
1053 createOrUpdatePR: (
1054 config: {
1055 /** PR title */
1056 title: string
1057 /** PR body */
1058 body: string
1059 /** The danger in danger/danger-js - defaults to the PR base name if undefined */
1060 owner?: string
1061 /** The danger-js in danger/danger-js - defaults to the PR base repo if undefined */
1062 repo?: string
1063 /** A message for the commit */
1064 commitMessage: string
1065 /** The name of the branch on the repo */
1066 newBranchName: string
1067 /** Base branch for the new branch e.g. what should Danger create the new branch from */
1068 baseBranch: string
1069 },
1070 fileMap: any
1071 ) => Promise<any>
1072}
1073
1074/**
1075 * This is `danger.github.issue` It refers to the issue that makes up the Pull Request.
1076 * GitHub treats all pull requests as a special type of issue. This DSL contains only parts of the issue that are
1077 * not found in the PR DSL, however it does contain the full JSON structure.
1078 *
1079 * A GitHub Issue
1080 */
1081interface GitHubIssue {
1082 /**
1083 * The labels associated with this issue
1084 */
1085 labels: GitHubIssueLabel[]
1086}
1087
1088// Subtypes specific to issues
1089
1090interface GitHubIssueLabel {
1091 /** The identifying number of this label */
1092 id: number
1093
1094 /** The URL that links to this label */
1095 url: string
1096
1097 /** The name of the label */
1098 name: string
1099
1100 /** The color associated with this label */
1101 color: string
1102}
1103
1104interface GitHubIssueComment {
1105 /**
1106 * UUID for the comment
1107 */
1108 id: string
1109
1110 /**
1111 * The User who made the comment
1112 */
1113 user: GitHubUser
1114
1115 /**
1116 * Textual representation of comment
1117 */
1118 body: string
1119}
1120
1121// This is `danger.github.pr`
1122
1123/**
1124 * An exact copy of the PR's reference JSON. This interface has type'd the majority
1125 * of it for tooling's sake, but any extra metadata which GitHub send will still be
1126 * inside the JS object.
1127 */
1128
1129interface GitHubPRDSL {
1130 /**
1131 * The UUID for the PR
1132 */
1133 number: number
1134
1135 /**
1136 * The state for the PR
1137 */
1138 state: "closed" | "open" | "locked" | "merged"
1139
1140 /**
1141 * Has the PR been locked to contributors only?
1142 */
1143 locked: boolean
1144
1145 /**
1146 * The title of the PR
1147 */
1148 title: string
1149
1150 /**
1151 * The markdown body message of the PR
1152 */
1153 body: string
1154
1155 /**
1156 * ISO6801 Date string for when PR was created
1157 */
1158 created_at: string
1159
1160 /**
1161 * ISO6801 Date string for when PR was updated
1162 */
1163 updated_at: string
1164
1165 /**
1166 * optional ISO6801 Date string for when PR was closed
1167 */
1168 closed_at: string | null
1169
1170 /**
1171 * Optional ISO6801 Date string for when PR was merged.
1172 * Danger probably shouldn't be running in this state.
1173 */
1174 merged_at: string | null
1175
1176 /**
1177 * Merge reference for the _other_ repo.
1178 */
1179 head: GitHubMergeRef
1180
1181 /**
1182 * Merge reference for _this_ repo.
1183 */
1184 base: GitHubMergeRef
1185
1186 /**
1187 * The User who submitted the PR
1188 */
1189 user: GitHubUser
1190
1191 /**
1192 * The User who is assigned the PR
1193 */
1194 assignee: GitHubUser
1195
1196 /**
1197 * The Users who are assigned to the PR
1198 */
1199 assignees: GitHubUser[]
1200
1201 /**
1202 * Has the PR been merged yet?
1203 */
1204 merged: boolean
1205
1206 /**
1207 * The number of comments on the PR
1208 */
1209 comments: number
1210
1211 /**
1212 * The number of review-specific comments on the PR
1213 */
1214 review_comments: number
1215
1216 /**
1217 * The number of commits in the PR
1218 */
1219 commits: number
1220
1221 /**
1222 * The number of additional lines in the PR
1223 */
1224 additions: number
1225
1226 /**
1227 * The number of deleted lines in the PR
1228 */
1229 deletions: number
1230
1231 /**
1232 * The number of changed files in the PR
1233 */
1234 changed_files: number
1235
1236 /**
1237 * The link back to this PR as user-facing
1238 */
1239 html_url: string
1240
1241 /** How does the PR author relate to this repo/org? */
1242 author_association:
1243 | "COLLABORATOR"
1244 | "CONTRIBUTOR"
1245 | "FIRST_TIMER"
1246 | "FIRST_TIME_CONTRIBUTOR"
1247 | "MEMBER"
1248 | "NONE"
1249 | "OWNER"
1250}
1251
1252// These are the individual subtypes of objects inside the larger DSL objects above.
1253
1254/** A GitHub specific implementation of a git commit, it has GitHub user names instead of an email. */
1255interface GitHubCommit {
1256 /** The raw commit metadata */
1257 commit: GitCommit
1258 /** The SHA for the commit */
1259 sha: string
1260 /** the url for the commit on GitHub */
1261 url: string
1262 /** The GitHub user who wrote the code */
1263 author: GitHubUser
1264 /** The GitHub user who shipped the code */
1265 committer: GitHubUser
1266 /** An array of parent commit shas */
1267 parents: any[]
1268}
1269
1270/**
1271 * A GitHub user account.
1272 */
1273interface GitHubUser {
1274 /**
1275 * Generic UUID
1276 */
1277 id: number
1278 /**
1279 * The handle for the user/org
1280 */
1281 login: string
1282 /**
1283 * Whether the user is an org, or a user
1284 */
1285 type: "User" | "Organization" | "Bot"
1286 /**
1287 * The url for a users's image
1288 */
1289 avatar_url: string
1290 /**
1291 * The href for a users's page
1292 */
1293 href: string
1294}
1295
1296/**
1297 * A GitHub Repo
1298 */
1299interface GitHubRepo {
1300 /**
1301 * Generic UUID
1302 */
1303 id: number
1304
1305 /**
1306 * The name of the repo, e.g. "Danger-JS"
1307 */
1308 name: string
1309
1310 /**
1311 * The full name of the owner + repo, e.g. "Danger/Danger-JS"
1312 */
1313 full_name: string
1314
1315 /**
1316 * The owner of the repo
1317 */
1318 owner: GitHubUser
1319
1320 /**
1321 * Is the repo publicly accessible?
1322 */
1323 private: boolean
1324
1325 /**
1326 * The textual description of the repo
1327 */
1328 description: string
1329
1330 /**
1331 * Is the repo a fork?
1332 */
1333 fork: boolean
1334
1335 /**
1336 * Is someone assigned to this PR?
1337 */
1338 assignee: GitHubUser
1339
1340 /**
1341 * Are there people assigned to this PR?
1342 */
1343 assignees: GitHubUser[]
1344 /**
1345 * The root web URL for the repo, e.g. https://github.com/artsy/emission
1346 */
1347 html_url: string
1348}
1349
1350interface GitHubMergeRef {
1351 /**
1352 * The human display name for the merge reference, e.g. "artsy:master"
1353 */
1354 label: string
1355
1356 /**
1357 * The reference point for the merge, e.g. "master"
1358 */
1359 ref: string
1360
1361 /**
1362 * The reference point for the merge, e.g. "704dc55988c6996f69b6873c2424be7d1de67bbe"
1363 */
1364 sha: string
1365
1366 /**
1367 * The user that owns the merge reference e.g. "artsy"
1368 */
1369 user: GitHubUser
1370 /**
1371 * The repo from whch the reference comes from
1372 */
1373 repo: GitHubRepo
1374}
1375
1376/**
1377 * GitHubReview
1378 * While a review is pending, it will only have a user. Once a review is complete, the rest of
1379 * the review attributes will be present
1380 * @export
1381 * @interface GitHubReview
1382 */
1383interface GitHubReview {
1384 /**
1385 * The user requested to review, or the user who has completed the review
1386 */
1387 user: GitHubUser
1388 /**
1389 * If there is a review, this provides the ID for it
1390 */
1391 id?: number
1392
1393 /**
1394 * If there is a review, the body of the review
1395 */
1396 body?: string
1397
1398 /**
1399 * If there is a review, the commit ID this review was made on
1400 */
1401 commit_id?: string
1402
1403 /**
1404 * The state of the review
1405 * APPROVED, REQUEST_CHANGES, COMMENT or PENDING
1406 */
1407 state?: "APPROVED" | "REQUEST_CHANGES" | "COMMENT" | "PENDING"
1408}
1409
1410/** Provides the current PR in an easily used way for params in `github.api` calls */
1411interface GitHubAPIPR {
1412 /** The repo owner */
1413 owner: string
1414 /** The repo name */
1415 repo: string
1416 /** The PR number */
1417 number: number
1418}
1419
1420interface GitHubReviewers {
1421 /** Users that have been requested */
1422 users: GitHubUser[]
1423 /** Teams that have been requested */
1424 teams: any[]
1425}
1426// TODO: extract out from BitBucket specifically, or create our own type
1427
1428// getPlatformReviewDSLRepresentation
1429interface GitLabJSONDSL {
1430 /** Info about the repo */
1431 metadata: RepoMetaData
1432 /** Info about the merge request */
1433 mr: GitLabMR
1434 /** All of the individual commits in the merge request */
1435 commits: GitLabMRCommit[]
1436}
1437
1438// danger.gitlab
1439/** The GitLab metadata for your MR */
1440interface GitLabDSL extends GitLabJSONDSL {
1441 utils: {
1442 fileContents(path: string, repoSlug?: string, ref?: string): Promise<string>
1443 }
1444}
1445
1446// ---
1447// JSON responses from API
1448
1449interface GitLabUser {
1450 id: number
1451 name: string
1452 username: string
1453 state: "active" | "blocked"
1454 avatar_url: string | null
1455 web_url: string
1456}
1457
1458interface GitLabUserProfile extends GitLabUser {
1459 created_at: string
1460 bio: string | null
1461 location: string | null
1462 public_email: string
1463 skype: string
1464 linkedin: string
1465 twitter: string
1466 website_url: string
1467 organization: string
1468 last_sign_in_at: string
1469 confirmed_at: string
1470 theme_id: number
1471 last_activity_on: string
1472 color_scheme_id: number
1473 projects_limit: number
1474 current_sign_in_at: string
1475 identities: [{ provider: string; extern_uid: string }]
1476 can_create_group: boolean
1477 can_create_project: boolean
1478 two_factor_enabled: boolean
1479 external: boolean
1480 private_profile: boolean
1481}
1482
1483interface GitLabMRBase {
1484 /** The MR's id */
1485 id: number
1486
1487 /** The unique ID for this MR */
1488 iid: number
1489
1490 /** The project ID for this MR */
1491 project_id: number
1492
1493 /** The given name of the MR */
1494 title: string
1495
1496 /** The body text describing the MR */
1497 description: string
1498
1499 /** The MR's current availability */
1500 state: "closed" | "open" | "locked" | "merged"
1501
1502 /** When was the MR made */
1503 created_at: string
1504
1505 /** When was the MR updated */
1506 updated_at: string
1507
1508 /** What branch is this MR being merged into */
1509 target_branch: string
1510 /** What branch is this MR come from */
1511 source_branch: string
1512
1513 /** How many folks have given it an upvote */
1514 upvotes: number
1515 /** How many folks have given it an downvote */
1516 downvotes: number
1517
1518 /** Who made it */
1519 author: GitLabUser
1520 /** Access rights for the user who created the MR */
1521 user: {
1522 /** Does the author have access to merge? */
1523 can_merge: boolean
1524 }
1525 /** Who was assigned as the person to review */
1526 assignee?: GitLabUser
1527 source_project_id: number
1528 target_project_id: number
1529 labels: string[]
1530 work_in_progress: boolean
1531 milestone: {
1532 id: number
1533 iid: number
1534 project_id: number
1535 title: string
1536 description: string
1537 state: "closed" | "active"
1538 created_at: string
1539 updated_at: string
1540 due_date: string
1541 start_date: string
1542 web_url: string
1543 }
1544 merge_when_pipeline_succeeds: boolean
1545 merge_status: "can_be_merged" // XXX: other statuses?
1546 merge_error: null | null
1547 sha: string
1548 merge_commit_sha: string | null
1549 user_notes_count: number
1550 discussion_locked: null | null
1551 should_remove_source_branch: boolean
1552 force_remove_source_branch: boolean
1553 allow_collaboration: boolean
1554 allow_maintainer_to_push: boolean
1555 web_url: string
1556 time_stats: {
1557 time_estimate: number
1558 total_time_spent: number
1559 human_time_estimate: number | null
1560 human_total_time_spent: number | null
1561 }
1562}
1563
1564/** TODO: These need more comments from someone who uses GitLab, see GitLabDSL.ts in the danger-js repo */
1565interface GitLabMR extends GitLabMRBase {
1566 squash: boolean
1567 subscribed: boolean
1568 changes_count: string
1569 merged_by: GitLabUser
1570 merged_at: string
1571 closed_by: GitLabUser | null
1572 closed_at: string | null
1573 latest_build_started_at: string
1574 latest_build_finished_at: string
1575 first_deployed_to_production_at: string | null
1576 pipeline: {
1577 id: number
1578 sha: string
1579 ref: string
1580 status: "canceled" | "failed" | "pending" | "running" | "skipped" | "success"
1581 web_url: string
1582 }
1583 diff_refs: {
1584 base_sha: string
1585 head_sha: string
1586 start_sha: string
1587 }
1588 diverged_commits_count: number
1589 rebase_in_progress: boolean
1590 approvals_before_merge: null | null
1591}
1592
1593interface GitLabMRChange {
1594 old_path: string
1595 new_path: string
1596 a_mode: string
1597 b_mode: string
1598 diff: string
1599 new_file: boolean
1600 renamed_file: boolean
1601 deleted_file: boolean
1602}
1603
1604interface GitLabMRChanges extends GitLabMRBase {
1605 changes: GitLabMRChange[]
1606}
1607
1608interface GitLabNote {
1609 id: number
1610 type: "DiffNote" | "DiscussionNote" | null // XXX: other types? null means "normal comment"
1611 body: string
1612 attachment: null // XXX: what can an attachment be?
1613 author: GitLabUser
1614 created_at: string
1615 updated_at: string
1616 system: boolean
1617 noteable_id: number
1618 noteable_type: "MergeRequest" // XXX: other types...?
1619 resolvable: boolean
1620 noteable_iid: number
1621}
1622
1623interface GitLabDiscussionTextPosition {
1624 position_type: "text"
1625 base_sha: string
1626 start_sha: string
1627 head_sha: string
1628 new_path: string
1629 new_line: number
1630 old_path: string
1631 old_line: number | null
1632}
1633
1634interface GitLabInlineNote extends GitLabNote {
1635 position: {
1636 base_sha: string
1637 start_sha: string
1638 head_sha: string
1639 old_path: string
1640 new_path: string
1641 position_type: "text" // XXX: other types?
1642 old_line: number | null
1643 new_line: number
1644 }
1645 resolvable: boolean
1646 resolved: boolean
1647 resolved_by: GitLabUser | null
1648}
1649
1650interface GitLabMRCommit {
1651 id: string
1652 short_id: string
1653 created_at: string
1654 parent_ids: string[]
1655 title: string
1656 message: string
1657 author_name: string
1658 author_email: string
1659 authored_date: string
1660 committer_name: string
1661 committer_email: string
1662 committed_date: string
1663}
1664
1665interface GitLabRepositoryFile {
1666 file_name: string
1667 file_path: string
1668 size: number
1669 encoding: "base64"
1670 content: string
1671 content_sha256: string
1672 ref: string
1673 blob_id: string
1674 commit_id: string
1675 last_commit_id: string
1676}
1677
1678interface GitLabCommit {
1679 id: string
1680 short_id: string
1681 title: string
1682 author_name: string
1683 author_email: string
1684 created_at: string
1685}
1686
1687interface GitLabRepositoryCompare {
1688 commit: GitLabCommit
1689 commits: GitLabCommit[]
1690 diffs: GitLabMRChange[]
1691 compare_timeout: boolean
1692 compare_same_ref: boolean
1693}
1694/**
1695 * The result of user doing warn, message or fail, built this way for
1696 * expansion later.
1697 */
1698interface Violation {
1699 /** The string representation */
1700 message: string
1701
1702 /** Optional path to the file */
1703 file?: string
1704
1705 /** Optional line in the file */
1706 line?: number
1707
1708 /** Optional icon for table (Only valid for messages) */
1709 icon?: string
1710}
1711/**
1712 * Describes the possible arguments that
1713 * could be used when calling the CLI
1714 */
1715interface CliArgs {
1716 /** The base reference used by danger PR (e.g. not master) */
1717 base: string
1718 /** For debugging */
1719 verbose: string
1720 /** Used by danger-js o allow having a custom CI */
1721 externalCiProvider: string
1722 /** Use SDTOUT instead of posting to the code review side */
1723 textOnly: string
1724 /** A custom path for the dangerfile (can also be a remote reference) */
1725 dangerfile: string
1726 /** So you can have many danger runs in one code review */
1727 id: string
1728 /** Use staged changes */
1729 staging?: boolean
1730}
1731
1732// NOTE: if add something new here, you need to change dslGenerator.ts
1733/** A function with a callback function, which Danger wraps in a Promise */
1734type CallbackableFn = (callback: (done: any) => void) => void
1735
1736/**
1737 * Types of things which Danger will schedule for you, it's recommended that you
1738 * just throw in an `async () => { [...] }` function. Can also handle a function
1739 * that has a single 'done' arg.
1740 */
1741type Scheduleable = Promise<any> | Promise<void> | CallbackableFn
1742/**
1743 * A Dangerfile, in Peril, is evaluated as a script, and so async code does not work
1744 * out of the box. By using the `schedule` function you can now register a
1745 * section of code to evaluate across multiple tick cycles.
1746 *
1747 * `schedule` currently handles two types of arguments, either a promise or a function with a resolve arg.
1748 *
1749 * @param {Function} asyncFunction the function to run asynchronously
1750 */
1751declare function schedule(asyncFunction: Scheduleable): void
1752
1753/**
1754 * Fails a build, outputting a specific reason for failing into a HTML table.
1755 *
1756 * @param {MarkdownString} message the String to output
1757 * @param {string | undefined} file a file which this message should be attached to
1758 * @param {number | undefined} line the line which this message should be attached to
1759 */
1760declare function fail(message: MarkdownString, file?: string, line?: number): void
1761
1762/**
1763 * Highlights low-priority issues, but does not fail the build. Message
1764 * is shown inside a HTML table.
1765 *
1766 * @param {MarkdownString} message the String to output
1767 * @param {string | undefined} file a file which this message should be attached to
1768 * @param {number | undefined} line the line which this message should be attached to
1769 */
1770declare function warn(message: MarkdownString, file?: string, line?: number): void
1771
1772/**
1773 * Adds a message to the Danger table, the only difference between this
1774 * and warn is the emoji which shows in the table.
1775 *
1776 * @param {MarkdownString} message the String to output
1777 * @param {string | undefined} file a file which this message should be attached to
1778 * @param {number | undefined} line the line which this message should be attached to
1779 */
1780declare function message(message: MarkdownString, file?: string, line?: number): void
1781/**
1782 * Adds a message to the Danger table, the only difference between this
1783 * and warn is the default emoji which shows in the table.
1784 * You can also specifiy a custom emoji to show in the table for each message
1785 *
1786 * @param {MarkdownString} message the String to output
1787 * @param {{file?: string, line?: string, icon?: MarkdownString}} [opts]
1788 * @param opts.file a file which this message should be attached to
1789 * @param opts.line the line which this message should be attached to
1790 * @param opts.icon icon string or image to show in table, take care not to break table formatting
1791 */
1792declare function message(message: MarkdownString, opts?: { file?: string; line?: number; icon?: MarkdownString }): void
1793
1794/**
1795 * Adds raw markdown into the Danger comment, under the table
1796 *
1797 * @param {MarkdownString} message the String to output
1798 * @param {string | undefined} file a file which this message should be attached to
1799 * @param {number | undefined} line the line which this message should be attached to
1800 */
1801declare function markdown(message: MarkdownString, file?: string, line?: number): void
1802
1803/**
1804 * The root Danger object. This contains all of the metadata you
1805 * will be looking for in order to generate useful rules.
1806 */
1807declare const danger: DangerDSLType
1808
1809/**
1810 * When Peril is running your Dangerfile, the Danger DSL is
1811 * extended with additional options.
1812 */
1813declare const peril: PerilDSL
1814
1815/**
1816 * The current results of a Danger run, this can be useful if you
1817 * are wanting to introspect on whether a build has already failed.
1818 */
1819declare const results: DangerRuntimeContainer
1820export declare type Pattern = string
1821export declare type Path = string
1822export declare type KeyedPatterns<T> = { readonly [K in keyof T]: Pattern[] }
1823export declare type KeyedPaths<T> = { readonly [K in keyof T]: Path[] }
1824export declare type _MatchResult<T> = { readonly [K in keyof T]: boolean }
1825export declare type MatchResult<T> = _MatchResult<T> & {
1826 /** Returns an object containing arrays of matched files instead of the usual boolean values. */
1827 getKeyedPaths(): KeyedPaths<T>
1828}
1829/** A vendored copy of the Chainsmoker module on NPM */
1830export declare type Chainsmoker<T> = (...patterns: Pattern[]) => MatchResult<T>