Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/v14 #124

Merged
merged 20 commits into from
Feb 16, 2024
20 changes: 11 additions & 9 deletions .github/workflows/local-testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Dev check PR
uses: JJ/github-pr-contains-action@dev
uses: JJ/github-pr-contains-action@feat/v14
id: dev_check_pr
with:
github-token: ${{github.token}}
bodyContains: "[x]"
bodyDoesNotContain: "your|own"
diffDoesNotContain: "TODO"
linesChanged: 1
waivedUsers: "dependabot[bot]|JJ"
- name: Info PR
with:
FILES : ${{ steps.dev_check_pr.outputs.files }}
DIFF : ${{ steps.dev_check_pr.outputs.diff }}
env:
NUMBER_OF_FILES : ${{ steps.dev_check_pr.outputs.numberOfFiles }}
run: |
echo "::warning::We got files: $NUMBER_OF_FILES"
- name: Fail if too big
if: ${{ steps.dev_check_pr.outputs.numberOfFiles > 3 }}
env:
NUMBER_OF_FILES : ${{ steps.dev_check_pr.outputs.numberOfFiles }}
run: |
echo "We got files: $( echo -n $FILES | wc -l )"
echo "We got diff: $( echo -n $DIFF | wc -l ) lines in diff"
echo "::error::Too many files, there are $NUMBER_OF_FILES"
exit 1
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ inputs:
outputs:
diff:
description: "Lines added to the PR"
files:
description: "Files changed in the PR"
numberOfFiles:
description: "Number of files changed in the PR"

runs:
using: "node20"
Expand Down
8 changes: 4 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@ function run() {
core.info("Checking diff contents");
const diffContains = core.getInput("diffContains");
const diffDoesNotContain = core.getInput("diffDoesNotContain");
const files = yield getDiff(octokit, repository, pull_request);
core.setOutput("files", files);
const parsedDiff = yield getDiff(octokit, repository, pull_request);
core.setOutput("numberOfFiles", parsedDiff.length);
const filesChanged = +core.getInput("filesChanged");
if (filesChanged && files.length != filesChanged) {
if (filesChanged && parsedDiff.length != filesChanged) {
core.setFailed("You should change exactly " + filesChanged + " file(s)");
}
let changes = "";
let additions = 0;
files.forEach(function (file) {
parsedDiff.forEach(function (file) {
additions += file.additions;
file.chunks.forEach(function (chunk) {
chunk.changes.forEach(function (change) {
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

Empty file added kk
Empty file.
Empty file added kk2
Empty file.
Empty file added kk3
Empty file.
8 changes: 4 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,18 @@ async function run() {
const diffContains = core.getInput("diffContains");
const diffDoesNotContain = core.getInput("diffDoesNotContain");

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

let changes = "";
let additions: number = 0;
files.forEach(function (file) {
parsedDiff.forEach(function (file) {
additions += file.additions;
file.chunks.forEach(function (chunk: parse.Chunk) {
chunk.changes.forEach(function (change: any) {
Expand Down
Loading