diff --git a/dist/index.js b/dist/index.js index 64ca1df..cc5e865 100644 --- a/dist/index.js +++ b/dist/index.js @@ -59,17 +59,14 @@ async function aiCheckDiffContext() { for (let key in files) { if (!files[key]) continue; - if (include_files.length > 0) { - if (!(0, utils_1.doesAnyPatternMatch)(include_files, files[key])) { - console.log("exclude(include):", files[key]); - continue; - } + console.log("check diff context:", files[key]); + if ((include_files.length > 0) && (!(0, utils_1.doesAnyPatternMatch)(include_files, files[key]))) { + console.log("exclude(include):", files[key]); + continue; } - if (exclude_files.length > 0) { - if ((0, utils_1.doesAnyPatternMatch)(exclude_files, files[key])) { - console.log("exclude(exclude):", files[key]); - continue; - } + else if ((exclude_files.length > 0) && ((0, utils_1.doesAnyPatternMatch)(exclude_files, files[key]))) { + console.log("exclude(exclude):", files[key]); + continue; } const fileDiffOutput = (0, node_child_process_1.execSync)(`git diff origin/${BASE_REF}...HEAD -- "${files[key]}"`, { encoding: 'utf-8' }); // ai generate diff --git a/src/index.ts b/src/index.ts index 10d6191..fb4064d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -63,18 +63,15 @@ async function aiCheckDiffContext() { let files = diffOutput.trim().split("\n"); for (let key in files) { if (!files[key]) continue; - if (include_files.length > 0) { - if (!doesAnyPatternMatch(include_files, files[key])) { - console.log("exclude(include):", files[key]) - continue; - } - } - if (exclude_files.length > 0) { - if (doesAnyPatternMatch(exclude_files, files[key])) { - console.log("exclude(exclude):", files[key]) - continue; - } + console.log("check diff context:", files[key]) + if ((include_files.length > 0) && (!doesAnyPatternMatch(include_files, files[key]))) { + console.log("exclude(include):", files[key]) + continue; + } else if ((exclude_files.length > 0) && (doesAnyPatternMatch(exclude_files, files[key]))) { + console.log("exclude(exclude):", files[key]) + continue; } + const fileDiffOutput = execSync(`git diff origin/${BASE_REF}...HEAD -- "${files[key]}"`, {encoding: 'utf-8'}); // ai generate try { diff --git a/test/split_message.test.ts b/test/split_message.test.ts index 988291c..e6417af 100644 --- a/test/split_message.test.ts +++ b/test/split_message.test.ts @@ -8,9 +8,23 @@ test2\\.js dist/.* `; - expect(doesAnyPatternMatch(split_message(testString),"readme.md")).toBe(true); - expect(doesAnyPatternMatch(split_message(testString),"dist/index.js")).toBe(true); - expect(doesAnyPatternMatch(split_message(testString),"dist/prompt.js")).toBe(true); - expect(doesAnyPatternMatch(split_message(testString),"src/index.js")).toBe(false); + expect(doesAnyPatternMatch(split_message(testString), "readme.md")).toBe(true); + expect(doesAnyPatternMatch(split_message(testString), "dist/index.js")).toBe(true); + expect(doesAnyPatternMatch(split_message(testString), "dist/prompt.js")).toBe(true); + expect(doesAnyPatternMatch(split_message(testString), "src/index.js")).toBe(false); + }); +}); + +describe('split_message', () => { + it('include readme.md', () => { + const testString = `^.+\\.md +test2\\.js +dist/.* + + `; + let file = "README.md"; + let include_files = split_message(testString); + console.log("check diff context:", file) + expect(((include_files.length > 0) && (doesAnyPatternMatch(include_files, file)))).toBe(true); }); });