Skip to content

Commit

Permalink
v2.3.1 (#143)
Browse files Browse the repository at this point in the history
* Only run on a pull request payload (#141)
  • Loading branch information
dangoslen authored Aug 17, 2021
1 parent 1bfce1f commit d17ffc1
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# CHANGELOG
Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## [v2.3.1]
### Changed
- Only runs on `pull_request` and `pull_request_target` events. This is to address issue #140

## [v2.3.0]
### Dependencies
- Bumps `lodash` from 4.17.19 to 4.17.21
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The purpose of this action is to enforce a change to a ongoing changelog file. I
### Usage
To use, follow the typical GitHub Action `uses` syntax.

**Requires the common [Checkout Action](https://github.com/marketplace/actions/checkout) as shown below! The enforcement of change is done all using local `git` commands and requires the repository be checked out!**
Requires the common [Checkout Action](https://github.com/marketplace/actions/checkout) as shown below. The enforcement of change is done all using local `git` commands and requires the repository be checked out.

```yaml
name: "Pull Request Workflow"
Expand All @@ -30,6 +30,8 @@ jobs:
skipLabels: 'Skip-Changelog'
```
_:warning: The Changelog Enforcer is designed to be used with the `pull_request` or `pull_request_target` event types. Using this action on any other event type will result in a warning logged and the action succeeding (as to not block the rest of a workflow)._

### Inputs / Properties
Below are the properties allowed by the Changelog Enforcer. These properties are shipped with sane defaults for typical use, especially for changelogs inline with the [KeepAChangelog](Keepachangelog.org) format.

Expand Down
3 changes: 0 additions & 3 deletions __tests__/changelog-enforcer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ let infoSpy
let failureSpy
let execSpy
let outputSpy
let warnSpy

describe('the changelog-enforcer', () => {

afterAll(() => {
// Restore
jest.restoreAllMocks()
})

Expand All @@ -37,7 +35,6 @@ describe('the changelog-enforcer', () => {
})

infoSpy = jest.spyOn(core, 'info').mockImplementation(jest.fn())
warnSpy = jest.spyOn(core, 'warning').mockImplementation(jest.fn())
failureSpy = jest.spyOn(core, 'setFailed').mockImplementation(jest.fn())
outputSpy = jest.spyOn(core, 'setOutput').mockImplementation(jest.fn())
execSpy = jest.spyOn(exec, 'exec').mockImplementation((command, args, options) => { return 0 })
Expand Down
46 changes: 46 additions & 0 deletions __tests__/context-extractor.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const contextExtractor = require('../src/context-extractor')
const core = require('@actions/core')

const PULL = {
key: 'value'
}

const CONTEXT_PULL = {
eventName: 'pull_request',
payload: {
pull_request: PULL
}
}

const CONTEXT_PUSH = {
eventName: 'push',
payload: {}
}

let warnSpy;

describe('the context-extractor', () => {

afterAll(() => {
jest.restoreAllMocks()
})

beforeEach(() => {
jest.clearAllMocks()

warnSpy = jest.spyOn(core, 'warning').mockImplementation(jest.fn())
})

it('will return the pull request context', () => {
const pull = contextExtractor.getPullRequestContext(CONTEXT_PULL)

expect(pull).toBe(PULL)
})

it('will error if not pull request context', () => {
const cntxt = contextExtractor.getPullRequestContext(CONTEXT_PUSH)

expect(cntxt).toBe(undefined)
expect(warnSpy.mock.calls.length).toBe(1)
})
})
2 changes: 1 addition & 1 deletion coverage/badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 22 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7307,6 +7307,7 @@ const github = __nccwpck_require__(5438)
const exec = __nccwpck_require__(1514)
const versionExtractor = __nccwpck_require__(5568)
const labelExtractor = __nccwpck_require__(863)
const contextExtractor = __nccwpck_require__(6155)

// Input keys
const IN_CHANGELOG_PATH = 'changeLogPath'
Expand All @@ -7332,7 +7333,11 @@ module.exports.enforce = async function() {
core.info(`Expected Latest Version: ${expectedLatestVersion}`)
core.info(`Version Pattern: ${versionPattern}`)

const pullRequest = github.context.payload.pull_request
const pullRequest = contextExtractor.getPullRequestContext(github.context)
if (!pullRequest) {
return
}

const labelNames = pullRequest.labels.map(l => l.name)
const baseRef = pullRequest.base.ref

Expand Down Expand Up @@ -7431,6 +7436,22 @@ async function validateLatestVersion(expectedLatestVersion, versionPattern, chan



/***/ }),

/***/ 6155:
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {

const core = __nccwpck_require__(2186)

module.exports.getPullRequestContext = function (context) {
const pull_request = context.payload.pull_request
if (pull_request == undefined) {
core.warning(`ChangeLog enforcer only runs for pull_request and pull_request_target event types`)
return undefined
}
return context.payload.pull_request;
}

/***/ }),

/***/ 863:
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "changelog-enforcer",
"version": "2.3.0",
"version": "2.3.1",
"description": "Enforces that a changelog is kept up-to-date",
"main": "index.js",
"scripts": {
Expand Down
7 changes: 6 additions & 1 deletion src/changelog-enforcer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const github = require('@actions/github')
const exec = require('@actions/exec')
const versionExtractor = require('./version-extractor')
const labelExtractor = require('./label-extractor')
const contextExtractor = require('./context-extractor')

// Input keys
const IN_CHANGELOG_PATH = 'changeLogPath'
Expand All @@ -28,7 +29,11 @@ module.exports.enforce = async function() {
core.info(`Expected Latest Version: ${expectedLatestVersion}`)
core.info(`Version Pattern: ${versionPattern}`)

const pullRequest = github.context.payload.pull_request
const pullRequest = contextExtractor.getPullRequestContext(github.context)
if (!pullRequest) {
return
}

const labelNames = pullRequest.labels.map(l => l.name)
const baseRef = pullRequest.base.ref

Expand Down
10 changes: 10 additions & 0 deletions src/context-extractor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const core = require('@actions/core')

module.exports.getPullRequestContext = function (context) {
const pull_request = context.payload.pull_request
if (pull_request == undefined) {
core.warning(`ChangeLog enforcer only runs for pull_request and pull_request_target event types`)
return undefined
}
return context.payload.pull_request;
}

0 comments on commit d17ffc1

Please sign in to comment.