Skip to content

Commit

Permalink
closes #135 should help #133
Browse files Browse the repository at this point in the history
  • Loading branch information
JJ committed Apr 19, 2024
1 parent 9525092 commit c7be844
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 73 deletions.
68 changes: 35 additions & 33 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,41 +125,43 @@ function run() {
core.info("Checking diff contents");
const diffContains = core.getInput("diffContains");
const diffDoesNotContain = core.getInput("diffDoesNotContain");
const parsedDiff = yield getDiff(octokit, repository, pull_request);
core.setOutput("numberOfFiles", parsedDiff.length);
const filesChanged = +core.getInput("filesChanged");
if (filesChanged && parsedDiff.length != filesChanged) {
core.setFailed("You should change exactly " + filesChanged + " file(s)");
}
let changes = "";
let additions = 0;
parsedDiff.forEach(function (file) {
additions += file.additions;
file.chunks.forEach(function (chunk) {
chunk.changes.forEach(function (change) {
if (change.add) {
changes += change.content;
}
if (diffContains || diffDoesNotContain) {
const parsedDiff = yield getDiff(octokit, repository, pull_request);
core.setOutput("numberOfFiles", parsedDiff.length);
const filesChanged = +core.getInput("filesChanged");
if (filesChanged && parsedDiff.length != filesChanged) {
core.setFailed("You should change exactly " + filesChanged + " file(s)");
}
let changes = "";
let additions = 0;
parsedDiff.forEach(function (file) {
additions += file.additions;
file.chunks.forEach(function (chunk) {
chunk.changes.forEach(function (change) {
if (change.add) {
changes += change.content;
}
});
});
});
});
if (diffContains && !(0, utils_1.rexify)(diffContains).test(changes)) {
core.setFailed("The added code does not contain «" + diffContains + "»");
}
else {
core.setOutput("diff", changes);
}
if (diffDoesNotContain && (0, utils_1.rexify)(diffDoesNotContain).test(changes)) {
core.setFailed("The added code should not contain " + diffDoesNotContain);
}
core.info("Checking lines/files changed");
const linesChanged = +core.getInput("linesChanged");
if (linesChanged && additions != linesChanged) {
const this_msg = "You should change exactly " +
linesChanged +
" lines(s) and you have changed " +
additions;
core.setFailed(this_msg);
if (diffContains && !(0, utils_1.rexify)(diffContains).test(changes)) {
core.setFailed("The added code does not contain «" + diffContains + "»");
}
else {
core.setOutput("diff", changes);
}
if (diffDoesNotContain && (0, utils_1.rexify)(diffDoesNotContain).test(changes)) {
core.setFailed("The added code should not contain " + diffDoesNotContain);
}
core.info("Checking lines/files changed");
const linesChanged = +core.getInput("linesChanged");
if (linesChanged && additions != linesChanged) {
const this_msg = "You should change exactly " +
linesChanged +
" lines(s) and you have changed " +
additions;
core.setFailed(this_msg);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

80 changes: 41 additions & 39 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,49 +91,51 @@ async function run() {
const diffContains = core.getInput("diffContains");
const diffDoesNotContain = core.getInput("diffDoesNotContain");

const parsedDiff = await getDiff(octokit, repository, pull_request);
core.setOutput("numberOfFiles", parsedDiff.length);
const filesChanged = +core.getInput("filesChanged");
if (filesChanged && parsedDiff.length != filesChanged) {
core.setFailed(
"You should change exactly " + filesChanged + " file(s)"
);
}
if (diffContains || diffDoesNotContain) {
const parsedDiff = await getDiff(octokit, repository, pull_request);
core.setOutput("numberOfFiles", parsedDiff.length);
const filesChanged = +core.getInput("filesChanged");
if (filesChanged && parsedDiff.length != filesChanged) {
core.setFailed(
"You should change exactly " + filesChanged + " file(s)"
);
}

let changes = "";
let additions: number = 0;
parsedDiff.forEach(function (file) {
additions += file.additions;
file.chunks.forEach(function (chunk: parse.Chunk) {
chunk.changes.forEach(function (change: any) {
if (change.add) {
changes += change.content;
}
let changes = "";
let additions: number = 0;
parsedDiff.forEach(function (file) {
additions += file.additions;
file.chunks.forEach(function (chunk: parse.Chunk) {
chunk.changes.forEach(function (change: any) {
if (change.add) {
changes += change.content;
}
});
});
});
});
if (diffContains && !rexify(diffContains).test(changes)) {
core.setFailed(
"The added code does not contain «" + diffContains + "»"
);
} else {
core.setOutput("diff", changes);
}
if (diffDoesNotContain && rexify(diffDoesNotContain).test(changes)) {
core.setFailed(
"The added code should not contain " + diffDoesNotContain
);
}
if (diffContains && !rexify(diffContains).test(changes)) {
core.setFailed(
"The added code does not contain «" + diffContains + "»"
);
} else {
core.setOutput("diff", changes);
}
if (diffDoesNotContain && rexify(diffDoesNotContain).test(changes)) {
core.setFailed(
"The added code should not contain " + diffDoesNotContain
);
}

core.info("Checking lines/files changed");
const linesChanged = +core.getInput("linesChanged");
if (linesChanged && additions != linesChanged) {
const this_msg =
"You should change exactly " +
linesChanged +
" lines(s) and you have changed " +
additions;
core.setFailed(this_msg);
core.info("Checking lines/files changed");
const linesChanged = +core.getInput("linesChanged");
if (linesChanged && additions != linesChanged) {
const this_msg =
"You should change exactly " +
linesChanged +
" lines(s) and you have changed " +
additions;
core.setFailed(this_msg);
}
}
}
} catch (error: any) {
Expand Down

0 comments on commit c7be844

Please sign in to comment.