forked from SocialGouv/dashlord
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new action to get data from updown
- Loading branch information
Showing
6 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: "UpDown data retrieving" | ||
description: "Récupération des données UpDown pour une démarche" | ||
|
||
inputs: | ||
updownToken: | ||
description: "Token UpDown associé à la démarche" | ||
required: true | ||
updownApiKey: | ||
description: "Clé API Read-only UpDown" | ||
required: true | ||
startDate: | ||
description: "Get data from this date" | ||
required: true | ||
endDate: | ||
description: "Get data to this date" | ||
required: false | ||
output: | ||
description: "Path to output file. defaults to updown.json" | ||
default: "updown.json" | ||
required: true | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Install | ||
shell: bash | ||
run: | | ||
cd ${{ github.action_path }} | ||
yarn | ||
- name: UpDown retrieve data | ||
shell: bash | ||
run: | | ||
cd ${{ github.action_path }} | ||
node index ${{ inputs.updownToken }} ${{ inputs.updownApiKey }} ${{ inputs.startDate }} ${{ inputs.endDate }} > ${{ github.workspace }}/${{ inputs.output }} | ||
cat ${{ github.workspace }}/${{ inputs.output }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const fetch = (...args) => | ||
import("node-fetch").then(({ default: fetch }) => fetch(...args)); | ||
|
||
const encodeQueryParams = (params) => { | ||
return Object.keys(params) | ||
.map((key) => { | ||
const value = params[key]; | ||
return ( | ||
encodeURIComponent(key) + | ||
"=" + | ||
encodeURIComponent( | ||
typeof value === "object" ? JSON.stringify(value) : value | ||
) | ||
); | ||
}) | ||
.join("&"); | ||
}; | ||
|
||
const getUpdownData = async (updownToken, updownApiKey, startDate, endDate) => { | ||
const params = { | ||
from: startDate, | ||
to: endDate, | ||
}; | ||
|
||
const metrics_url = `https://updown.io/api/checks/${updownToken}/metrics?${encodeQueryParams(params)}`; | ||
|
||
fetch(metrics_url, { | ||
method: "GET", | ||
headers: { | ||
"Content-Type": "application/json", | ||
"X-API-KEY": updownApiKey | ||
}, | ||
}).then((response) => { | ||
response.json().then((json) => { | ||
const data = json; | ||
|
||
if (data) { | ||
console.log(JSON.stringify(data)); | ||
} | ||
}); | ||
}); | ||
}; | ||
|
||
module.exports = { getUpdownData }; | ||
|
||
if (require.main === module) { | ||
getUpdownData( | ||
process.argv[process.argv.length - 4], | ||
process.argv[process.argv.length - 3], | ||
process.argv[process.argv.length - 2], | ||
process.argv[process.argv.length - 1] | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "jdma", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"dependencies": { | ||
"node-fetch": "^3.3.0" | ||
}, | ||
"devDependencies": { | ||
"jest": "^29.0.2" | ||
}, | ||
"scripts": { | ||
"test": "jest" | ||
} | ||
} |