Integration examples¶
This page includes examples of scripts that we used to populate our own Pulse dashboard with historical data.
You can use the examples to understand better how you can integrate the Pulse CLI with your existing workflows, or adapt these examples to populate your Pulse dashboard with historical data from your team.
Pushing historic changes and deployments¶
In this example, we used the Pulse CLI to push past changes and deployments from a Git repository into Pulse.
Deployments are identified using semantic version Git tags, and the changes are the commits included in those deployments.
```sh
example.sh¶
!/usr/bin/env bash¶
set -e
CREDENTIALS="xxx"
workdir=$(mktemp -d -t website-dora-XXXXXXXXXX)
function clean { rm -rf ${workdir} } trap clean EXIT
git clone git@bitbucket.org:qamine/codacy-website "$workdir" cd ${workdir} mapfile -t deployments < <( git for-each-ref --sort=creatordate --format '%(refname) %(objectname)' refs/tags | grep -E '^refs\/tags\/[0-9]+.[0-9]+.[0-9]+\s' | awk -F"\/" '{print $3}' ) previous_deployment="" current_deployment="" for deployment in "${deployments[@]}" do deployment_id=$(echo "${deployment}" | awk '{print $1}') deployment_sha=$(echo "${deployment}" | awk '{print $2}') deployment_date=$(git log --format="%at" ${deployment_sha} | head -n 1)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
done ```
Pushing historic incidents¶
In this example, we used the Pulse CLI to push past incidents from the Codacy status page API into Pulse.
```python
incidents.py¶
import requests import subprocess from datetime import datetime, timezone
url = 'https://status.codacy.com/api/incidents'
resp = requests.get(url=url) data = resp.json()
def convert_to_unix_epoch(date_time_str): return str(int(datetime.strptime(date_time_str, '%Y-%m-%dT%H:%M:%S.%fZ').replace(tzinfo=timezone.utc).timestamp()))
for incident in data: id = incident['incidentID'] created = convert_to_unix_epoch(incident['createdAt']) updated = convert_to_unix_epoch(incident['updatedAt'])
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
```