Skip to content

Commit 6df2310

Browse files
Merge pull request #4 from snakemode/main
check contents of hooks for data that might put errors in the console
2 parents 02e02e4 + ad11570 commit 6df2310

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

app/src/data/GitHubCommitHistory.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,53 @@ describe("GitHubCommitHistory", () => {
1919
expect(tree).toBeDefined();
2020
});
2121

22+
it("toTree, no commits in git hook, doesn't crash", () => {
23+
const hookData = gitHookWith();
24+
delete hookData.commits;
25+
26+
sut.push(hookData);
27+
28+
expect(sut.toNodesAndEdges()).toBeDefined();
29+
});
30+
31+
it("toTree, no files added in commit, doesn't crash", () => {
32+
const hookData = gitHookWith();
33+
delete hookData.commits[0].added;
34+
35+
sut.push(hookData);
36+
37+
expect(sut.toNodesAndEdges()).toBeDefined();
38+
});
39+
40+
it("toTree, no files modified in commit, doesn't crash", () => {
41+
const hookData = gitHookWith();
42+
delete hookData.commits[0].modified;
43+
44+
sut.push(hookData);
45+
46+
expect(sut.toNodesAndEdges()).toBeDefined();
47+
});
48+
49+
it("toTree, no files removed in commit, doesn't crash", () => {
50+
const hookData = gitHookWith();
51+
delete hookData.commits[0].removed;
52+
53+
sut.push(hookData);
54+
55+
expect(sut.toNodesAndEdges()).toBeDefined();
56+
});
57+
58+
it("toTree, no repository reference in commit, doesn't crash and skips commit", () => {
59+
const hookData = gitHookWith();
60+
delete hookData.repository;
61+
62+
sut.push(hookData);
63+
const { nodes } = sut.toNodesAndEdges();
64+
65+
expect(nodes).toBeDefined();
66+
expect([...nodes.values()].length).toBe(0);
67+
});
68+
2269
it("toTree, single file committed, node present", () => {
2370
sut.push(gitHookWith(["file.txt"]));
2471

app/src/data/GitHubCommitHistory.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,27 @@ export class GitHubCommitHistory {
2525
}
2626

2727
private processFilePaths(message: GitHubHook) {
28-
for (const commit of message.commits) {
28+
const commits = message.commits || [];
29+
30+
if (!message?.repository?.name) {
31+
return;
32+
}
33+
34+
for (const commit of commits) {
35+
commit.added = commit.added || [];
36+
commit.modified = commit.modified || [];
37+
commit.removed = commit.removed || [];
38+
2939
this.ensureRepositoryNodeExists(message.repository.name);
3040

3141
const touchedFiles = [...commit.added, ...commit.modified];
32-
const deletedFiles = commit.removed || [];
3342

3443
for (const file of touchedFiles) {
3544
const id = `${message.repository.name}/${file}`;
3645
this.createNodesForPath(id, message.repository.name);
3746
}
3847

39-
for (const file of deletedFiles) {
48+
for (const file of commit.removed) {
4049
this.deleteNodeAndEdges(`${message.repository.name}/${file}`);
4150
}
4251
}

0 commit comments

Comments
 (0)