2021-06-09 20:31:45 +02:00
|
|
|
import simpleGit from 'simple-git'
|
|
|
|
|
|
|
|
import { Challenge } from './Challenge'
|
|
|
|
import { Solution } from './Solution'
|
|
|
|
|
|
|
|
const git = simpleGit()
|
|
|
|
|
|
|
|
const solutionsRegex = new RegExp(
|
2021-06-24 22:10:08 +02:00
|
|
|
/challenges\/[\s\S]*\/solutions\/(c|cpp|cs|dart|java|javascript|python|rust|typescript)\/[\s\S]*\/(solution|Solution).(c|cpp|cs|dart|java|js|py|rs|ts)/
|
2021-06-09 20:31:45 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
class GitAffected {
|
|
|
|
public async getAffectedSolutions (): Promise<Solution[]> {
|
|
|
|
await git.add('.')
|
|
|
|
const diff = await git.diff(['--name-only', '--staged'])
|
|
|
|
const affectedSolutionsPaths = diff.split('\n').filter((currentDiff) => {
|
|
|
|
return solutionsRegex.test(currentDiff)
|
|
|
|
})
|
|
|
|
return affectedSolutionsPaths.map((solution) => {
|
|
|
|
const [, challengeName, , programmingLanguageName, solutionName] =
|
|
|
|
solution.split('/')
|
|
|
|
return new Solution({
|
|
|
|
challenge: new Challenge({
|
|
|
|
name: challengeName
|
|
|
|
}),
|
|
|
|
name: solutionName,
|
|
|
|
programmingLanguageName
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const gitAffected = new GitAffected()
|