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

Updated Pagerduty Self Service GitHub Actions #1215

Merged
merged 13 commits into from
May 28, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
{
"incidents": [
{
"id": "${{ fromJson(inputs.port_payload).port_context.entity }}",
"id": "${{ fromJson(inputs.port_context).entity }}",
"type": "incident_reference",
"status": "acknowledged"
}
Expand Down Expand Up @@ -114,6 +114,7 @@ jobs:
"created_at": "${{ fromJson(steps.acknowledge_incident.outputs.response).incidents[0].created_at }}",
"updated_at": "${{ fromJson(steps.acknowledge_incident.outputs.response).incidents[0].updated_at }}"
}
relations: "${{ toJson(fromJson(inputs.port_context).relations) }}"
clientId: ${{ secrets.PORT_CLIENT_ID }}
clientSecret: ${{ secrets.PORT_CLIENT_SECRET }}
baseUrl: https://api.getport.io
Expand Down Expand Up @@ -191,8 +192,9 @@ Create a new self service action using the following JSON configuration.
"{{if (.inputs | has(\"from\")) then \"from\" else null end}}": "{{.inputs.\"from\"}}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"{{if (.inputs | has(\"from\")) then \"from\" else null end}}": "{{.inputs.\"from\"}}",
"from": "{{.inputs.\"from\"}}",

"port_context": {
"blueprint": "{{.action.blueprint}}",
"entity": "{{.entity}}",
"run_id": "{{.run.id}}"
"entity": "{{.entity.identifier}}",
"run_id": "{{.run.id}}",
"relations": "{{.entity.relations}}"
}
},
"reportWorkflowStatus": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ jobs:
"description": "${{ fromJson(steps.new_schedule.outputs.response).schedule.description}}",
"users": ${{ env.user_summaries }}
}
relations: "${{ toJson(fromJson(inputs.port_context).relations) }}"
clientId: ${{ secrets.PORT_CLIENT_ID }}
clientSecret: ${{ secrets.PORT_CLIENT_SECRET }}
baseUrl: https://api.getport.io
Expand Down Expand Up @@ -250,16 +251,17 @@ Create a new self service action using the following JSON configuration.
"type": "GITHUB",
"org": "<GITHUB_ORG>",
"repo": "<GITHUB_REPO>",
"workflow": "change-incident-owner.yaml",
"workflow": "change-on-call-user.yaml",
"workflowInputs": {
"{{if (.inputs | has(\"ref\")) then \"ref\" else null end}}": "{{.inputs.\"ref\"}}",
"{{if (.inputs | has(\"start_time\")) then \"start_time\" else null end}}": "{{.inputs.\"start_time\"}}",
"{{if (.inputs | has(\"end_time\")) then \"end_time\" else null end}}": "{{.inputs.\"end_time\"}}",
"{{if (.inputs | has(\"new_on_call_user\")) then \"new_on_call_user\" else null end}}": "{{.inputs.\"new_on_call_user\"}}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all the inputs here too could go through this change:

Suggested change
"{{if (.inputs | has(\"new_on_call_user\")) then \"new_on_call_user\" else null end}}": "{{.inputs.\"new_on_call_user\"}}",
"new_on_call_user": "{{.inputs.\"new_on_call_user\"}}",

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats relevant for the other files in this PR as well

"port_context": {
"blueprint": "{{.action.blueprint}}",
"entity": "{{.entity}}",
"run_id": "{{.run.id}}"
"entity": "{{.entity.identifier}}",
"run_id": "{{.run.id}}",
"relations": "{{.entity.relations}}"
}
},
"reportWorkflowStatus": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ jobs:
"created_at": "${{ fromJson(steps.change_owner.outputs.response).incident.created_at }}",
"updated_at": "${{ fromJson(steps.change_owner.outputs.response).incident.updated_at }}"
}
relations: "${{ toJson(fromJson(inputs.port_context).relations) }}"
clientId: ${{ secrets.PORT_CLIENT_ID }}
clientSecret: ${{ secrets.PORT_CLIENT_SECRET }}
baseUrl: https://api.getport.io
Expand Down Expand Up @@ -290,12 +291,13 @@ Create a new self service action using the following JSON configuration.
"workflow": "change-incident-owner.yaml",
"workflowInputs": {
"{{if (.inputs | has(\"ref\")) then \"ref\" else null end}}": "{{.inputs.\"ref\"}}",
"{{if (.inputs | has(\"new_owner_user_id\")) then \"new_owner_user_id\" else null end}}": "{{.inputs.\"new_owner_user_id\"}}",
"{{if (.inputs | has(\"new_owner\")) then \"new_owner\" else null end}}": "{{.inputs.\"new_owner\"}}",
"{{if (.inputs | has(\"from\")) then \"from\" else null end}}": "{{.inputs.\"from\"}}",
"port_context": {
"blueprint": "{{.action.blueprint}}",
"entity": "{{.entity}}",
"run_id": "{{.run.id}}"
"entity": "{{.entity.identifier}}",
"run_id": "{{.run.id}}",
"relations": "{{.entity.relations}}"
}
},
"reportWorkflowStatus": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,26 @@ jobs:
"service": {
"name": "${{ github.event.inputs.name }}",
"description": "${{ github.event.inputs.description }}",
"escalation_policy": ${{ github.event.inputs.escalation_policy }}
"status": "active",
"escalation_policy": {
"id": "${{ github.event.inputs.escalation_policy }}",
"type": "escalation_policy_reference"
}
}
}
}

- name: Create a log message

- name: Log Create Service Request Failure
if: failure()
uses: port-labs/port-github-action@v1
with:
clientId: ${{ secrets.PORT_CLIENT_ID }}
clientSecret: ${{ secrets.PORT_CLIENT_SECRET }}
baseUrl: https://api.getport.io
operation: PATCH_RUN
runId: ${{fromJson(inputs.port_context).run_id}}
logMessage: "Request to create service failed ..."

- name: Log Request Success
uses: port-labs/port-github-action@v1
with:
clientId: ${{ secrets.PORT_CLIENT_ID }}
Expand All @@ -83,17 +98,37 @@ jobs:
runId: ${{fromJson(inputs.port_context).run_id}}
logMessage: |
PagerDuty service created! ✅
Requesting for oncalls
Requesting for on-calls

- name: Request for oncalls for escalation_policy
- name: Request for oncalls for Escalation Policy
id: fetch_oncalls
uses: fjogeleit/http-request-action@v1
with:
url: 'https://api.pagerduty.com/oncalls?include[]=users&escalation_policy_ids[]=${{ fromJson(github.event.inputs.escalation_policy).id }}'
url: 'https://api.pagerduty.com/oncalls?include[]=users&escalation_policy_ids[]=${{ inputs.escalation_policy }}'
method: 'GET'
customHeaders: '{"Content-Type": "application/json", "Accept": "application/json", "Authorization": "Token token=${{ secrets.PAGERDUTY_API_KEY }}"}'

- name: Create a log message
- name: Extract User Emails
pazhersh marked this conversation as resolved.
Show resolved Hide resolved
if: steps.fetch_oncalls.outcome == 'success'
id: extract_user_emails
run: |
echo "Extracting user emails..."
EMAILS=$(echo '${{ steps.fetch_oncalls.outputs.response }}' | jq -c '[.oncalls[].user.email]')
echo "Extracted emails: $EMAILS"
echo "user_emails=${EMAILS}" >> $GITHUB_ENV

- name: Log Fetch Oncalls Request Failure
if: steps.fetch_oncalls.outcome == 'failure'
uses: port-labs/port-github-action@v1
with:
clientId: ${{ secrets.PORT_CLIENT_ID }}
clientSecret: ${{ secrets.PORT_CLIENT_SECRET }}
baseUrl: https://api.getport.io
operation: PATCH_RUN
runId: ${{fromJson(inputs.port_context).run_id}}
logMessage: Failed to fetch on-calls ❌

- name: Log Before Upserting Entity
uses: port-labs/port-github-action@v1
with:
clientId: ${{ secrets.PORT_CLIENT_ID }}
Expand All @@ -108,24 +143,23 @@ jobs:
uses: port-labs/port-github-action@v1
with:
identifier: "${{ fromJson(steps.create_service_request.outputs.response).service.id }}"
title: "${{ fromJson(steps.create_service_request.outputs.response).service.summary }}"
team: "[]"
title: "${{ fromJson(steps.create_service_request.outputs.response).service.summary }}"
icon: pagerduty
blueprint: ${{fromJson(inputs.port_context).blueprint}}
blueprint: "${{fromJson(inputs.port_context).blueprint}}"
properties: |-
{
"status": "${{ fromJson(steps.create_service_request.outputs.response).service.status }}",
"url": "${{ fromJson(steps.create_service_request.outputs.response).service.html_url }}",
"oncall": "${{ fromJson(steps.fetch_oncalls).oncalls }}"
"oncall": ${{ env.user_emails }}
}
relations: "{}"
relations: "${{ toJson(fromJson(inputs.port_context).relations) }}"
clientId: ${{ secrets.PORT_CLIENT_ID }}
clientSecret: ${{ secrets.PORT_CLIENT_SECRET }}
baseUrl: https://api.getport.io
operation: UPSERT
runId: ${{fromJson(inputs.port_context).run_id}}

- name: Create a log message
- name: Log After Upserting Entity
uses: port-labs/port-github-action@v1
with:
clientId: ${{ secrets.PORT_CLIENT_ID }}
Expand All @@ -134,7 +168,7 @@ jobs:
operation: PATCH_RUN
runId: ${{fromJson(inputs.port_context).run_id}}
logMessage: |
Upsert was successful ✅
Upserting was successful ✅
```
</details>

Expand Down Expand Up @@ -175,7 +209,7 @@ Create a new self service action using the following JSON configuration.
"description": "PagerDuty Escalation Policy ID to apply",
"icon": "pagerduty",
"type": "string"
},
}
},
"required": [
"name",
Expand All @@ -201,8 +235,9 @@ Create a new self service action using the following JSON configuration.
"{{if (.inputs | has(\"escalation_policy\")) then \"escalation_policy\" else null end}}": "{{.inputs.\"escalation_policy\"}}",
"port_context": {
"blueprint": "{{.action.blueprint}}",
"entity": "{{.entity}}",
"run_id": "{{.run.id}}"
"entity": "{{.entity.identifier}}",
"run_id": "{{.run.id}}",
"relations": "{{.entity.relations}}"
}
},
"reportWorkflowStatus": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
id: escalate_incident
uses: fjogeleit/http-request-action@v1
with:
url: 'https://api.pagerduty.com/incidents/${{inputs.entity_identifier}}'
url: 'https://api.pagerduty.com/incidents/${{fromJson(inputs.port_context).entity}}'
method: 'PUT'
customHeaders: '{"Content-Type": "application/json", "Accept": "application/vnd.pagerduty+json;version=2", "Authorization": "Token token=${{ secrets.PAGERDUTY_API_KEY }}", "From": "${{ github.event.inputs.from }}"}'
data: >-
Expand Down Expand Up @@ -109,6 +109,7 @@ jobs:
logMessage: "Reporting the escalated incident back to Port ..."

- name: Upsert pagerduty entity to Port
id: upsert_entity
uses: port-labs/port-github-action@v1
with:
identifier: ${{inputs.entity_identifier}}
Expand All @@ -124,14 +125,15 @@ jobs:
"created_at": "${{ fromJson(steps.escalate_incident.outputs.response).incident.created_at }}",
"updated_at": "${{ fromJson(steps.escalate_incident.outputs.response).incident.updated_at }}"
}
relations: "${{ toJson(fromJson(inputs.port_context).relations) }}"
clientId: ${{ secrets.PORT_CLIENT_ID }}
clientSecret: ${{ secrets.PORT_CLIENT_SECRET }}
baseUrl: https://api.getport.io
operation: UPSERT
runId: ${{fromJson(inputs.port_context).run_id}}

- name: Inform Entity upsert failure
if: failure()
if: steps.upsert_entity.outcome == 'failure'
uses: port-labs/port-github-action@v1
with:
clientId: ${{ secrets.PORT_CLIENT_ID }}
Expand All @@ -141,7 +143,7 @@ jobs:
runId: ${{fromJson(inputs.port_context).run_id}}
logMessage: "Failed to report the escalated incident back to Port ..."

- name: Inform completion of PagerDuty escalation process into Port
- name: Inform completion of PagerDuty incident escalation
uses: port-labs/port-github-action@v1
with:
clientId: ${{ secrets.PORT_CLIENT_ID }}
Expand Down Expand Up @@ -227,8 +229,9 @@ Create a new self service action using the following JSON configuration.
"{{if (.inputs | has(\"from\")) then \"from\" else null end}}": "{{.inputs.\"from\"}}",
"port_context": {
"blueprint": "{{.action.blueprint}}",
"entity": "{{.entity}}",
"run_id": "{{.run.id}}"
"entity": "{{.entity.identifier}}",
"run_id": "{{.run.id}}",
"relations": "{{.entity.relations}}"
}
},
"reportWorkflowStatus": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
{
"incidents": [
{
"id": "${{ fromJson(inputs.port_payload).port_context.entity }}",
"id": "${{fromJson(inputs.port_context).entity}}",
"type": "incident_reference",
"status": "resolved"
}
Expand Down Expand Up @@ -114,6 +114,7 @@ jobs:
"created_at": "${{ fromJson(steps.resolve_incident.outputs.response).incidents[0].created_at }}",
"updated_at": "${{ fromJson(steps.resolve_incident.outputs.response).incidents[0].updated_at }}"
}
relations: "${{ toJson(fromJson(inputs.port_context).relations) }}"
clientId: ${{ secrets.PORT_CLIENT_ID }}
clientSecret: ${{ secrets.PORT_CLIENT_SECRET }}
baseUrl: https://api.getport.io
Expand Down Expand Up @@ -169,16 +170,17 @@ Create a new self service action using the following JSON configuration.
},
"invocationMethod": {
"type": "GITHUB",
"org": "<GITHUB_ORG>",
"repo": "<GITHUB_REPO>",
"org": "GITHUB_ORG",
"repo": "GITHUB_REPO",
"workflow": "resolve-incident.yaml",
"workflowInputs": {
"{{if (.inputs | has(\"ref\")) then \"ref\" else null end}}": "{{.inputs.\"ref\"}}",
"{{if (.inputs | has(\"from\")) then \"from\" else null end}}": "{{.inputs.\"from\"}}",
"port_context": {
"blueprint": "{{.action.blueprint}}",
"entity": "{{.entity}}",
"run_id": "{{.run.id}}"
"entity": "{{.entity.identifier}}",
"run_id": "{{.run.id}}",
"relations": "{{.entity.relations}}"
}
},
"reportWorkflowStatus": true
Expand Down