Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
JackFreelander opened this issue Feb 16, 2023 · 1 comment

Comments

@JackFreelander
Copy link

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
Copy link
Contributor

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants