Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
"description": "Which GitHub installation number that is used when GitHub communication is initiated by Slack (since the installation is not known at that point in time)",
"required": false
},
"WEBHOOK_PATH": {
"description": "Path Probot listens on for GitHub webhook POSTs. Kept at '/' since that's what the GitHub App's webhook URL is already configured to.",
"required": false,
"value": "/"
},
"WEBHOOK_PROXY_URL": {
"description": "Proxy URL for webhooks (used by the dev PullRequests since each dyno cannot register with GitHubwhen it spins up",
"required": false
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"express": "^4.17.3",
"probot": "^13.4.7",
"probot-addon-settings": "github:probot/settings#v4.1.11",
"probot-config": "^1.1.0",
"sax": "^1.2.4",
"smee-client": "^1.2.2"
},
Expand Down
12 changes: 5 additions & 7 deletions src/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
// Based on github.com/mikz/probot-changelog#8441e070926211ad32b5f0430c9fe30a26f97c6d
// but modified in the following ways:
// - uses .github/config.yml (instead of .github/changelog.yml)
// - uses probot-config to allow inheriting the config from another repository
// - uses context.config() to allow inheriting the config from another repository
/* istanbul ignore file */
Comment thread
TylerZeroMaster marked this conversation as resolved.

import getConfig from 'probot-config'

const Status = Object.seal({
FAIL: Symbol('failure'),
SUCCESS: Symbol('success'),
Expand All @@ -24,7 +22,7 @@ export default (robot) => {
const itself = _ => _

async function changedFiles (context) {
const merged = context.octokit.pulls.listFiles.endpoint.merge(context.issue())
const merged = context.octokit.pulls.listFiles.endpoint.merge(context.pullRequest())
return context.octokit.paginate(merged, res => {
return res.data.map(itself)
})
Expand Down Expand Up @@ -96,14 +94,14 @@ export default (robot) => {
description: descriptionFor(status),
context: 'changelog'
})
return context.octokit.repos.createStatus(params)
return context.octokit.repos.createCommitStatus(params)
}

function log (context, object) {
const ctx = { event: context.event, action: context.payload.action }
const url = context.payload.pull_request.html_url

robot.log(ctx, context.issue({ url, ...object }))
robot.log.info(ctx, context.issue({ url, ...object }))
Comment thread
Copilot marked this conversation as resolved.
Outdated
}

async function hasLabel (context, label) {
Expand All @@ -122,7 +120,7 @@ export default (robot) => {
}

async function checkChangelog (context) {
const config = await getConfig(context, 'config.yml')
const config = await context.config('config.yml')

if (!config || !config.changelog) {
// don't try to run analysis without a config
Expand Down
70 changes: 70 additions & 0 deletions test/changelog.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import changelog from '../src/changelog.js'
import nock from 'nock'
import { Probot } from 'probot'

const repository = {
name: 'testrepo',
owner: {
login: 'testowner'
}
}

const pullRequestPayload = {
action: 'opened',
number: 7,
pull_request: {
number: 7,
html_url: 'https://github.com/testowner/testrepo/pull/7',
head: { sha: 'abc123' }
},
repository
}

describe('changelog', () => {
let app

beforeEach(() => {
nock.disableNetConnect()
app = new Probot({ appId: 1234, cert: 'test', githubToken: 'test' })
app.load(changelog)
})

afterEach(() => {
nock.cleanAll()
nock.enableNetConnect()
})

test('sets a success status when the PR includes a changelog entry', async () => {
nock('https://api.github.com')
.get('/repos/testowner/testrepo/contents/.github%2Fconfig.yml')
.reply(200, 'changelog: {}\n')

nock('https://api.github.com')
.get('/repos/testowner/testrepo/pulls/7/files')
.reply(200, [{ filename: 'CHANGELOG.md', status: 'modified' }])

nock('https://api.github.com')
.get('/repos/testowner/testrepo/issues/7/labels')
.reply(200, [])

const status = nock('https://api.github.com')
.post('/repos/testowner/testrepo/statuses/abc123', (body) => {
return body.state === 'success' && body.context === 'changelog'
})
.reply(201)

await app.receive({ name: 'pull_request', payload: pullRequestPayload })

expect(status.isDone()).toBe(true)
})

test('does nothing when there is no changelog config', async () => {
const config = nock('https://api.github.com')
.get('/repos/testowner/testrepo/contents/.github%2Fconfig.yml')
.reply(200, 'foo: bar\n')

await app.receive({ name: 'pull_request', payload: pullRequestPayload })

expect(config.isDone()).toBe(true)
})
})
15 changes: 1 addition & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3572,11 +3572,6 @@ deepmerge@4.3.1, deepmerge@^4.3.1:
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-4.3.1.tgz#44b5f2147cd3b00d4b56137685966f26fd25dd4a"
integrity sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A==

deepmerge@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-2.2.1.tgz#5d3ff22a01c00f645405a2fbc17d0778a1801170"
integrity sha512-R9hc1Xa/NOBi9WRVUWg19rl1UB7Tt4kuPd+thNJgFZoxXsTz7ncaPaeIm+40oSGuP33DfMb4sZt1QIGiJzC4EA==

deepmerge@^4.2.2:
version "4.2.2"
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-4.2.2.tgz#44d2ea3679b8f4d4ffba33f03d865fc1e7bf4955"
Expand Down Expand Up @@ -5639,7 +5634,7 @@ js-yaml@4.1.1:
dependencies:
argparse "^2.0.1"

js-yaml@^3.10.0, js-yaml@^3.13.1:
js-yaml@^3.13.1:
version "3.14.1"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.14.1.tgz#dae812fdb3825fa306609a8717383c50c36a0537"
integrity sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==
Expand Down Expand Up @@ -6768,14 +6763,6 @@ pretty-format@^29.7.0:
js-yaml "4.1.1"
probot "13.3.9"

probot-config@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/probot-config/-/probot-config-1.1.0.tgz#f8131c9f4f3e499e7bfc5c79284d012e4a8d2f25"
integrity sha512-FkTWzitDzkmGG3Pt7zLl2sTRpHuRbrUnKUbxs+7ruqoLv2dOEdc+sU1+uk0EP+fRR84sBkQfv8UjGASdeKT5lg==
dependencies:
deepmerge "^2.2.1"
js-yaml "^3.10.0"

probot@13.3.9:
version "13.3.9"
resolved "https://registry.yarnpkg.com/probot/-/probot-13.3.9.tgz#2b6680fda6886dacb2fa7b87de4b8312ad306b01"
Expand Down
Loading