2020-05-26 15:16:09 +00:00
|
|
|
import {exec} from '@actions/exec'
|
|
|
|
|
2020-06-15 19:49:10 +00:00
|
|
|
export async function fetchCommit(sha: string): Promise<void> {
|
|
|
|
const exitCode = await exec('git', ['fetch', '--depth=1', 'origin', sha])
|
2020-05-26 15:16:09 +00:00
|
|
|
if (exitCode !== 0) {
|
2020-06-15 19:49:10 +00:00
|
|
|
throw new Error(`Fetching commit ${sha} failed`)
|
2020-05-26 15:16:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-15 19:49:10 +00:00
|
|
|
export async function getChangedFiles(sha: string): Promise<string[]> {
|
2020-05-26 15:16:09 +00:00
|
|
|
let output = ''
|
2020-06-15 19:49:10 +00:00
|
|
|
const exitCode = await exec('git', ['diff-index', '--name-only', sha], {
|
2020-05-26 15:16:09 +00:00
|
|
|
listeners: {
|
|
|
|
stdout: (data: Buffer) => (output += data.toString())
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
if (exitCode !== 0) {
|
2020-06-15 19:49:10 +00:00
|
|
|
throw new Error(`Couldn't determine changed files`)
|
2020-05-26 15:16:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return output
|
|
|
|
.split('\n')
|
|
|
|
.map(s => s.trim())
|
|
|
|
.filter(s => s.length > 0)
|
|
|
|
}
|