Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update node, deps, testing (#229)
Browse files Browse the repository at this point in the history
jef authored Dec 11, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent e73526d commit 774e6b8
Showing 19 changed files with 32,004 additions and 11,931 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/
18 changes: 5 additions & 13 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -12,20 +12,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: "16"
- name: Setup build cache
uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: ${{ runner.os }}-node-
node-version-file: package.json
- name: Install dependencies
run: npm ci
- name: Compile TypeScript
run: npm run compile
- name: Run linter
run: npm run lint
- name: Run build
run: npm run build
5 changes: 4 additions & 1 deletion .github/workflows/pr-lint.yaml
Original file line number Diff line number Diff line change
@@ -5,13 +5,16 @@ on:
- opened
- edited
- reopened
- synchronize
jobs:
lint-pr:
name: Lint pull request title
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Lint pull request title
uses: ./
with:
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -9,9 +9,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup release please
uses: google-github-actions/release-please-action@v3
uses: googleapis/release-please-action@v4
id: release
with:
token: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ on:
- opened
- edited
- reopened
- synchronize
jobs:
lint-pr:
name: Lint pull request title
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
@@ -12,5 +12,5 @@ inputs:
required: true
description: Access token to the repository.
runs:
using: node16
using: node20
main: dist/index.js
32,347 changes: 26,905 additions & 5,442 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/sourcemap-register.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/src/__tests__/lint.test.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
561 changes: 561 additions & 0 deletions dist/src/github.d.ts

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions dist/src/lint.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export declare function getConventionalCommitTypes(): string;
export declare function lintPullRequest(title: string): Promise<boolean>;
export declare function lint(): Promise<void>;
4 changes: 4 additions & 0 deletions dist/src/main.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* Entrypoint for action.
*/
export declare function entrypoint(): Promise<void>;
8 changes: 8 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('ts-jest').JestConfigWithTsJest} **/
module.exports = {
testEnvironment: 'node',
transform: {
'^.+.tsx?$': ['ts-jest', {}],
},
testMatch: ['**/src/**/*.test.ts'],
};
10,882 changes: 4,472 additions & 6,410 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
@@ -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": [
@@ -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' +
@@ -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},
@@ -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
@@ -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
@@ -6,7 +6,11 @@
},
"include": [
"src/**/*.ts",
"src/**/*.d.ts",
"test/**/*.ts"
"src/**/*.d.ts"
],
"exclude": [
"node_modules",
"build",
"dist"
]
}

0 comments on commit 774e6b8

Please sign in to comment.