Skip to content

Commit 03db417

Browse files
authored
Merge pull request #11 from githubocto/diffstat-fix
Add diffstat case for deleted file
2 parents 97f24e2 + f5a825d commit 03db417

File tree

4 files changed

+42
-17
lines changed

4 files changed

+42
-17
lines changed

dist/index.js

+16-5
Original file line numberDiff line numberDiff line change
@@ -357,20 +357,31 @@ async function getHeadSize(path) {
357357
}
358358
}
359359
async function diffSize(file) {
360-
const stat = fs_1.statSync(file.path);
361-
core.debug(`Calculating diff for ${JSON.stringify(file)}, with size ${stat.size}b`);
362360
switch (file.flag) {
363-
case 'M':
361+
case 'M': {
362+
const stat = fs_1.statSync(file.path);
363+
core.debug(`Calculating diff for ${JSON.stringify(file)}, with size ${stat.size}b`);
364364
// get old size and compare
365365
const oldSize = await getHeadSize(file.path);
366366
const delta = oldSize === undefined ? stat.size : stat.size - oldSize;
367367
core.debug(` ==> ${file.path} modified: old ${oldSize}, new ${stat.size}, delta ${delta}b `);
368368
return delta;
369-
case 'A':
369+
}
370+
case 'A': {
371+
const stat = fs_1.statSync(file.path);
372+
core.debug(`Calculating diff for ${JSON.stringify(file)}, with size ${stat.size}b`);
370373
core.debug(` ==> ${file.path} added: delta ${stat.size}b`);
371374
return stat.size;
372-
default:
375+
}
376+
case 'D': {
377+
const oldSize = await getHeadSize(file.path);
378+
const delta = oldSize === undefined ? 0 : oldSize;
379+
core.debug(` ==> ${file.path} deleted: delta ${delta}b`);
380+
return delta;
381+
}
382+
default: {
373383
throw new Error(`Encountered an unexpected file status in git: ${file.flag} ${file.path}`);
384+
}
374385
}
375386
}
376387
async function diff(filename) {

dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "flat",
3-
"version": "2.0.2",
3+
"version": "2.1.0",
44
"description": "The GitHub action which powers data fetching for Flat",
55
"main": "index.js",
66
"scripts": {

src/git.ts

+24-10
Original file line numberDiff line numberDiff line change
@@ -46,29 +46,42 @@ async function getHeadSize(path: string): Promise<number | undefined> {
4646
}
4747
}
4848

49-
async function diffSize(file: GitStatus): Promise<number> {
50-
const stat = statSync(file.path)
51-
core.debug(
52-
`Calculating diff for ${JSON.stringify(file)}, with size ${stat.size}b`
53-
)
54-
switch (file.flag) {
55-
case 'M':
49+
async function diffSize(file: GitStatus): Promise<number> {
50+
switch (file.flag) {
51+
case 'M': {
52+
const stat = statSync(file.path)
53+
core.debug(
54+
`Calculating diff for ${JSON.stringify(file)}, with size ${stat.size}b`
55+
)
56+
5657
// get old size and compare
5758
const oldSize = await getHeadSize(file.path)
5859
const delta = oldSize === undefined ? stat.size : stat.size - oldSize
5960
core.debug(
6061
` ==> ${file.path} modified: old ${oldSize}, new ${stat.size}, delta ${delta}b `
6162
)
6263
return delta
64+
}
65+
case 'A': {
66+
const stat = statSync(file.path)
67+
core.debug(
68+
`Calculating diff for ${JSON.stringify(file)}, with size ${stat.size}b`
69+
)
6370

64-
case 'A':
6571
core.debug(` ==> ${file.path} added: delta ${stat.size}b`)
6672
return stat.size
67-
68-
default:
73+
}
74+
case 'D': {
75+
const oldSize = await getHeadSize(file.path)
76+
const delta = oldSize === undefined ? 0 : oldSize
77+
core.debug(` ==> ${file.path} deleted: delta ${delta}b`)
78+
return delta
79+
}
80+
default: {
6981
throw new Error(
7082
`Encountered an unexpected file status in git: ${file.flag} ${file.path}`
7183
)
84+
}
7285
}
7386
}
7487

@@ -84,3 +97,4 @@ export async function diff(filename: string): Promise<number> {
8497
}
8598
return await diffSize(status)
8699
}
100+

0 commit comments

Comments
 (0)