Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support default export execution #240

Closed
orta opened this issue Apr 25, 2018 · 2 comments
Closed

Support default export execution #240

orta opened this issue Apr 25, 2018 · 2 comments

Comments

@orta
Copy link
Member

orta commented Apr 25, 2018

Right now we eval to run the dangerfile, and in most peril setups there's this faff:

const isJest = typeof jest !== "undefined"

// Stores the parameter in a closure that can be invoked in tests.
const storeRFC = (reason: string, closure: () => void | Promise<any>) =>
  // We return a closure here so that the (promise is resolved|closure is invoked)
  // during test time and not when we call rfc().
  () => (closure instanceof Promise ? closure : Promise.resolve(closure()))

// Either schedules the promise for execution via Danger, or invokes closure.
const runRFC = (reason: string, closure: () => void | Promise<any>) => schedule(closure)

const rfc: any = isJest ? storeRFC : runRFC

Which is needed to write tests, and to setup the schedule system which isn't needed in sandbox'd environments like peril-staging but we can verify and wrap it in a scheduler anyway on heroku instances

But what if instead you could provide a default export and that is evaluated or tested? Then you get logical async scope easily, and can test trivially too.

export default async () => {
  if(danger...
}

Might be even better for the DSL because the webhook could be passed in which fixes the awkward const gh = (danger.github as any) as Create too

export default async (status: Status) => {
  if(status.id...
}
@orta
Copy link
Member Author

orta commented Apr 25, 2018

Support is in Danger

@orta
Copy link
Member Author

orta commented Apr 27, 2018

And Peril support is in #247

@orta orta closed this as completed Apr 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant