5
0
Fork 0
mirror of https://github.com/wagoid/commitlint-github-action.git synced 2025-11-07 16:06:56 +00:00

fix: also check range of commits for push events

This covers the case when sending multiple commits together in ome push.
This commit is contained in:
Wagner Santos 2019-11-23 18:22:00 -03:00
parent dbcd202509
commit aa3e7ae63b
3 changed files with 1436 additions and 1420 deletions

2823
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -16,7 +16,6 @@
"homepage": "https://github.com/wagoid/commitlint-github-action", "homepage": "https://github.com/wagoid/commitlint-github-action",
"dependencies": { "dependencies": {
"@actions/core": "1.1.1", "@actions/core": "1.1.1",
"@actions/exec": "1.0.1",
"@actions/github": "1.1.0", "@actions/github": "1.1.0",
"@commitlint/config-angular": "8.2.0", "@commitlint/config-angular": "8.2.0",
"@commitlint/config-conventional": "8.2.0", "@commitlint/config-conventional": "8.2.0",

32
run.js
View file

@ -2,7 +2,6 @@ const { existsSync } = require('fs')
const { resolve } = require('path') const { resolve } = require('path')
const core = require('@actions/core') const core = require('@actions/core')
const github = require('@actions/github') const github = require('@actions/github')
const exec = require('@actions/exec')
const lint = require('@commitlint/lint') const lint = require('@commitlint/lint')
const { format } = require('@commitlint/format') const { format } = require('@commitlint/format')
const load = require('@commitlint/load') const load = require('@commitlint/load')
@ -17,11 +16,34 @@ const configPath = resolve(
core.getInput('configFile'), core.getInput('configFile'),
) )
const getRangeFromPullRequest = async () => { const { context: eventContext } = github
if (GITHUB_EVENT_NAME !== pullRequestEvent) return [null, GITHUB_SHA]
const gitEmptySha = '0000000000000000000000000000000000000000'
const getRangeForPushEvent = () => {
let from = eventContext.payload.before
const to = GITHUB_SHA
if (eventContext.payload.forced) {
// When a commit is forced, "before" field from the push event data may point to a commit that doesn't exist
console.warn(
'Commit was forced, checking only the latest commit from push instead of a range of commit messages',
)
from = null
}
if (from === gitEmptySha) {
from = null
}
return [from, to]
}
const getRangeForEvent = async () => {
if (GITHUB_EVENT_NAME !== pullRequestEvent) return getRangeForPushEvent()
const octokit = new github.GitHub(GITHUB_TOKEN) const octokit = new github.GitHub(GITHUB_TOKEN)
const { owner, repo, number } = github.context.issue const { owner, repo, number } = eventContext.issue
const { data: commits } = await octokit.pulls.listCommits({ const { data: commits } = await octokit.pulls.listCommits({
owner, owner,
repo, repo,
@ -91,7 +113,7 @@ const exitWithMessage = message => error => {
} }
const main = () => const main = () =>
getRangeFromPullRequest() getRangeForEvent()
.catch( .catch(
exitWithMessage("error trying to get list of pull request's commits"), exitWithMessage("error trying to get list of pull request's commits"),
) )