From 3dce0ff04f0f39aa28b6693a358e92ef48323874 Mon Sep 17 00:00:00 2001 From: Maikel van den Hurk Date: Mon, 3 Jun 2024 08:49:49 +0200 Subject: [PATCH] Revert "fix(revert): commisery-action support runs triggered by merge_group event (#288)" This reverts commit 5b7c3a35a8f959135fc91f1765558f33de8ff2d2. --- README.md | 5 ++-- dist/bump/index.js | 9 +++++- dist/validate/index.js | 13 +++++++-- src/actions/validate.ts | 11 ++++++-- src/github.ts | 7 +++++ test/validate.test.ts | 61 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 97 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 3a8b1b35..8acd8eca 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/dist/bump/index.js b/dist/bump/index.js index 6259240c..87ddbaef 100644 --- a/dist/bump/index.js +++ b/dist/bump/index.js @@ -32985,7 +32985,7 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.createBranch = exports.getCommitsBetweenRefs = exports.currentHeadMatchesTag = exports.getContent = exports.updateLabels = exports.getAssociatedPullRequests = exports.getAllTags = exports.getShaForTag = exports.matchTagsToCommits = exports.getReleaseConfiguration = exports.getConfig = exports.createTag = exports.updateDraftRelease = exports.getRelease = exports.createRelease = exports.getPullRequest = exports.getCommitsInPR = exports.getPullRequestTitle = exports.getRunNumber = exports.getPullRequestId = exports.isPullRequestEvent = void 0; +exports.createBranch = exports.getCommitsBetweenRefs = exports.currentHeadMatchesTag = exports.getContent = exports.updateLabels = exports.getAssociatedPullRequests = exports.getAllTags = exports.getShaForTag = exports.matchTagsToCommits = exports.getReleaseConfiguration = exports.getConfig = exports.createTag = exports.updateDraftRelease = exports.getRelease = exports.createRelease = exports.getPullRequest = exports.getCommitsInPR = exports.getPullRequestTitle = exports.getRunNumber = exports.getPullRequestId = exports.isPullRequestEvent = exports.isMergeGroupEvent = void 0; const core = __importStar(__nccwpck_require__(2186)); const fs = __importStar(__nccwpck_require__(7147)); const github = __importStar(__nccwpck_require__(5438)); @@ -33010,6 +33010,13 @@ function githubCommitsAsICommits(commits) { }; }); } +/** + * Returns whether we are running in context of a Merge Group event + */ +function isMergeGroupEvent() { + return github.context.eventName === "merge_group"; +} +exports.isMergeGroupEvent = isMergeGroupEvent; /** * Returns whether we are running in context of a Pull Request event */ diff --git a/dist/validate/index.js b/dist/validate/index.js index cce64068..e4b78ce3 100644 --- a/dist/validate/index.js +++ b/dist/validate/index.js @@ -31149,8 +31149,8 @@ async function determineLabels(conventionalCommits, config) { */ async function run() { try { - if (!(0, github_1.isPullRequestEvent)()) { - core.warning("Conventional Commit Message validation requires a workflow using the `pull_request` trigger!"); + if (!(0, github_1.isPullRequestEvent)() && !(0, github_1.isMergeGroupEvent)()) { + core.warning("Conventional Commit Message validation requires a workflow using the `pull_request` or `merge_group` trigger!"); return; } await (0, github_1.getConfig)(core.getInput("config")); @@ -32943,7 +32943,7 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.createBranch = exports.getCommitsBetweenRefs = exports.currentHeadMatchesTag = exports.getContent = exports.updateLabels = exports.getAssociatedPullRequests = exports.getAllTags = exports.getShaForTag = exports.matchTagsToCommits = exports.getReleaseConfiguration = exports.getConfig = exports.createTag = exports.updateDraftRelease = exports.getRelease = exports.createRelease = exports.getPullRequest = exports.getCommitsInPR = exports.getPullRequestTitle = exports.getRunNumber = exports.getPullRequestId = exports.isPullRequestEvent = void 0; +exports.createBranch = exports.getCommitsBetweenRefs = exports.currentHeadMatchesTag = exports.getContent = exports.updateLabels = exports.getAssociatedPullRequests = exports.getAllTags = exports.getShaForTag = exports.matchTagsToCommits = exports.getReleaseConfiguration = exports.getConfig = exports.createTag = exports.updateDraftRelease = exports.getRelease = exports.createRelease = exports.getPullRequest = exports.getCommitsInPR = exports.getPullRequestTitle = exports.getRunNumber = exports.getPullRequestId = exports.isPullRequestEvent = exports.isMergeGroupEvent = void 0; const core = __importStar(__nccwpck_require__(2186)); const fs = __importStar(__nccwpck_require__(7147)); const github = __importStar(__nccwpck_require__(5438)); @@ -32968,6 +32968,13 @@ function githubCommitsAsICommits(commits) { }; }); } +/** + * Returns whether we are running in context of a Merge Group event + */ +function isMergeGroupEvent() { + return github.context.eventName === "merge_group"; +} +exports.isMergeGroupEvent = isMergeGroupEvent; /** * Returns whether we are running in context of a Pull Request event */ diff --git a/src/actions/validate.ts b/src/actions/validate.ts index df732938..9fdda248 100644 --- a/src/actions/validate.ts +++ b/src/actions/validate.ts @@ -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 { @@ -59,9 +64,9 @@ async function determineLabels( */ export async function run(): Promise { 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; } diff --git a/src/github.ts b/src/github.ts index c5acdc06..9d334c3c 100644 --- a/src/github.ts +++ b/src/github.ts @@ -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 */ diff --git a/test/validate.test.ts b/test/validate.test.ts index d7e307eb..b9394cca 100644 --- a/test/validate.test.ts +++ b/test/validate.test.ts @@ -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";