import transformCommit from "../transforms/commit" ; import { GitHubAPI } from "probot" ; import { Repository } from "../models/subscription" ; import GitHubClient from "../github/client/github-client" ; import { LoggerWithTarget } from "probot/lib/wrap-logger" ; import { getCommits as getCommitsQuery , getDefaultRef } from "../github/client/github-queries" ; export default async ( logger , github , _newGithub , _jiraHost , repository , cursor ? , perPage ? ) => { logger . info ( "Syncing commits: started" ) ; const data = ( await github . graphql ( getDefaultRef , { owner : repository . owner . login , repo : repository . name } ) as any ) ; const refName = ( data . repository . defaultBranchRef ) ? data . repository . defaultBranchRef . name : "master" ; let commitsData = { } ; const getCommits = async ( includeChangedFiles ) => { return github . graphql ( getCommitsQuery ( includeChangedFiles ) , { owner : repository . owner . login , repo : repository . name , per_page : perPage , cursor , default_ref : refName } ) ; } ; try { commitsData = await getCommits ( true ) ; } catch ( err ) { logger . info ( "retrying without changedFiles" ) ; const changedFilesErrors = err . errors ?. filter ( e => e . message ?. includes ( "The changedFiles count for this commit is unavailable" ) ) ; if ( changedFilesErrors . length ) { commitsData = await getCommits ( false ) ; } logger . info ( "successfully retried without changedFiles" ) ; } const edges = commitsData . repository ?. ref ?. target ?. history ?. edges ; const commits = edges ?. map ( ( { node : item } ) => item ) || [ ] ; logger . info ( "Syncing commits: finished" ) ; return { edges , jiraPayload : transformCommit ( { commits , repository } ) } ; } ;