From 70ab1b8aebc3d626c8e81bdd145e9f11f0021a67 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Tue, 29 Jan 2019 09:15:13 -0600 Subject: [PATCH] Skip deployments of updated github PR with only body changes --- .../handlers/githubPullRequestSynchronize.js | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/services/webhooks2tasks/src/handlers/githubPullRequestSynchronize.js b/services/webhooks2tasks/src/handlers/githubPullRequestSynchronize.js index b2ea91a25a..f78d202d80 100644 --- a/services/webhooks2tasks/src/handlers/githubPullRequestSynchronize.js +++ b/services/webhooks2tasks/src/handlers/githubPullRequestSynchronize.js @@ -1,11 +1,22 @@ // @flow +const R = require('ramda'); const { logger } = require('@lagoon/commons/src/local-logging'); const { sendToLagoonLogs } = require('@lagoon/commons/src/logs'); const { createDeployTask } = require('@lagoon/commons/src/tasks'); import type { WebhookRequestData, removeData, ChannelWrapper, Project } from '../types'; +const isEditAction = R.propEq('action', 'edited'); + +const onlyBodyChanges = R.pipe( + R.propOr({}, 'changes'), + R.keys, + R.equals(['body']), +); + +const skipRedeploy = R.and(isEditAction, onlyBodyChanges); + async function githubPullRequestSynchronize(webhook: WebhookRequestData, project: Project) { const { @@ -16,9 +27,12 @@ async function githubPullRequestSynchronize(webhook: WebhookRequestData, project body, } = webhook; - if (body.action == 'updated' && !('base' in body.changes)) { - // we are only interested in this webhook if the base had been updated, ofter updates like title or description don't need a redeploy - return + // Don't trigger deploy if only the PR body was edited. + if (skipRedeploy(body)) { + sendToLagoonLogs('info', project.name, uuid, `${webhooktype}:${event}:handledButNoTask`, {}, + `*[${project.name}]* PR ${body.number} updated. No deploy task created, reason: Only body changed` + ) + return; } const headBranchName = body.pull_request.head.ref