Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/forms / danger / git.ts
Size: Mime:
import { exec } from 'child_process'
import { promisify } from 'util'

const asyncExec = promisify(exec)

/**
 * @example getChangedFiles().then(changed => changed.forEach(file => console.log(file)))
 */
export async function getChangedFiles(): Promise<string[]> {
  return new Promise(resolve => {
    asyncExec('git diff --name-only `git merge-base origin/master HEAD`')
      .then(result => {
        const output = result.stdout!.toString()
        const files = output.split('\n').filter(line => line !== '')
        const filesChangedList = files.filter(
          file => file.endsWith('.ts') || file.endsWith('.tsx')
        )
        resolve(filesChangedList)
      })
      .catch(exception => {
        console.error(exception)
        resolve([])
      })
  }) as Promise<string[]>
}