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: outputs the error messages #194

Merged
merged 11 commits into from
Sep 26, 2022
Prev Previous commit
Next Next commit
fix: setOutput never getting called
  • Loading branch information
juninholiveira committed Jul 20, 2022
commit a0adbcd590aebb2315cb08c0f654cefc35a1a975
60 changes: 33 additions & 27 deletions src/validatePrTitle.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,29 @@ module.exports = async function validatePrTitle(
}

if (!result.type) {
errorMessage = `No release type found in pull request title "${prTitle}". Add a prefix to indicate what kind of release this pull request corresponds to. For reference, see https://www.conventionalcommits.org/\n\n${printAvailableTypes()}`;
throw new Error(errorMessage);
raiseError(
`No release type found in pull request title "${prTitle}". Add a prefix to indicate what kind of release this pull request corresponds to. For reference, see https://www.conventionalcommits.org/\n\n${printAvailableTypes()}`
);
}

if (!result.subject) {
errorMessage = `No subject found in pull request title "${prTitle}".`;
throw new Error(errorMessage);
raiseError(`No subject found in pull request title "${prTitle}".`);
}

if (!types.includes(result.type)) {
errorMessage = `Unknown release type "${
result.type
}" found in pull request title "${prTitle}". \n\n${printAvailableTypes()}`;
throw new Error(errorMessage);
raiseError(
`Unknown release type "${
result.type
}" found in pull request title "${prTitle}". \n\n${printAvailableTypes()}`
);
}

if (requireScope && !result.scope) {
errorMessage = `No scope found in pull request title "${prTitle}".`;
let message = `No scope found in pull request title "${prTitle}".`;
if (scopes) {
errorMessage += ` Use one of the available scopes: ${scopes.join(', ')}.`;
message += ` Use one of the available scopes: ${scopes.join(', ')}.`;
}
throw new Error(errorMessage);
raiseError(message);
}

const givenScopes = result.scope
Expand All @@ -85,24 +86,26 @@ module.exports = async function validatePrTitle(

const unknownScopes = givenScopes ? givenScopes.filter(isUnknownScope) : [];
if (scopes && unknownScopes.length > 0) {
errorMessage = `Unknown ${
unknownScopes.length > 1 ? 'scopes' : 'scope'
} "${unknownScopes.join(
','
)}" found in pull request title "${prTitle}". Use one of the available scopes: ${scopes.join(
', '
)}.`;
throw new Error(errorMessage);
raiseError(
`Unknown ${
unknownScopes.length > 1 ? 'scopes' : 'scope'
} "${unknownScopes.join(
','
)}" found in pull request title "${prTitle}". Use one of the available scopes: ${scopes.join(
', '
)}.`
);
}

const disallowedScopes = givenScopes
? givenScopes.filter(isDisallowedScope)
: [];
if (disallowScopes && disallowedScopes.length > 0) {
errorMessage = `Disallowed ${
disallowedScopes.length === 1 ? 'scope was' : 'scopes were'
} found: ${disallowScopes.join(', ')}`;
throw new Error(errorMessage);
raiseError(
`Disallowed ${
disallowedScopes.length === 1 ? 'scope was' : 'scopes were'
} found: ${disallowScopes.join(', ')}`
);
}

function throwSubjectPatternError(message) {
Expand All @@ -112,10 +115,7 @@ module.exports = async function validatePrTitle(
title: prTitle
});
}

errorMessage = message;

throw new Error(message);
raiseError(message);
}

if (subjectPattern) {
Expand All @@ -136,4 +136,10 @@ module.exports = async function validatePrTitle(
}

core.setOutput('error_message', errorMessage);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have some reasoning on why you picked error_message? Generally we use camelCase, so in doubt I'd go for that here too. It would also be good to do some research if there is some existing convention from other actions that we could align ourselves to.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I only based my choice on the Conventional Changelog Action, which uses snake_case for the outputs.

https://github.com/TriPSs/conventional-changelog-action

I can look into some more famous examples, but the final decision is yours xD what do you prefer? camelCase?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend using as it is in docs, upper case and underscore

https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, base it on docs seems like the best option imo

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


function raiseError(message) {
core.setOutput('errorMessage', message);

throw new Error(message);
}
};