Skip to content

Commit

Permalink
feat: add support to detect changes for merge group event (#1404)
Browse files Browse the repository at this point in the history
Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
jackton1 and actions-user committed Jul 24, 2023
1 parent fc3c551 commit b8e577a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 31 deletions.
51 changes: 30 additions & 21 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

21 changes: 14 additions & 7 deletions src/commitSha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ const getCurrentSHA = async ({
})) === 0
) {
currentSha = github.context.payload.pull_request?.head?.sha
} else if (github.context.eventName === 'merge_group') {
currentSha = github.context.payload.merge_group?.head_sha
} else {
currentSha = await getHeadSha({cwd: workingDirectory})
}
Expand All @@ -78,7 +80,7 @@ export interface DiffResult {
initialCommit?: boolean
}

export const getSHAForPushEvent = async (
export const getSHAForNonPullRequestEvent = async (
inputs: Inputs,
env: Env,
workingDirectory: string,
Expand Down Expand Up @@ -197,12 +199,17 @@ export const getSHAForPushEvent = async (
previousSha = sha
targetBranch = tag
} else {
core.debug('Getting previous SHA for last remote commit...')
if (
github.context.payload.forced === 'false' ||
!github.context.payload.forced
) {
previousSha = github.context.payload.before
if (github.context.eventName === 'merge_group') {
core.debug('Getting previous SHA for merge group...')
previousSha = github.context.payload.merge_group?.base_sha
} else {
core.debug('Getting previous SHA for last remote commit...')
if (
github.context.payload.forced === 'false' ||
!github.context.payload.forced
) {
previousSha = github.context.payload.before
}
}

if (
Expand Down
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {setChangedFilesOutput} from './changedFilesOutput'
import {
DiffResult,
getSHAForPullRequestEvent,
getSHAForPushEvent
getSHAForNonPullRequestEvent
} from './commitSha'
import {Env, getEnv} from './env'
import {getInputs, Inputs} from './inputs'
Expand Down Expand Up @@ -130,7 +130,7 @@ const getChangedFilesFromLocalGit = async ({

if (!github.context.payload.pull_request?.base?.ref) {
core.info(`Running on a ${github.context.eventName || 'push'} event...`)
diffResult = await getSHAForPushEvent(
diffResult = await getSHAForNonPullRequestEvent(
inputs,
env,
workingDirectory,
Expand Down

0 comments on commit b8e577a

Please sign in to comment.