Skip to content

Commit

Permalink
Merge pull request #356 from danger/schedule_types
Browse files Browse the repository at this point in the history
Update the scheduled types
  • Loading branch information
orta committed Aug 28, 2017
2 parents 2f1efb9 + 2669ac3 commit bc8dd7e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### 2.0.0-alpha.13

- Move back to the original URLs for diffs, instead of relying on PR metadata - orta
- Updates the types for `schedule` to be more accepting of what it actually takes - orta

### 2.0.0-alpha.12

Expand Down
2 changes: 1 addition & 1 deletion scripts/create-danger-dts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ const output = dts()
// This is so you can get it for this repo 👍
fs.writeFileSync("source/danger.d.ts", output)
fs.writeFileSync("distribution/danger.d.ts", output)
fs.writeFileSync("types/index.d.ts", output)
fs.writeFileSync("types/index.d.ts", "// TypeScript Version: 2.2\n" + output)

console.log("Awesome - shipped to source/danger.d.ts, distribution/danger.d.ts and types/index.d.ts")
3 changes: 3 additions & 0 deletions scripts/danger-dts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ declare module "danger" {
}
return newLine
}
if (line.includes("export type")) {
return line
}
if (line.includes("(")) {
return "function " + line.trim()
}
Expand Down
11 changes: 10 additions & 1 deletion source/danger.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,15 @@ declare module "danger" {
*/
message: string
}
/** A function with a callback function, which Danger wraps in a Promise */
type CallbackableFn = (callback: (done: any) => void) => void

/**
* Types of things which Danger will schedule for you, it's recommended that you
* just throw in an `async () => { [...] }` function. Can also handle a function
* that has a single 'done' arg.
*/
type Scheduleable = Promise<any> | Promise<void> | CallbackableFn
/**
* A Dangerfile is evaluated as a script, and so async code does not work
* out of the box. By using the `schedule` function you can now register a
Expand All @@ -607,7 +616,7 @@ declare module "danger" {
*
* @param {Function} asyncFunction the function to run asynchronously
*/
function schedule(asyncFunction: (p: Promise<any>) => void): void
function schedule(asyncFunction: Scheduleable): void

/**
* Fails a build, outputting a specific reason for failing.
Expand Down
14 changes: 12 additions & 2 deletions source/runner/Dangerfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ import { MarkdownString } from "../dsl/Aliases"

/// Start of Danger DSL definition

/** A function with a callback function, which Danger wraps in a Promise */
export type CallbackableFn = (callback: (done: any) => void) => void

/**
* Types of things which Danger will schedule for you, it's recommended that you
* just throw in an `async () => { [...] }` function. Can also handle a function
* that has a single 'done' arg.
*/
export type Scheduleable = Promise<any> | Promise<void> | CallbackableFn

export interface DangerContext {
/**
* A Dangerfile is evaluated as a script, and so async code does not work
Expand All @@ -14,7 +24,7 @@ export interface DangerContext {
*
* @param {Function} asyncFunction the function to run asynchronously
*/
schedule(asyncFunction: (p: Promise<any>) => void): void
schedule(asyncFunction: Scheduleable): void

/**
* Fails a build, outputting a specific reason for failing.
Expand Down Expand Up @@ -74,7 +84,7 @@ export function contextForDanger(dsl: DangerDSLType): DangerContext {
scheduled: [],
}

const schedule = (fn: Function) => results.scheduled.push(fn)
const schedule = (fn: any) => results.scheduled.push(fn)
const fail = (message: MarkdownString) => results.fails.push({ message })
const warn = (message: MarkdownString) => results.warnings.push({ message })
const message = (message: MarkdownString) => results.messages.push({ message })
Expand Down

0 comments on commit bc8dd7e

Please sign in to comment.