Skip to content

Commit

Permalink
feat: update node, deps, testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jef committed Dec 11, 2024
1 parent e73526d commit b584084
Show file tree
Hide file tree
Showing 8 changed files with 4,549 additions and 6,505 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
build/
coverage/
dist/
node_modules/
node_modules/
4 changes: 2 additions & 2 deletions action.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Convetional Commits Pull Request
name: Conventional Commits Pull Request
description: Lints a pull request title based on Conventional Commits
branding:
icon: align-left
Expand All @@ -12,5 +12,5 @@ inputs:
required: true
description: Access token to the repository.
runs:
using: node16
using: node20
main: dist/index.js
7 changes: 7 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** @type {import('ts-jest').JestConfigWithTsJest} **/
module.exports = {
testEnvironment: 'node',
transform: {
'^.+.tsx?$': ['ts-jest', {}],
},
};
10,950 changes: 4,506 additions & 6,444 deletions package-lock.json

Large diffs are not rendered by default.

31 changes: 13 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
"version": "1.1.1",
"private": true,
"description": "Lints pull requests based on Conventional Commits and Jira tickets",
"main": "build/src/main.js",
"main": "./src/main.ts",
"scripts": {
"build": "npm run test && ncc build --source-map",
"compile": "tsc",
"clean": "gts clean",
"fix": "gts fix",
"lint": "gts lint",
"prestart": "npm run compile",
"start": "node ./build/src/main.js",
"pretest": "npm run compile",
"test": "c8 mocha build/test/**/test-*.js",
"start": "node --experimental-loader=node:ts ./src/main.js",
"test": "jest",
"posttest": "npm run lint"
},
"files": [
Expand All @@ -25,23 +23,20 @@
},
"dependencies": {
"@actions/core": "^1.11.1",
"@actions/github": "^5.1.1",
"@actions/github": "^6.0.0",
"conventional-commit-types": "^3.0.0"
},
"devDependencies": {
"@types/mocha": "^9.1.0",
"@types/node": "^17.0.22",
"@types/sinon": "^10.0.11",
"@vercel/ncc": "^0.33.3",
"c8": "^7.11.0",
"gts": "^3.1.0",
"mocha": "^9.2.2",
"prettier": "^2.6.0",
"sinon": "^13.0.1",
"ts-node": "^10.7.0",
"typescript": "^4.6.2"
"@types/jest": "^29.5.14",
"@types/node": "^22.10.2",
"@vercel/ncc": "^0.38.3",
"gts": "^6.0.2",
"jest": "^29.7.0",
"prettier": "^3.4.2",
"ts-jest": "^29.2.5",
"typescript": "^5.7.2"
},
"volta": {
"node": "16.14.2"
"node": "20.18.1"
}
}
25 changes: 4 additions & 21 deletions test/test-lint.ts → src/__tests__/lint.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import * as github from '../src/github';
import {SinonStub, stub} from 'sinon';
import {getConventionalCommitTypes, lintPullRequest} from '../src/lint';
import {deepStrictEqual} from 'assert';
import {getConventionalCommitTypes, lintPullRequest} from '../lint';

describe('getConvetionalCommitTypes tests', () => {
it('should return types', () => {
const types = getConventionalCommitTypes();

deepStrictEqual(
expect(
'- **feat**: A new feature\n' +
'- **fix**: A bug fix\n' +
'- **docs**: Documentation only changes\n' +
Expand All @@ -19,25 +16,11 @@ describe('getConvetionalCommitTypes tests', () => {
'- **ci**: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)\n' +
"- **chore**: Other changes that don't modify src or test files\n" +
'- **revert**: Reverts a previous commit',
types
);
).toBe(types);
});
});

describe('lintPullRequest tests', () => {
let createPrCommentStub: SinonStub;
let deletePrCommentStub: SinonStub;

before(() => {
createPrCommentStub = stub(github, 'createPrComment');
deletePrCommentStub = stub(github, 'deletePrComment');
});

after(() => {
createPrCommentStub.restore();
deletePrCommentStub.restore();
});

const tests = [
{args: 'feat: test', expected: true},
{args: 'feat(test): test', expected: true},
Expand All @@ -48,7 +31,7 @@ describe('lintPullRequest tests', () => {

tests.forEach(({args, expected}) => {
it(`should pass or fail linting ['${args}', '${expected}']`, async () => {
deepStrictEqual(await lintPullRequest(args), expected);
expect(await lintPullRequest(args)).toBe(expected);
});
});
});
27 changes: 10 additions & 17 deletions src/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,21 @@ export async function lintPullRequest(title: string) {
return new RegExp(`^${type}(\\(.*\\))?!?:.*$`);
});

if (!matches.some(regex => regex.test(title))) {
if (getInput('comment') === 'true') {
await createPrComment();
}

return false;
}

await deletePrComment();
return true;
return matches.some(regex => regex.test(title));
}

export async function lint() {
const pr = await getPullRequest();
let errorMessage: string;
if (!(await lintPullRequest(pr.title))) {
if (getInput('comment') !== 'true') {
errorMessage = `pr linting failed.\n\n${buildMessage()}`;
} else {
errorMessage = 'pr linting failed. see pull request conversation.';

const isPrTitleOk = await lintPullRequest(pr.title);

if (isPrTitleOk) {
await deletePrComment();
} else {
if (getInput('comment') === 'true') {
await createPrComment();
}

throw new Error(errorMessage);
throw new Error(`pr linting failed.\n\n${buildMessage()}`);
}
}
8 changes: 6 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
},
"include": [
"src/**/*.ts",
"src/**/*.d.ts",
"test/**/*.ts"
"src/**/*.d.ts"
],
"exclude": [
"node_modules",
"build",
"dist"
]
}

0 comments on commit b584084

Please sign in to comment.