Skip to content

Commit

Permalink
Revert "fix(revert): commisery-action support runs triggered by merge…
Browse files Browse the repository at this point in the history
…_group event (#288)"

This reverts commit 5b7c3a3.
  • Loading branch information
maikelvdh committed Jun 3, 2024
1 parent 5987f46 commit 3dce0ff
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 9 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ The `commisery-action` supports a configuration file, allowing you to:
Please refer to the [documentation](docs/configuration.md) for more details

### Conventional Commit message validation
The following example workflow will trigger on pull request creation/modification and verify
all associated commit messages.
The following example workflow will trigger on pull request creation/modification,
and on the merge queue run, and verify all associated commit messages.

```yaml
name: Commisery
on:
pull_request:
merge_group:

jobs:
commit-message:
Expand Down
9 changes: 8 additions & 1 deletion dist/bump/index.js

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

13 changes: 10 additions & 3 deletions dist/validate/index.js

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

11 changes: 8 additions & 3 deletions src/actions/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ import { getVersionBumpType } from "../bump";
import { ConventionalCommitMessage } from "../commit";

import { Configuration } from "../config";
import { getConfig, isPullRequestEvent, updateLabels } from "../github";
import {
getConfig,
isMergeGroupEvent,
isPullRequestEvent,
updateLabels
} from "../github";
import * as Label from "../label";
import { SemVerType } from "../semver";
import {
Expand Down Expand Up @@ -59,9 +64,9 @@ async function determineLabels(
*/
export async function run(): Promise<void> {
try {
if (!isPullRequestEvent()) {
if (!isPullRequestEvent() && !isMergeGroupEvent()) {
core.warning(
"Conventional Commit Message validation requires a workflow using the `pull_request` trigger!"
"Conventional Commit Message validation requires a workflow using the `pull_request` or `merge_group` trigger!"
);
return;
}
Expand Down
7 changes: 7 additions & 0 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ function githubCommitsAsICommits(
});
}

/**
* Returns whether we are running in context of a Merge Group event
*/
export function isMergeGroupEvent(): boolean {
return github.context.eventName === "merge_group";
}

/**
* Returns whether we are running in context of a Pull Request event
*/
Expand Down
61 changes: 61 additions & 0 deletions test/validate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,67 @@ describe("Warning cases", () => {
);
});

describe("Event type cases", () => {
const eventTypeCases = [
{
testDescription:
"should issue a warning if not `pull_request` nor `merge_group` trigger",
messages: [OK_1],
prTitle: "ci: proper title",
warningMessages: [
"Conventional Commit Message validation requires a workflow using the `pull_request` or `merge_group` trigger!",
],
isPullRequest: false,
isMergeGroup: false,
},
{
testDescription: "should not issue a warning if `pull_request` trigger",
messages: [OK_1],
prTitle: "ci: proper title",
warningMessages: [],
isPullRequest: true,
isMergeGroup: false,
},
{
testDescription: "should not issue a warning if `merge_group` trigger",
messages: [OK_1],
prTitle: "ci: proper title",
warningMessages: [],
isPullRequest: false,
isMergeGroup: true,
},
];
test.each(eventTypeCases)(
"$testDescription",
({
testDescription,
messages,
prTitle,
warningMessages,
isPullRequest,
isMergeGroup,
}) => {
jest.spyOn(github, "getCommitsInPR").mockResolvedValue(messages);
jest.spyOn(github, "getPullRequestTitle").mockResolvedValue(prTitle);
jest.spyOn(github, "isPullRequestEvent").mockReturnValue(isPullRequest);
jest.spyOn(github, "isMergeGroupEvent").mockReturnValue(isMergeGroup);

validate.run().then(() => {
if (!warningMessages.length) {
expect(core.warning).not.toHaveBeenCalled();
} else {
expect(core.warning).toHaveBeenCalled();
for (const msg of warningMessages) {
expect(core.warning).toHaveBeenCalledWith(
expect.stringContaining(msg)
);
}
}
});
}
);
});

describe("Error cases", () => {
const INVALID_CONVENTIONAL_COMMIT_MSG = "not valid Conventional Commits";
const PR_TITLE_NOT_COMPLIANT_MSG = "pull request title is not compliant";
Expand Down

0 comments on commit 3dce0ff

Please sign in to comment.