-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
51 lines (46 loc) · 1.28 KB
/
index.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
40
41
42
43
44
45
46
47
48
49
50
51
const core = require("@actions/core");
const axios = require("axios");
const size = core.getInput("news");
if (size > 100) {
core.setFailed(
"More than 100 news are not allowed. Please set a smaller number of news count."
);
}
//top news
const hackernewsURL = "https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty";
async function run() {
const temp = [];
let msg = "";
const newsContent = obj => {
temp.push(obj);
msg += `[${temp.length}] ${obj.title} \n* link : ${obj.link} \n* details : ${obj.detail} \n\n`;
if (temp.length === size) {
try {
core.setOutput("Top 5 news on HackerNews", msg);
} catch (error) {
core.setFailed(error.message);
}
}
};
axios
.get(hackernewsURL)
.then(function(response) {
response.data.slice(0, size).map(rs => {
axios
.get(
`https://hacker-news.firebaseio.com/v0/item/${rs}.json?print=pretty`
)
.then(rs_response => {
newsContent({
title: rs_response.data.title,
link: rs_response.data.url,
detail: `https://news.ycombinator.com/item?id=${rs}`
});
});
});
})
.catch(function(error) {
core.setFailed(error.message);
});
}
run();