Skip to content

Commit b584084

Browse files
committed
feat: update node, deps, testing
1 parent e73526d commit b584084

File tree

8 files changed

+4549
-6505
lines changed

8 files changed

+4549
-6505
lines changed

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
build/
22
coverage/
33
dist/
4-
node_modules/
4+
node_modules/

action.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Convetional Commits Pull Request
1+
name: Conventional Commits Pull Request
22
description: Lints a pull request title based on Conventional Commits
33
branding:
44
icon: align-left
@@ -12,5 +12,5 @@ inputs:
1212
required: true
1313
description: Access token to the repository.
1414
runs:
15-
using: node16
15+
using: node20
1616
main: dist/index.js

jest.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/** @type {import('ts-jest').JestConfigWithTsJest} **/
2+
module.exports = {
3+
testEnvironment: 'node',
4+
transform: {
5+
'^.+.tsx?$': ['ts-jest', {}],
6+
},
7+
};

package-lock.json

Lines changed: 4506 additions & 6444 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33
"version": "1.1.1",
44
"private": true,
55
"description": "Lints pull requests based on Conventional Commits and Jira tickets",
6-
"main": "build/src/main.js",
6+
"main": "./src/main.ts",
77
"scripts": {
88
"build": "npm run test && ncc build --source-map",
99
"compile": "tsc",
1010
"clean": "gts clean",
1111
"fix": "gts fix",
1212
"lint": "gts lint",
13-
"prestart": "npm run compile",
14-
"start": "node ./build/src/main.js",
15-
"pretest": "npm run compile",
16-
"test": "c8 mocha build/test/**/test-*.js",
13+
"start": "node --experimental-loader=node:ts ./src/main.js",
14+
"test": "jest",
1715
"posttest": "npm run lint"
1816
},
1917
"files": [
@@ -25,23 +23,20 @@
2523
},
2624
"dependencies": {
2725
"@actions/core": "^1.11.1",
28-
"@actions/github": "^5.1.1",
26+
"@actions/github": "^6.0.0",
2927
"conventional-commit-types": "^3.0.0"
3028
},
3129
"devDependencies": {
32-
"@types/mocha": "^9.1.0",
33-
"@types/node": "^17.0.22",
34-
"@types/sinon": "^10.0.11",
35-
"@vercel/ncc": "^0.33.3",
36-
"c8": "^7.11.0",
37-
"gts": "^3.1.0",
38-
"mocha": "^9.2.2",
39-
"prettier": "^2.6.0",
40-
"sinon": "^13.0.1",
41-
"ts-node": "^10.7.0",
42-
"typescript": "^4.6.2"
30+
"@types/jest": "^29.5.14",
31+
"@types/node": "^22.10.2",
32+
"@vercel/ncc": "^0.38.3",
33+
"gts": "^6.0.2",
34+
"jest": "^29.7.0",
35+
"prettier": "^3.4.2",
36+
"ts-jest": "^29.2.5",
37+
"typescript": "^5.7.2"
4338
},
4439
"volta": {
45-
"node": "16.14.2"
40+
"node": "20.18.1"
4641
}
4742
}
Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
import * as github from '../src/github';
2-
import {SinonStub, stub} from 'sinon';
3-
import {getConventionalCommitTypes, lintPullRequest} from '../src/lint';
4-
import {deepStrictEqual} from 'assert';
1+
import {getConventionalCommitTypes, lintPullRequest} from '../lint';
52

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

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

2723
describe('lintPullRequest tests', () => {
28-
let createPrCommentStub: SinonStub;
29-
let deletePrCommentStub: SinonStub;
30-
31-
before(() => {
32-
createPrCommentStub = stub(github, 'createPrComment');
33-
deletePrCommentStub = stub(github, 'deletePrComment');
34-
});
35-
36-
after(() => {
37-
createPrCommentStub.restore();
38-
deletePrCommentStub.restore();
39-
});
40-
4124
const tests = [
4225
{args: 'feat: test', expected: true},
4326
{args: 'feat(test): test', expected: true},
@@ -48,7 +31,7 @@ describe('lintPullRequest tests', () => {
4831

4932
tests.forEach(({args, expected}) => {
5033
it(`should pass or fail linting ['${args}', '${expected}']`, async () => {
51-
deepStrictEqual(await lintPullRequest(args), expected);
34+
expect(await lintPullRequest(args)).toBe(expected);
5235
});
5336
});
5437
});

src/lint.ts

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,21 @@ export async function lintPullRequest(title: string) {
2424
return new RegExp(`^${type}(\\(.*\\))?!?:.*$`);
2525
});
2626

27-
if (!matches.some(regex => regex.test(title))) {
28-
if (getInput('comment') === 'true') {
29-
await createPrComment();
30-
}
31-
32-
return false;
33-
}
34-
35-
await deletePrComment();
36-
return true;
27+
return matches.some(regex => regex.test(title));
3728
}
3829

3930
export async function lint() {
4031
const pr = await getPullRequest();
41-
let errorMessage: string;
42-
if (!(await lintPullRequest(pr.title))) {
43-
if (getInput('comment') !== 'true') {
44-
errorMessage = `pr linting failed.\n\n${buildMessage()}`;
45-
} else {
46-
errorMessage = 'pr linting failed. see pull request conversation.';
32+
33+
const isPrTitleOk = await lintPullRequest(pr.title);
34+
35+
if (isPrTitleOk) {
36+
await deletePrComment();
37+
} else {
38+
if (getInput('comment') === 'true') {
39+
await createPrComment();
4740
}
4841

49-
throw new Error(errorMessage);
42+
throw new Error(`pr linting failed.\n\n${buildMessage()}`);
5043
}
5144
}

tsconfig.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
},
77
"include": [
88
"src/**/*.ts",
9-
"src/**/*.d.ts",
10-
"test/**/*.ts"
9+
"src/**/*.d.ts"
10+
],
11+
"exclude": [
12+
"node_modules",
13+
"build",
14+
"dist"
1115
]
1216
}

0 commit comments

Comments
 (0)