Skip to content

Commit

Permalink
feat: add severity input
Browse files Browse the repository at this point in the history
- remove critical references in docs
- add input to action
  • Loading branch information
jardon committed Jan 6, 2025
1 parent c1caf20 commit 025b3d7
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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'
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions lib/prepare-alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit 025b3d7

Please sign in to comment.