forked from OKEAMAH/bolt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchanges.js
More file actions
45 lines (36 loc) · 1.14 KB
/
changes.js
File metadata and controls
45 lines (36 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// @flow
import Repository from '../Repository';
import Package from '../Package';
import * as git from '../utils/git';
async function getLastVersionCommitForPackage(repo: Repository, pkg: Package) {
let cwd = repo.dir;
let filePath = pkg.config.filePath;
let commits = await git.getCommitsToFile(filePath, { cwd });
let matchedCommit = null;
for (let commit of commits) {
let parentCommit = await git.getCommitParent(commit.hash, { cwd });
if (!parentCommit) continue;
let before = await git.showFileAtCommit(filePath, parentCommit, {
cwd
});
let after = await git.showFileAtCommit(filePath, commit.hash, { cwd });
let jsonBefore = JSON.parse(before);
let jsonAfter = JSON.parse(after);
if (jsonAfter.version !== jsonBefore.version) {
matchedCommit = commit;
break;
}
}
return matchedCommit;
}
export async function getPackageVersionCommits(
repo: Repository,
packages: Array<Package>
) {
let versionCommits = new Map();
for (let pkg of packages) {
let commit = await getLastVersionCommitForPackage(repo, pkg);
versionCommits.set(pkg, commit);
}
return versionCommits;
}