Skip to content

Commit

Permalink
Pass build
Browse files Browse the repository at this point in the history
Signed-off-by: Luiz Ferraz <luiz@lferraz.com>
  • Loading branch information
Fryuni committed Oct 31, 2023
1 parent d0104fd commit eae5dbc
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 98 deletions.
26 changes: 14 additions & 12 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32891,7 +32891,7 @@ function errorMessageOnNonVerb(firstWord, inputs) {
'Whether the word is in imperative mood is determined by ' +
'whitelisting. The general whitelist is available at ' +
'https://github.com/mristin/opinionated-commit-message/' +
'blob/master/src/mostFrequentEnglishVerbs.ts.'
'blob/master/src/mostFrequentEnglishVerbs.ts.',
];
if (!inputs.hasAdditionalVerbsInput) {
parts.push('You can whitelist additional verbs using ' +
Expand Down Expand Up @@ -33204,16 +33204,18 @@ function runWithExceptions() {
* Main function
*/
function run() {
runWithExceptions().catch((error) => {
if (error instanceof Error) {
core.error(error);
core.setFailed(error.message);
}
else {
const message = `Unexpected error value: ${error}`;
core.error(message);
core.setFailed(message);
}
return __awaiter(this, void 0, void 0, function* () {
return runWithExceptions().catch(error => {
if (error instanceof Error) {
core.error(error);
core.setFailed(error.message);
}
else {
const message = `Unexpected error value: ${error}`;
core.error(message);
core.setFailed(message);
}
});
});
}
exports.run = run;
Expand Down Expand Up @@ -34005,7 +34007,7 @@ exports.SET = new Set([
'upgrade',
'verbosify',
'whitelist',
'wrap'
'wrap',
]);


Expand Down
30 changes: 9 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"eslint-plugin-jest": "^27.6.0",
"jest": "^29.7.0",
"jest-circus": "^24.9.0",
"prettier": "^1.19.1",
"prettier": "^3.0.3",
"ts-jest": "^29.1.1",
"ts-node": "^8.10.2",
"typescript": "^5.2.2"
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/inspection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ it('reports no errors on any message when body check is disabled.', () => {
expect(inspection.check(message, inputCheckingBody)).not.toEqual([]);

const inputNotCheckingBody = input
.parseInputs('', '', '', '', '', '', 'true', '')
.parseInputs('', '', '', '', '', '', '','true')
.mustInputs();

expect(inspection.check(message, inputNotCheckingBody)).toEqual([]);
Expand Down
24 changes: 12 additions & 12 deletions src/__tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ it('ensures that the core mocks are reset between the tests.', () => {
expect(someInput).toEqual('');
});

it('considers additional verbs.', () => {
it('considers additional verbs.', async () => {
jest
.spyOn(commitMessages, 'retrieve')
.mockResolvedValue(['Table SomeClass\n\nThis is a dummy commit.']);
Expand All @@ -39,7 +39,7 @@ it('considers additional verbs.', () => {
name === 'additional-verbs' ? 'rewrap,table' : ''
);

mainImpl.run();
await mainImpl.run();

expect(core.setFailed).not.toHaveBeenCalled();
});
Expand Down Expand Up @@ -72,7 +72,7 @@ it('considers additional verbs from path.', () => {
expect(core.setFailed).not.toHaveBeenCalled();
});

it('considers allow-one-liners.', () => {
it('considers allow-one-liners.', async () => {
jest
.spyOn(commitMessages, 'retrieve')
.mockResolvedValue(['Do something']);
Expand All @@ -83,12 +83,12 @@ it('considers allow-one-liners.', () => {
.spyOn(core, 'getInput')
.mockImplementation(name => (name === 'allow-one-liners' ? 'true' : ''));

mainImpl.run();
await mainImpl.run();

expect(core.setFailed).not.toHaveBeenCalled();
});

it('considers skip-body-check.', () => {
it('considers skip-body-check.', async () => {
jest
.spyOn(commitMessages, 'retrieve')
.mockResolvedValue([
Expand All @@ -105,12 +105,12 @@ it('considers skip-body-check.', () => {
.spyOn(core, 'getInput')
.mockImplementation(name => (name === 'skip-body-check' ? 'true' : ''));

mainImpl.run();
await mainImpl.run();

expect(core.setFailed).not.toHaveBeenCalled();
});

it('formats properly no error message.', () => {
it('formats properly no error message.', async () => {
jest
.spyOn(commitMessages, 'retrieve')
.mockResolvedValue([
Expand All @@ -122,12 +122,12 @@ it('formats properly no error message.', () => {

jest.spyOn(core, 'setFailed');

mainImpl.run();
await mainImpl.run();

expect(core.setFailed).not.toHaveBeenCalled();
});

it('formats properly errors on a single message.', () => {
it('formats properly errors on a single message.', async () => {
jest
.spyOn(commitMessages, 'retrieve')
.mockResolvedValue([
Expand All @@ -136,7 +136,7 @@ it('formats properly errors on a single message.', () => {

jest.spyOn(core, 'setFailed');

mainImpl.run();
await mainImpl.run();

expect(core.setFailed).toHaveBeenCalledTimes(1);

Expand All @@ -152,7 +152,7 @@ it('formats properly errors on a single message.', () => {
);
});

it('formats properly errors on two messages.', () => {
it('formats properly errors on two messages.', async () => {
jest
.spyOn(commitMessages, 'retrieve')
.mockResolvedValue([
Expand All @@ -162,7 +162,7 @@ it('formats properly errors on two messages.', () => {

jest.spyOn(core, 'setFailed');

mainImpl.run();
await mainImpl.run();

expect(core.setFailed).toBeCalledTimes(1);
expect(core.setFailed).toHaveBeenCalledWith(
Expand Down
19 changes: 14 additions & 5 deletions src/commitMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import type {RestEndpointMethodTypes} from '@octokit/plugin-rest-endpoint-method
*
* @returns string[]
*/
export async function retrieve(inputs: Inputs, token?: string): Promise<string[]> {
export async function retrieve(
inputs: Inputs,
token?: string,
): Promise<string[]> {
const result: string[] = [];

switch (github.context.eventName) {
Expand Down Expand Up @@ -70,23 +73,29 @@ async function extractMessagesFromPullRequest(
return getCommits(pullRequest, token);
}

async function getCommits(pullRequest: PullRequest, token?: string): Promise<string[]> {
async function getCommits(
pullRequest: PullRequest,
token?: string,
): Promise<string[]> {
// Head repository where commits are registered. Value is null when the PR within a single repository,
// in which use base repository instead.
const repo = pullRequest.head.repo ?? pullRequest.base.repo;

if (repo.private && token === undefined) {
throw new Error('GitHub token is required to validate pull request commits on private repository.');
throw new Error(
'GitHub token is required to validate pull request commits on private repository.',
);
}

const octokit = github.getOctokit(token ?? '');

type Commits = RestEndpointMethodTypes['pulls']['listCommits']['response']['data'];
type Commits =
RestEndpointMethodTypes['pulls']['listCommits']['response']['data'];

const commits = await octokit.request<Commits>({
method: 'GET',
url: pullRequest.commits_url,
})
});

return commits.data.map(({commit}) => commit.message);
}
33 changes: 17 additions & 16 deletions src/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class Inputs {
maxBodyLineLength: number,
enforceSignOff: boolean,
validatePullRequestCommits: boolean,
skipBodyCheck: boolean
skipBodyCheck: boolean,
) {
this.hasAdditionalVerbsInput = hasAdditionalVerbsInput;
this.pathToAdditionalVerbs = pathToAdditionalVerbs;
Expand All @@ -50,7 +50,7 @@ export class MaybeInputs {

if (inputs !== null && error !== null) {
throw Error(
"Unexpected both 'inputs' and 'error' arguments to be given."
"Unexpected both 'inputs' and 'error' arguments to be given.",
);
}

Expand All @@ -62,7 +62,7 @@ export class MaybeInputs {
if (this.inputs === null) {
throw Error(
"The field 'inputs' is expected to be set, but it is null. " +
`The field 'error' is: ${this.error}`
`The field 'error' is: ${this.error}`,
);
}
return this.inputs;
Expand All @@ -77,7 +77,7 @@ export function parseInputs(
maxBodyLineLengthInput: string,
enforceSignOffInput: string,
validatePullRequestCommitsInput: string,
skipBodyCheckInput: string
skipBodyCheckInput: string,
): MaybeInputs {
const additionalVerbs = new Set<string>();

Expand All @@ -94,7 +94,7 @@ export function parseInputs(
return new MaybeInputs(
null,
'The file referenced by path-to-additional-verbs could ' +
`not be found: ${pathToAdditionalVerbsInput}`
`not be found: ${pathToAdditionalVerbsInput}`,
);
}

Expand All @@ -113,7 +113,7 @@ export function parseInputs(
return new MaybeInputs(
null,
'Unexpected value for allow-one-liners. ' +
`Expected either 'true' or 'false', got: ${allowOneLinersInput}`
`Expected either 'true' or 'false', got: ${allowOneLinersInput}`,
);
}

Expand All @@ -125,7 +125,7 @@ export function parseInputs(
return new MaybeInputs(
null,
'Unexpected value for max-subject-line-length. ' +
`Expected a number or nothing, got ${maxSubjectLengthInput}`
`Expected a number or nothing, got ${maxSubjectLengthInput}`,
);
}

Expand All @@ -137,7 +137,7 @@ export function parseInputs(
return new MaybeInputs(
null,
'Unexpected value for max-body-line-length. ' +
`Expected a number or nothing, got ${maxBodyLineLengthInput}`
`Expected a number or nothing, got ${maxBodyLineLengthInput}`,
);
}

Expand All @@ -149,19 +149,20 @@ export function parseInputs(
return new MaybeInputs(
null,
'Unexpected value for enforce-sign-off. ' +
`Expected either 'true' or 'false', got: ${enforceSignOffInput}`
`Expected either 'true' or 'false', got: ${enforceSignOffInput}`,
);
}

const validatePullRequestCommits: boolean | null = !validatePullRequestCommitsInput
? false
: parseBooleanFromString(validatePullRequestCommitsInput);
const validatePullRequestCommits: boolean | null =
!validatePullRequestCommitsInput
? false
: parseBooleanFromString(validatePullRequestCommitsInput);

if (validatePullRequestCommits === null) {
return new MaybeInputs(
null,
'Unexpected value for validate-pull-request-commits. ' +
`Expected either 'true' or 'false', got: ${validatePullRequestCommitsInput}`
`Expected either 'true' or 'false', got: ${validatePullRequestCommitsInput}`,
);
}

Expand All @@ -173,7 +174,7 @@ export function parseInputs(
return new MaybeInputs(
null,
'Unexpected value for skip-body-check. ' +
`Expected either 'true' or 'false', got: ${skipBodyCheckInput}`
`Expected either 'true' or 'false', got: ${skipBodyCheckInput}`,
);
}

Expand All @@ -187,9 +188,9 @@ export function parseInputs(
maxBodyLineLength,
enforceSignOff,
validatePullRequestCommits,
skipBodyCheck
skipBodyCheck,
),
null
null,
);
}

Expand Down
Loading

0 comments on commit eae5dbc

Please sign in to comment.