Skip to content

Commit

Permalink
fix: using compareCommits for push event commit query (#801)
Browse files Browse the repository at this point in the history
* fix: fixed logic in push event API request to only get commits from before to after event

* fix: getting events from first push using push event payload
  • Loading branch information
Brian-Triplett committed Sep 4, 2024
1 parent a2bc521 commit 47ff131
Show file tree
Hide file tree
Showing 3 changed files with 352 additions and 96 deletions.
30 changes: 24 additions & 6 deletions src/action.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const pullRequestTargetEvent = 'pull_request_target'
const pullRequestEvents = [pullRequestEvent, pullRequestTargetEvent]

const { GITHUB_EVENT_NAME } = process.env
const FIRST_COMMIT_SHA = '0000000000000000000000000000000000000000'

const configPath = resolve(process.env.GITHUB_WORKSPACE, getInput('configFile'))

Expand All @@ -22,13 +23,30 @@ const getCommitDepth = () => {
return Number.isNaN(commitDepth) ? null : Math.max(commitDepth, 0)
}

const getPushEventCommits = () => {
const mappedCommits = eventContext.payload.commits.map((commit) => ({
message: commit.message,
hash: commit.id,
}))
const getPushEventCommits = async () => {
const octokit = getOctokit(getInput('token'))
const { owner, repo } = eventContext.issue
const { before, after } = eventContext.payload

if (before === FIRST_COMMIT_SHA) {
return eventContext.payload.commits.map((commit) => ({
message: commit.message,
hash: commit.id,
}))
}

return mappedCommits
const { data: comparison } = await octokit.rest.repos.compareCommits({
owner,
repo,
head: after,
base: before,
per_page: 100,
})

return comparison.commits.map((commit) => ({
message: commit.commit.message,
hash: commit.sha,
}))
}

const getPullRequestEventCommits = async () => {
Expand Down
Loading

0 comments on commit 47ff131

Please sign in to comment.