Change detection via git + rename githubToken to token (#9)

This commit is contained in:
Michal Dorner 2020-05-26 17:16:09 +02:00 committed by GitHub
parent a2e5f9f7bb
commit 1cbb925a17
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 1318 additions and 31 deletions

26
src/git.ts Normal file
View file

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