From 025b3d7765fd6c26902717e3e186e3881d59e596 Mon Sep 17 00:00:00 2001 From: Jarred Wilson Date: Mon, 6 Jan 2025 15:46:41 +0000 Subject: [PATCH] feat: add severity input - remove critical references in docs - add input to action --- README.md | 2 +- action.yml | 5 ++++- index.js | 3 ++- lib/prepare-alert.js | 6 ++++-- package.json | 2 +- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 80ad0ad..ce4bd17 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # PagerDuty Alert GitHub Action -Sends a critical PagerDuty alert, e.g. on action failure. Optionally, resolves on success. +Sends a PagerDuty alert, e.g. on action failure. Optionally, resolves on success. ## Prerequisites diff --git a/action.yml b/action.yml index b9bd076..cb09d63 100644 --- a/action.yml +++ b/action.yml @@ -1,5 +1,5 @@ name: 'PagerDuty Alert' -description: 'GitHub Action to send a critical PagerDuty alert, e.g. on action failure.' +description: 'GitHub Action to send a PagerDuty alert, e.g. on action failure.' inputs: pagerduty-integration-key: description: 'The integration key for your PagerDuty service' @@ -13,6 +13,9 @@ inputs: resolve: description: 'If set to true, will resolve any alert with the same pagerduty-dedup-key (if such an alert exists).' required: false + severity: + description: 'Notification severity label.' + required: false runs: using: 'node20' main: 'index.js' diff --git a/index.js b/index.js index 5922d17..0214159 100644 --- a/index.js +++ b/index.js @@ -7,8 +7,9 @@ try { const pagerDutyDedupKey = core.getInput('pagerduty-dedup-key'); // Optional const runbookUrl = core.getInput('runbook-url'); // Optional const resolve = core.getInput('resolve'); // Optional + const severity = core.getInput('severity'); // Optional - const alert = prepareAlert(pagerDutyintegrationKey, pagerDutyDedupKey, runbookUrl, resolve); + const alert = prepareAlert(pagerDutyintegrationKey, pagerDutyDedupKey, runbookUrl, resolve, severity); await sendAlert(alert); } catch (error) { core.setFailed(error.message); diff --git a/lib/prepare-alert.js b/lib/prepare-alert.js index bcd9398..0a0b2a3 100644 --- a/lib/prepare-alert.js +++ b/lib/prepare-alert.js @@ -7,13 +7,15 @@ import { context } from '@actions/github'; * @param {string} pagerDutyDedupKey The PagerDuty deduplication key (optional) * @param {string} runbookUrl The runbook URL (optional) * @param {boolean} resolve Whether to resolve the alert (optional) + * @param {string} severity Severity label for notification * @returns {Object} The alert object */ export default function prepareAlert( pagerDutyintegrationKey, pagerDutyDedupKey, runbookUrl, - resolve + resolve, + severity ) { if (!pagerDutyintegrationKey) { throw new Error('PagerDuty integration key is required'); @@ -24,7 +26,7 @@ export default function prepareAlert( summary: `${context.repo.repo}: Error in "${context.workflow}" run by @${context.actor}`, timestamp: new Date().toISOString(), source: 'GitHub Actions', - severity: 'critical', + severity: severity || 'critical', custom_details: { run_details: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`, related_commits: context.payload.commits diff --git a/package.json b/package.json index 5d5d9e8..e2db815 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "action-pagerduty-alert", "version": "1.0.2", - "description": "GitHub Action to send a critical PagerDuty alert", + "description": "GitHub Action to send a PagerDuty alert", "type": "module", "exports": "./index.js", "scripts": {