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

Merge pull request #15 from wagoid/fix/also-check-range-of-commits-for-push-events

fix: also check range of commits for push events
This commit is contained in:
Wagner Santos 2019-11-23 18:38:32 -03:00 committed by GitHub
commit 7637484297
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 1440 additions and 1420 deletions

View file

@ -9,6 +9,7 @@ jobs:
steps:
- uses: actions/checkout@v1
- run: sed -i -E "s/([']docker:.+)/Dockerfile/" ./action.yml
- run: echo -n "" > .dockerignore
- uses: ./
commitlint-with-yml-file:
runs-on: ubuntu-latest
@ -17,6 +18,7 @@ jobs:
steps:
- uses: actions/checkout@v1
- run: sed -i -E "s/([']docker:.+)/Dockerfile/" ./action.yml
- run: echo -n '' > .dockerignore
- uses: ./
with:
configFile: './.commitlintrc.yml'
@ -27,6 +29,7 @@ jobs:
steps:
- uses: actions/checkout@v1
- run: sed -i -E "s/([']docker:.+)/Dockerfile/" ./action.yml
- run: echo -n '' > .dockerignore
- uses: ./
with:
configFile: './.commitlintrc-with-lerna-scopes.yml'

View file

@ -9,4 +9,5 @@ jobs:
steps:
- uses: actions/checkout@v1
- run: sed -i -E "s/([']docker:.+)/Dockerfile/" ./action.yml
- run: echo -n '' > .dockerignore
- uses: ./

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",
"dependencies": {
"@actions/core": "1.1.1",
"@actions/exec": "1.0.1",
"@actions/github": "1.1.0",
"@commitlint/config-angular": "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 core = require('@actions/core')
const github = require('@actions/github')
const exec = require('@actions/exec')
const lint = require('@commitlint/lint')
const { format } = require('@commitlint/format')
const load = require('@commitlint/load')
@ -17,11 +16,34 @@ const configPath = resolve(
core.getInput('configFile'),
)
const getRangeFromPullRequest = async () => {
if (GITHUB_EVENT_NAME !== pullRequestEvent) return [null, GITHUB_SHA]
const { context: eventContext } = github
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 { owner, repo, number } = github.context.issue
const { owner, repo, number } = eventContext.issue
const { data: commits } = await octokit.pulls.listCommits({
owner,
repo,
@ -91,7 +113,7 @@ const exitWithMessage = message => error => {
}
const main = () =>
getRangeFromPullRequest()
getRangeForEvent()
.catch(
exitWithMessage("error trying to get list of pull request's commits"),
)