Entle / action-pagerduty-alert

MIT License
8 stars 32 forks source link

Allow callers to specify additional parameters (summary, severity, group, class, component) #7

Open JackFreelander opened 1 year ago

JackFreelander commented 1 year ago

Would be nice to allow callers to pass additional parameters; I have a (local) branch for this (including updates to README) but don't have permission to push upstream.

// Run the action
try {
  const severityLevels = ['critical', 'error', 'warning', 'info'];
  const defaultSeverity = 'critical';

  const integrationKey = core.getInput('pagerduty-integration-key');
  const summary = core.getInput('pagerduty-summary') ?? `${context.repo.repo}: Error in "${context.workflow}" run by @${context.actor}`;
  const severityParam = core.getInput('pagerduty-severity');
  const severity = severityLevels.includes(severityParam) ? severityParam : defaultSeverity;

  let alert = {
    payload: {
      summary,
      timestamp: new Date().toISOString(),
      source: 'GitHub Actions',
      severity,
      custom_details: {
        run_details: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
        related_commits: context.payload.commits
          ? context.payload.commits.map((commit) => `${commit.message}: ${commit.url}`).join(', ')
          : 'No related commits',
      },
    },
    routing_key: integrationKey,
    event_action: 'trigger',
  };

  // See https://developer.pagerduty.com/docs/ZG9jOjExMDI5NTgx-send-an-alert-event for endpoint documentation
  const componentParam = core.getInput('pagerduty-component');
  if (componentParam) {
    alert.component = componentParam;
  }

  const groupParam = core.getInput('pagerduty-group');
  if (groupParam) {
    alert.group = groupParam;
  }

  const classParam = core.getInput('pagerduty-class');
  if (classParam) {
    alert.class = classParam;
  }

  const dedupKey = core.getInput('pagerduty-dedup-key');
  if (dedupKey != '') {
    alert.dedup_key = dedupKey;
  }
  sendAlert(alert);
} catch (error) {
  core.setFailed(error.message);
}
miparnisari commented 1 year ago

I did something similar to this in my fork: https://github.com/miparnisari/action-pagerduty-alert. Feel free to send a PR to add more fields :)

JohJonker commented 1 week ago

Thanks for the input @JackFreelander and sorry for the slow response. Could you submit a PR?