From 696259b0d30799b2c1a36105e4a133556736f9cb Mon Sep 17 00:00:00 2001 From: Brady Clifford <8923247+bradyclifford@users.noreply.github.com> Date: Wed, 14 Jun 2023 14:36:02 -0600 Subject: [PATCH 1/6] Add custom details and links Add custom details and links to custom event and push event. --- index.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 1ec1928..fe7dcc6 100644 --- a/index.js +++ b/index.js @@ -15,16 +15,16 @@ async function sendChangeEvent(changeEvent) { } } -function handleCustomEvent(summary, integrationKey) { +function handleCustomEvent(summary, customDetails, customLinks, integrationKey) { const changeEvent = { routing_key: integrationKey, payload: { summary: summary, source: 'GitHub', timestamp: (new Date()).toISOString(), - custom_details: {} + custom_details: customDetails }, - links: [ + links: customLinks || [ { href: `https://github.com/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`, text: "View run" @@ -35,7 +35,7 @@ function handleCustomEvent(summary, integrationKey) { sendChangeEvent(changeEvent); } -function handlePushEvent(data, integrationKey) { +function handlePushEvent(data, customDetails, customLinks, integrationKey) { const { ref, compare: compareHref, @@ -58,9 +58,9 @@ function handlePushEvent(data, integrationKey) { summary: `${senderLogin} pushed branch ${branch} from ${repoFullName}`.slice(0, 1024), source: 'GitHub', timestamp: (new Date()).toISOString(), - custom_details: {} + custom_details: customDetails }, - links: [ + links: customLinks || [ { href: compareHref, text: 'View on GitHub' @@ -148,11 +148,14 @@ try { const customEvent = core.getInput('custom-event'); const data = github.context.payload; + const customDetails = core.getInput('custom-details') ? JSON.parse(core.getInput('custom-details')) || {}; + const customLinks = core.getInput('custom-links') ? JSON.parse(core.getInput('custom-links')) : null; + if (typeof customEvent === 'string' && customEvent !== '') { // if custom event is described, prefer emitting custom event - handleCustomEvent(customEvent, integrationKey); + handleCustomEvent(customEvent, customDetails, customLinks, integrationKey); } else if (github.context.eventName === 'push') { - handlePushEvent(data, integrationKey); + handlePushEvent(data, customDetails, customLinks, integrationKey); } else if (github.context.eventName === 'pull_request' && data.action === 'closed' && data.pull_request.merged) { handlePullRequestEvent(data, integrationKey); } else { From c7cac6cb4c7d57134a2830b225c36d401dd64791 Mon Sep 17 00:00:00 2001 From: Brady Clifford <8923247+bradyclifford@users.noreply.github.com> Date: Wed, 14 Jun 2023 14:42:15 -0600 Subject: [PATCH 2/6] Update action.yml --- action.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/action.yml b/action.yml index dce2586..5ac1b7d 100644 --- a/action.yml +++ b/action.yml @@ -7,6 +7,12 @@ inputs: custom-event: description: 'Custom event summary. If provided the GitHub event type is ignored and the given summary used. A link to the run is included in the event.' required: false + custom-details: + description: 'Additional details about the event and affected system on a push or custom event.' + required: false + custom-links: + description: 'Links to be shown on the alert and/or corresponding incident.' + required: false runs: using: 'node12' main: 'index.js' From a413f7544b242a3ffa95754da9a13380d72b2149 Mon Sep 17 00:00:00 2001 From: Brady Clifford <8923247+bradyclifford@users.noreply.github.com> Date: Wed, 14 Jun 2023 14:45:25 -0600 Subject: [PATCH 3/6] Update action.yml --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 5ac1b7d..ce50b64 100644 --- a/action.yml +++ b/action.yml @@ -11,7 +11,7 @@ inputs: description: 'Additional details about the event and affected system on a push or custom event.' required: false custom-links: - description: 'Links to be shown on the alert and/or corresponding incident.' + description: 'Override default links to be shown on the alert and/or corresponding incident for a push or custom event.' required: false runs: using: 'node12' From ad746398f121d7559408f5a9f60f17bdfa22d131 Mon Sep 17 00:00:00 2001 From: Brady Clifford <8923247+bradyclifford@users.noreply.github.com> Date: Wed, 14 Jun 2023 14:48:31 -0600 Subject: [PATCH 4/6] Update README.md --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index 493ea85..87dcd4c 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,14 @@ workflow configuration. Custom event summary. If provided the GitHub event type is ignored and the given summary used. A link to the run is included in the change event. +### `custom-details` + +Additional details about the event and affected system on a push or custom event. + +### `custom-link` + +Override default links to be shown on the alert and/or corresponding incident for a push or custom event. + ## Example usage ```yaml @@ -77,9 +85,23 @@ jobs: # see https://github.com/marketplace/actions/workflow-status-action - uses: martialonline/workflow-status@v3 id: check + - name: Create a change event uses: PagerDuty/pagerduty-change-events-action@master with: integration-key: ${{ secrets.PAGERDUTY_CHANGE_INTEGRATION_KEY }} custom-event: Deployment ${{ steps.check.outputs.status }} + custom-details: | + { + "build_state": "passed", + "build_number": "220", + "run_time": "1236s" + } + custom-links: | + [ + { + "href": "https://dashboard.com/1234", + "text": "View Dashboard" + } + ] ``` From 8029916ebe9fbd3ff247a88c9ee36aa4906a63d7 Mon Sep 17 00:00:00 2001 From: Brady Clifford <8923247+bradyclifford@users.noreply.github.com> Date: Wed, 14 Jun 2023 14:52:18 -0600 Subject: [PATCH 5/6] Use GITHUB_SERVER_URL env. var --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index fe7dcc6..83c862f 100644 --- a/index.js +++ b/index.js @@ -26,7 +26,7 @@ function handleCustomEvent(summary, customDetails, customLinks, integrationKey) }, links: customLinks || [ { - href: `https://github.com/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`, + href: `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`, text: "View run" } ] From 073a0abb5abcaa2a70ee71affad199d5def8767e Mon Sep 17 00:00:00 2001 From: Brady Clifford <8923247+bradyclifford@users.noreply.github.com> Date: Wed, 14 Jun 2023 14:53:03 -0600 Subject: [PATCH 6/6] Update action to node16 --- action.yml | 2 +- index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index ce50b64..14ba472 100644 --- a/action.yml +++ b/action.yml @@ -14,5 +14,5 @@ inputs: description: 'Override default links to be shown on the alert and/or corresponding incident for a push or custom event.' required: false runs: - using: 'node12' + using: 'node16' main: 'index.js' diff --git a/index.js b/index.js index 83c862f..6c9875b 100644 --- a/index.js +++ b/index.js @@ -148,7 +148,7 @@ try { const customEvent = core.getInput('custom-event'); const data = github.context.payload; - const customDetails = core.getInput('custom-details') ? JSON.parse(core.getInput('custom-details')) || {}; + const customDetails = core.getInput('custom-details') ? JSON.parse(core.getInput('custom-details')) : {}; const customLinks = core.getInput('custom-links') ? JSON.parse(core.getInput('custom-links')) : null; if (typeof customEvent === 'string' && customEvent !== '') {