diff --git a/README.ja.md b/README.ja.md
index e9962b6a..21371241 100644
--- a/README.ja.md
+++ b/README.ja.md
@@ -209,9 +209,9 @@ jobs:
|:---|:---|:---|
| diff | 差分のあるファイルの結果
`SET_ENV_NAME`(default: `GIT_DIFF`) が設定されている場合、その名前で環境変数が設定されます | `src/main.ts src/docs.md` |
| count | 差分のあるファイル数
`SET_ENV_NAME_COUNT`(default: `''`) が設定されている場合、その名前で環境変数が設定されます | `100` |
-| insertions | 追加された行数
`SET_ENV_NAME_INSERTIONS`(default: `''`) が設定されている場合、その名前で環境変数が設定されます | `100` |
-| deletions | 削除された行数
`SET_ENV_NAME_DELETIONS`(default: `''`) が設定されている場合、その名前で環境変数が設定されます | `100` |
-| lines | 追加された行数と削除された行数の和
`SET_ENV_NAME_LINES`(default: `''`) が設定されている場合、その名前で環境変数が設定されます | `200` |
+| insertions | 追加された行数 (`GET_FILE_DIFF` が `true` の場合のみ利用可能)
`SET_ENV_NAME_INSERTIONS`(default: `''`) が設定されている場合、その名前で環境変数が設定されます | `100` |
+| deletions | 削除された行数 (`GET_FILE_DIFF` が `true` の場合のみ利用可能)
`SET_ENV_NAME_DELETIONS`(default: `''`) が設定されている場合、その名前で環境変数が設定されます | `100` |
+| lines | 追加された行数と削除された行数の和 (`GET_FILE_DIFF` が `true` の場合のみ利用可能)
`SET_ENV_NAME_LINES`(default: `''`) が設定されている場合、その名前で環境変数が設定されます | `200` |
## Action イベント詳細
### 対象イベント
diff --git a/README.md b/README.md
index 699f9554..62073563 100644
--- a/README.md
+++ b/README.md
@@ -209,9 +209,9 @@ If there is no difference in the source code below, this workflow will skip the
|:---|:---|:---|
| diff | The results of diff file names.
If inputs `SET_ENV_NAME`(default: `GIT_DIFF`) is set, an environment variable is set with that name. | `src/main.ts src/docs.md` |
| count | The number of diff files.
If inputs `SET_ENV_NAME_COUNT`(default: `''`) is set, an environment variable is set with that name. | `100` |
-| insertions | The number of insertions lines.
If inputs `SET_ENV_NAME_INSERTIONS`(default: `''`) is set, an environment variable is set with that name. | `100` |
-| deletions | The number of deletions lines.
If inputs `SET_ENV_NAME_DELETIONS`(default: `''`) is set, an environment variable is set with that name. | `100` |
-| lines | The number of diff lines.
If inputs `SET_ENV_NAME_LINES`(default: `''`) is set, an environment variable is set with that name. | `200` |
+| insertions | The number of insertions lines. (Available only if `GET_FILE_DIFF` is `true`)
If inputs `SET_ENV_NAME_INSERTIONS`(default: `''`) is set, an environment variable is set with that name. | `100` |
+| deletions | The number of deletions lines. (Available only if `GET_FILE_DIFF` is `true`)
If inputs `SET_ENV_NAME_DELETIONS`(default: `''`) is set, an environment variable is set with that name. | `100` |
+| lines | The number of diff lines. (Available only if `GET_FILE_DIFF` is `true`)
If inputs `SET_ENV_NAME_LINES`(default: `''`) is set, an environment variable is set with that name. | `200` |
## Action event details
### Target events
diff --git a/action.yml b/action.yml
index 13d46109..b736e982 100644
--- a/action.yml
+++ b/action.yml
@@ -105,6 +105,9 @@ inputs:
description: Default value (count).
default: '0'
required: false
+ GET_FILE_DIFF:
+ description: Whether to get file diff.
+ required: false
INSERTIONS_DEFAULT:
description: Default value (insertions).
default: '0'
diff --git a/build.json b/build.json
index e4834ec8..17e971ec 100644
--- a/build.json
+++ b/build.json
@@ -1 +1 @@
-{"owner":"technote-space","repo":"get-diff-action","sha":"f6b329f6e5250a5fa5e599a7f9ef0ccec08a5ad4","ref":"refs/tags/test/v5.0.3.1651929536","tagName":"test/v5.0.3.1651929536","branch":"gh-actions","tags":["test/v5.0.3.1651929536","test/v5.0.3","test/v5.0","test/v5"],"updated_at":"2022-01-04T03:04:37.777Z"}
\ No newline at end of file
+{"owner":"technote-space","repo":"get-diff-action","sha":"FETCH_HEAD","ref":"refs/heads/master","tagName":"test/v5.0.3","branch":"gh-actions","tags":["test/v5.0.3","test/v5.0","test/v5"],"updated_at":"2022-01-05T07:28:59.463Z"}
\ No newline at end of file
diff --git a/dist/index.js b/dist/index.js
index 46566467..91dd2de0 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -90,18 +90,24 @@ const dumpDiffs = (diffs, logger) => {
};
exports.dumpDiffs = dumpDiffs;
const setResult = (diffs, skipped, logger) => {
- const insertions = (0, command_1.sumResults)(diffs, item => item.insertions);
- const deletions = (0, command_1.sumResults)(diffs, item => item.deletions);
+ // eslint-disable-next-line no-magic-numbers
+ const insertions = (0, command_1.sumResults)(diffs, item => 'insertions' in item ? item.insertions : 0);
+ // eslint-disable-next-line no-magic-numbers
+ const deletions = (0, command_1.sumResults)(diffs, item => 'deletions' in item ? item.deletions : 0);
const getValue = (setting) => skipped ? (0, core_1.getInput)(`${setting.name.toUpperCase()}_DEFAULT`) : `${setting.value()}`;
const settings = [
{ name: 'diff', value: () => (0, command_1.getDiffFiles)(diffs, false), envNameSuffix: '' },
{ name: 'filtered_diff', value: () => (0, command_1.getDiffFiles)(diffs, true) },
{ name: 'matched_files', value: () => (0, command_1.getMatchedFiles)(diffs) },
{ name: 'count', value: () => diffs.length },
- { name: 'insertions', value: () => insertions },
- { name: 'deletions', value: () => deletions },
- { name: 'lines', value: () => insertions + deletions },
];
+ if ((0, command_1.getFileDiffFlag)()) {
+ settings.push(...[
+ { name: 'insertions', value: () => insertions },
+ { name: 'deletions', value: () => deletions },
+ { name: 'lines', value: () => insertions + deletions },
+ ]);
+ }
logger.startProcess('Dump output');
settings.forEach(setting => {
var _a;
@@ -144,7 +150,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
-exports.sumResults = exports.getMatchedFiles = exports.getDiffFiles = exports.getGitDiff = exports.getFileDiff = void 0;
+exports.sumResults = exports.getMatchedFiles = exports.getDiffFiles = exports.getGitDiff = exports.getFileDiff = exports.getFileDiffFlag = void 0;
const path_1 = __nccwpck_require__(1017);
const core_1 = __nccwpck_require__(2186);
const multimatch_1 = __importDefault(__nccwpck_require__(5225));
@@ -159,6 +165,8 @@ const getFilter = () => (0, core_1.getInput)('DIFF_FILTER', { required: true });
const getRelativePath = () => (0, core_1.getInput)('RELATIVE');
const getOutputFormatType = () => getRawInput('FORMAT');
const escapeWhenJsonFormat = () => github_action_helper_1.Utils.getBoolValue(getRawInput('ESCAPE_JSON'));
+const getFileDiffFlag = () => github_action_helper_1.Utils.getBoolValue(getRawInput('GET_FILE_DIFF'));
+exports.getFileDiffFlag = getFileDiffFlag;
const getSeparator = () => getRawInput('SEPARATOR');
const getPatterns = () => github_action_helper_1.Utils.getArrayInput('PATTERNS', undefined, '');
const getFiles = () => github_action_helper_1.Utils.getArrayInput('FILES', undefined, '');
@@ -178,8 +186,11 @@ const getMatchOptions = () => ({
nonegate: github_action_helper_1.Utils.getBoolValue((0, core_1.getInput)('MINIMATCH_OPTION_NONEGATE')),
});
const getCompareRef = (ref) => github_action_helper_1.Utils.isRef(ref) ? github_action_helper_1.Utils.getLocalRefspec(ref, constant_1.REMOTE_NAME) : ref;
-const getFileDiff = (file, diffInfo, dot) => __awaiter(void 0, void 0, void 0, function* () {
+const getFileDiff = (file, diffInfo, dot, skip) => __awaiter(void 0, void 0, void 0, function* () {
var _a, _b;
+ if (skip) {
+ return undefined;
+ }
const stdout = (yield command.execAsync({
command: 'git diff',
args: [
@@ -229,6 +240,7 @@ const getGitDiff = (logger, context) => __awaiter(void 0, void 0, void 0, functi
const patterns = getPatterns();
const options = getMatchOptions();
const filter = getFilter();
+ const skipFileDiff = !(0, exports.getFileDiffFlag)();
return (yield github_action_helper_1.Utils.split((yield command.execAsync({
command: 'git diff',
args: [
@@ -248,7 +260,7 @@ const getGitDiff = (logger, context) => __awaiter(void 0, void 0, void 0, functi
isMatched: isMatched(item, patterns, options),
}))
.filter(item => item.filterIgnored || item.isMatched)
- .map((item) => __awaiter(void 0, void 0, void 0, function* () { return (Object.assign(Object.assign({}, item), yield (0, exports.getFileDiff)(item, diffInfo, dot))); }))
+ .map((item) => __awaiter(void 0, void 0, void 0, function* () { return (Object.assign(Object.assign({}, item), yield (0, exports.getFileDiff)(item, diffInfo, dot, skipFileDiff))); }))
.reduce((prev, item) => __awaiter(void 0, void 0, void 0, function* () {
const acc = yield prev;
return acc.concat(yield item);