-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.js
39 lines (35 loc) · 1.36 KB
/
lib.js
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
const core = require('@actions/core');
var axios = require('axios').default;
module.exports = async function () {
try {
const apiKey = core.getInput('api-key');
const name = core.getInput('name');
const ext = core.getInput('ext');
const response = await axios({
method: 'GET',
url: `https://domaine-nc.p.rapidapi.com/${name}/${ext}`,
headers: {
'x-rapidapi-host': 'domaine-nc.p.rapidapi.com',
'x-rapidapi-key': apiKey,
},
});
if (response.data.expired) {
core.wan(`🚨 ${name}.${ext} is expired since ${response.data.dateExpiration} 🚨`);
} else if (response.data.nbDaysBeforeExpires <= 14) {
core.warn(`⚠️ ${name}.${ext} expires within ${response.data.nbDaysBeforeExpires} day(s) ⚠️`);
} else {
core.info(`✅ ${name}.${ext} expires within ${response.data.nbDaysBeforeExpires} day(s)`);
}
core.setOutput('expired', response.data.expired);
core.setOutput('expirationDate', response.data.dateExpiration);
core.setOutput('daysBeforeExpiration', response.data.nbDaysBeforeExpires);
} catch (error) {
if (error.response && error.response.status === 401) {
core.setFailed('HTTP 401 : maybe invalid api-key ?');
} else if (error.response && error.response.data) {
core.setFailed(error.response.data);
} else {
core.setFailed(error);
}
}
};