generated from actions/javascript-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
43 lines (41 loc) · 1.17 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
const core = require('@actions/core')
const superagent = require('superagent')
const dayjs = require('dayjs')
const { format } = require('util')
async function run() {
try {
const userId = core.getInput('user_id')
core.info(`user_id: ${userId}`)
const res = await superagent
.post('https://api.juejin.cn/content_api/v1/article/query_list')
.send({
user_id: userId,
sort_type: 2,
cursor: '0',
})
const articleList = res.body.data.map((item) => item.article_info)
if (articleList.length === 0) {
core.warning(`${userId} 此 id 没发表文章`)
return
}
const itemMd = articleList
.map(
(article) =>
`* <a href='https://juejin.cn/post/${
article.article_id
}' target='_blank'>${article.title}</a> - ${dayjs
.unix(article.ctime)
.format('YYYY/MM/DD HH:mm')}`
)
.join('\n')
const md = format(
`#### 🤾 <a href="https://juejin.cn/user/${userId}" target="_blank">最近更新</a>
%s`,
itemMd
)
core.exportVariable('juejin_post_md', md)
} catch (error) {
core.setFailed(error.message)
}
}
run()