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

Add custom details and links #13

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
}
]
```
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: 'Override default links to be shown on the alert and/or corresponding incident for a push or custom event.'
required: false
runs:
using: 'node16'
main: 'index.js'
21 changes: 12 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ 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}`,
href: `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`,
text: "View run"
}
]
Expand All @@ -35,7 +35,7 @@ function handleCustomEvent(summary, integrationKey) {
sendChangeEvent(changeEvent);
}

function handlePushEvent(data, integrationKey) {
function handlePushEvent(data, customDetails, customLinks, integrationKey) {
const {
ref,
compare: compareHref,
Expand All @@ -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'
Expand Down Expand Up @@ -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 {
Expand Down