UNPKG

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