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: add an option "validateSingleCommitMatchesPr" for #159 #160

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
validateSingleCommit: true
validateSingleCommitMatchesPr: true
kenji-miyake marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ The action works without configuration, however you can provide options for cust
# merge commit, and it's easy to commit this by mistake. Enable this option
# to also validate the commit message for one commit PRs.
validateSingleCommit: true
# When using "validateSingleCommit", even if you edit the PR title, the PR
# title is not used for the merge commit. Also, since it cannot detect an error
# as long as the commit message is semantic, it's easy to commit this by mistake.
# Enable this option to also validate if the PR title matches the commit title.
kenji-miyake marked this conversation as resolved.
Show resolved Hide resolved
validateSingleCommitMatchesPr: true
# If you use Github Enterprise, you can set this to the URL of your server
githubBaseUrl: https://github.myorg.com/api/v3
```
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ inputs:
validateSingleCommit:
description: "When using \"Squash and merge\" on a PR with only one commit, GitHub will suggest using that commit message instead of the PR title for the merge commit, and it's easy to commit this by mistake. Enable this option to also validate the commit message for one commit PRs."
required: false
validateSingleCommitMatchesPr:
description: "When using \"validateSingleCommit\", even if you edit the PR title, the PR title is not used for the merge commit. Also, since it cannot detect an error as long as the commit message is semantic, it's easy to commit this by mistake. Enable this option to also validate if the PR title matches the commit title."
required: false
githubBaseUrl:
description: "If you use Github Enterprise, you can set this to the URL of your server (e.g. https://github.myorg.com/api/v3)"
required: false
15 changes: 9 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = async function run() {
subjectPattern,
subjectPatternError,
validateSingleCommit,
validateSingleCommitMatchesPr,
githubBaseUrl
} = parseConfig();

Expand Down Expand Up @@ -98,12 +99,14 @@ module.exports = async function run() {
);
}

const commitTitle =
nonMergeCommits[0].commit.message.split('\n')[0];
if (commitTitle !== pullRequest.title) {
throw new Error(
`The pull request has only one (non-merge) commit and in this case Github will use it as the default commit message when merging. The pull request title doesn't match the commit though ("${pullRequest.title}" vs. "${commitTitle}"). Please update the pull request title accordingly to avoid surprises.`
);
if (validateSingleCommitMatchesPr) {
const commitTitle =
nonMergeCommits[0].commit.message.split('\n')[0];
if (commitTitle !== pullRequest.title) {
throw new Error(
`The pull request has only one (non-merge) commit and in this case Github will use it as the default commit message when merging. The pull request title doesn't match the commit though ("${pullRequest.title}" vs. "${commitTitle}"). Please update the pull request title accordingly to avoid surprises.`
);
}
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/parseConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ module.exports = function parseConfig() {
);
}

let validateSingleCommitMatchesPr;
if (process.env.INPUT_VALIDATESINGLECOMMITMATCHESPR) {
validateSingleCommitMatchesPr = ConfigParser.parseBoolean(
process.env.INPUT_VALIDATESINGLECOMMITMATCHESPR
);
}

let githubBaseUrl;
if (process.env.INPUT_GITHUBBASEURL) {
githubBaseUrl = ConfigParser.parseString(process.env.INPUT_GITHUBBASEURL);
Expand All @@ -53,6 +60,7 @@ module.exports = function parseConfig() {
subjectPattern,
subjectPatternError,
validateSingleCommit,
validateSingleCommitMatchesPr,
githubBaseUrl
};
};