Skip to content

Commit

Permalink
Merge pull request #190 from danger/dangerfile_ref
Browse files Browse the repository at this point in the history
Update TS definitions to work correctly on 3rd party repos
  • Loading branch information
orta committed Mar 21, 2017
2 parents 3ce3477 + 88fd95d commit 873d4ca
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 28 deletions.
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// Add your own contribution below

### 0.14.0
### 0.14.0 - 0.14.1

* TypeScript Dangerfiles are now support in Danger - orta

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "danger",
"version": "0.14.0",
"version": "0.14.1",
"description": "Unit tests for Team Culture",
"main": "distribution/danger.js",
"typings": "distribution/danger.d.ts",
Expand Down
9 changes: 3 additions & 6 deletions scripts/danger-dts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,12 @@ const createDTS = () => {
// we need to add either `declare function` or `declare var` to the interface
const context = moduleContext.split("\n").map((line: string) => {
if ((line.length === 0) || (line.includes("*"))) { return line }
if (line.includes("(")) { return " function " + line.trim() }
if (line.includes(":")) { return " const " + line.trim() }
if (line.includes("(")) { return "declare function " + line.trim() }
if (line.includes(":")) { return "declare const " + line.trim() }
return ""
}).join("\n")

fileOutput += `declare namespace danger {
${context}
}
`// last extra line is EOF
fileOutput += context

// Remove all JS-y bits
fileOutput = fileOutput.split("\n").filter((line) => {
Expand Down
27 changes: 12 additions & 15 deletions source/danger.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,17 @@ export interface GitDSL {
/**
* Filepaths with changes relative to the git root
*/
readonly modified_files: Readonly<Array<string>>
readonly modified_files: Array<string>

/**
* Newly created filepaths relative to the git root
*/
readonly created_files: Readonly<Array<string>>
readonly created_files: Array<string>

/**
* Removed filepaths relative to the git root
*/
readonly deleted_files: Readonly<Array<string>>
readonly deleted_files: Array<string>

/** Offers the diff for a specific file */
diffForFile(filename: string): string | null,
Expand Down Expand Up @@ -193,7 +193,7 @@ export interface GitDSL {
JSONDiffForFile(filename: string): Promise<any>,

/** The Git commit metadata */
readonly commits: Readonly<Array<GitCommit>>
readonly commits: Array<GitCommit>
}
// This is `danger.github`

Expand Down Expand Up @@ -548,54 +548,51 @@ export interface Violation {
*/
message: string
}

declare namespace danger {
/**
* Contains asynchronous code to be run after the application has booted.
*
* @param {Function} asyncFunction the function to run asynchronously
*/
function schedule(asyncFunction: (p: Promise<any>) => void): void
declare function schedule(asyncFunction: (p: Promise<any>) => void): void

/**
* Fails a build, outputting a specific reason for failing
*
* @param {MarkdownString} message the String to output
*/
function fail(message: MarkdownString): void
declare function fail(message: MarkdownString): void

/**
* Highlights low-priority issues, does not fail the build
*
* @param {MarkdownString} message the String to output
*/
function warn(message: MarkdownString): void
declare function warn(message: MarkdownString): void

/**
* Puts a message inside the Danger table
*
* @param {MarkdownString} message the String to output
*/
function message(message: MarkdownString): void
declare function message(message: MarkdownString): void

/**
* Puts a message inside the Danger table
*
* @param {MarkdownString} message the String to output
*/
function markdown(message: MarkdownString): void
declare function markdown(message: MarkdownString): void

/** Typical console */
const console: Console
declare const console: Console

/**
* The Danger object to work with
*
*/
const danger: DangerDSLType
declare const danger: DangerDSLType
/**
* Results of a Danger run
*
*/
const results: DangerRuntimeContainer
}
declare const results: DangerRuntimeContainer
8 changes: 4 additions & 4 deletions source/dsl/GitDSL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ export interface GitDSL {
* Filepaths with changes relative to the git root
* @type {string[]}
*/
readonly modified_files: Readonly<Array<string>>
readonly modified_files: Array<string>

/**
* Newly created filepaths relative to the git root
* @type {string[]}
*/
readonly created_files: Readonly<Array<string>>
readonly created_files: Array<string>

/**
* Removed filepaths relative to the git root
* @type {string[]}
*/
readonly deleted_files: Readonly<Array<string>>
readonly deleted_files: Array<string>

/** Offers the diff for a specific file */
diffForFile(filename: string): string | null,
Expand Down Expand Up @@ -88,5 +88,5 @@ export interface GitDSL {
JSONDiffForFile(filename: string): Promise<any>,

/** The Git commit metadata */
readonly commits: Readonly<Array<GitCommit>>
readonly commits: Array<GitCommit>
}
1 change: 0 additions & 1 deletion source/runner/Executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ export class Executor {
const failureCount = [...fails, ...warnings].length
const messageCount = [...messages, ...markdowns].length

console.log(this)
this.d(results)

if (failureCount + messageCount === 0) {
Expand Down

0 comments on commit 873d4ca

Please sign in to comment.