import { Context } from "probot" ; import run from "./run" ; import match from "./helpers/match" ; export default async function toggle ( context ) { const { payload , github , log } = context ; const { head , body } = payload . pull_request ; const issue = context . issue ( { body } ) ; const deps = await match ( { ... issue , pull_number : issue . issue_number , } ) ; if ( deps . length > 0 ) { log ( "Adding label" ) ; await github . issues . addLabels ( { ... issue , labels : [ "dependent" ] } ) ; } else { try { log ( "No dependencies found, removing the label" ) ; await github . issues . removeLabel ( { ... issue , name : "dependent" } ) ; } catch ( err ) { log ( "The label doesn't exist. It's OK!" ) ; } } log ( "Running checks" ) ; await run ( github , issue , head . sha , deps ) ; }