-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(.github/actions/semanetic-pr-footer-v1): add a list of known gitu…
…b actors to skip validation (#99)
- Loading branch information
Showing
9 changed files
with
195 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
name: 'Semantic PR Footer' | ||
description: 'Validate pull request footer against team policy' | ||
|
||
inputs: | ||
ignore_additional_actors: | ||
description: 'Comma delimited list of additional actors to ignore when validating pull request footer. List of actors already ignored: dependabot[bot], dependabot-preview[bot], github-actions[bot], axe-core, attest-team-ci' | ||
default: '' | ||
|
||
runs: | ||
using: 'node20' | ||
main: 'dist/index.js' | ||
main: 'dist/index.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import type core from '@actions/core'; | ||
import type github from '@actions/github'; | ||
export type Core = Pick<typeof core, 'setFailed' | 'info'>; | ||
export default function run(core: Core, payload?: typeof github.context.payload): void; | ||
import type { Core, GitHub } from './types'; | ||
export declare const ignoredActors: string[]; | ||
export default function run(core: Core, github: GitHub): void; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import github from '@actions/github'; | ||
import core from '@actions/core'; | ||
export type Core = Pick<typeof core, 'setFailed' | 'info' | 'getInput'>; | ||
export type GitHub = Pick<typeof github, 'context'>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,187 @@ | ||
import sinon from 'sinon'; | ||
import sinon from 'sinon' | ||
import { assert } from 'chai' | ||
import run, { type Core } from './run' | ||
import run, { ignoredActors } from './run' | ||
import type { Core, GitHub } from './types' | ||
|
||
describe('run', () => { | ||
afterEach(() => { | ||
sinon.restore() | ||
}) | ||
|
||
describe('github actors', () => { | ||
describe('given no actors', () => { | ||
it('uses default actor and skips validation if actor is in ignoredActors', () => { | ||
const core = { | ||
info: sinon.spy(), | ||
getInput: sinon.stub().returns('') | ||
} | ||
|
||
const github = { | ||
context: { | ||
actor: ignoredActors[0] | ||
} | ||
} | ||
|
||
run(core as unknown as Core, github as unknown as GitHub) | ||
|
||
assert.isTrue(core.info.calledOnce) | ||
assert.isTrue( | ||
core.info.calledWith( | ||
`Skipping PR footer validation for actor: ${ignoredActors[0]}` | ||
) | ||
) | ||
}) | ||
}) | ||
|
||
describe('given additional actors', () => { | ||
it('skips validation', () => { | ||
const core = { | ||
info: sinon.spy(), | ||
// give additional actors in different ways | ||
getInput: sinon.stub().returns('coffee[bot], , HaXor') | ||
} | ||
|
||
const github = { | ||
context: { | ||
actor: 'haxor' | ||
} | ||
} | ||
|
||
run(core as unknown as Core, github as unknown as GitHub) | ||
|
||
assert.isTrue(core.info.calledOnce) | ||
assert.isTrue( | ||
core.info.calledWith(`Skipping PR footer validation for actor: haxor`) | ||
) | ||
}) | ||
}) | ||
}) | ||
|
||
it('fails if pr does not have body', () => { | ||
const core = { | ||
setFailed: sinon.spy() | ||
setFailed: sinon.spy(), | ||
getInput: sinon.stub().returns('') | ||
} | ||
run(core as unknown as Core) | ||
|
||
const github = { | ||
context: { | ||
payload: {} | ||
} | ||
} | ||
|
||
run(core as unknown as Core, github as unknown as GitHub) | ||
|
||
assert.isTrue(core.setFailed.calledOnce) | ||
assert.isTrue(core.setFailed.calledWith('PR does not have a body')) | ||
}) | ||
|
||
it('fails if pr has empty body', () => { | ||
const core = { | ||
setFailed: sinon.spy() | ||
setFailed: sinon.spy(), | ||
getInput: sinon.stub().returns('') | ||
} | ||
const payload = { | ||
pull_request: { | ||
number: 1, | ||
body: '' | ||
const github = { | ||
context: { | ||
payload: { | ||
pull_request: { | ||
number: 1, | ||
body: '' | ||
} | ||
} | ||
} | ||
} | ||
run(core as unknown as Core, payload) | ||
run(core as unknown as Core, github as unknown as GitHub) | ||
|
||
assert.isTrue(core.setFailed.calledOnce) | ||
assert.isTrue(core.setFailed.calledWith('PR does not have a body')) | ||
}) | ||
|
||
it('logs the pr footer', () => { | ||
const core = { | ||
info: sinon.spy() | ||
info: sinon.spy(), | ||
getInput: sinon.stub().returns('') | ||
} | ||
const payload = { | ||
pull_request: { | ||
number: 1, | ||
body: 'This pr does some things.\n\ncloses: #1' | ||
const github = { | ||
context: { | ||
payload: { | ||
pull_request: { | ||
number: 1, | ||
body: 'This pr does some things.\n\ncloses: #1' | ||
} | ||
} | ||
} | ||
} | ||
run(core as unknown as Core, payload) | ||
run(core as unknown as Core, github as unknown as GitHub) | ||
|
||
assert.isTrue(core.info.calledWith('Validating PR footer: "closes: #1"')) | ||
}) | ||
|
||
it('passes if pr footer is valid', () => { | ||
const core = { | ||
info: sinon.spy() | ||
info: sinon.spy(), | ||
getInput: sinon.stub().returns('') | ||
} | ||
const payload = { | ||
pull_request: { | ||
number: 1, | ||
body: 'closes: #1' | ||
const github = { | ||
context: { | ||
payload: { | ||
pull_request: { | ||
number: 1, | ||
body: 'closes: #1' | ||
} | ||
} | ||
} | ||
} | ||
run(core as unknown as Core, payload) | ||
run(core as unknown as Core, github as unknown as GitHub) | ||
|
||
assert.isTrue(core.info.calledWith('Footer matches team policy')) | ||
}) | ||
|
||
it('fails if pr footer is not valid', () => { | ||
const core = { | ||
setFailed: sinon.spy(), | ||
getInput: sinon.stub().returns(''), | ||
info: sinon.spy() | ||
} | ||
const payload = { | ||
pull_request: { | ||
number: 1, | ||
body: 'nothing to close' | ||
const github = { | ||
context: { | ||
payload: { | ||
pull_request: { | ||
number: 1, | ||
body: 'nothing to close' | ||
} | ||
} | ||
} | ||
} | ||
run(core, payload) | ||
run(core as unknown as Core, github as unknown as GitHub) | ||
|
||
assert.isTrue(core.setFailed.calledOnce) | ||
assert.isTrue(core.setFailed.calledWith(sinon.match('PR footer does not close an issue'))) | ||
assert.isTrue( | ||
core.setFailed.calledWith( | ||
sinon.match('PR footer does not close an issue') | ||
) | ||
) | ||
}) | ||
|
||
it('fails if anything throws', () => { | ||
const core = { | ||
setFailed: sinon.spy(), | ||
info() { throw new Error('failure!') } | ||
getInput: sinon.stub().returns(''), | ||
info() { | ||
throw new Error('failure!') | ||
} | ||
} | ||
const payload = { | ||
pull_request: { | ||
number: 1, | ||
body: 'nothing to close' | ||
const github = { | ||
context: { | ||
payload: { | ||
pull_request: { | ||
number: 1, | ||
body: 'nothing to close' | ||
} | ||
} | ||
} | ||
} | ||
run(core, payload) | ||
run(core as unknown as Core, github as unknown as GitHub) | ||
|
||
assert.isTrue(core.setFailed.calledWith('failure!')) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import github from '@actions/github' | ||
import core from '@actions/core' | ||
|
||
export type Core = Pick<typeof core, 'setFailed' | 'info' | 'getInput'> | ||
export type GitHub = Pick<typeof github, 'context'> |