UNPKG

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