From a63b9e9ffa03b7fbbcaee8c4fc7986b258d6c6a0 Mon Sep 17 00:00:00 2001 From: thinkasany <480968828@qq.com> Date: Sat, 14 Sep 2024 14:56:16 +0800 Subject: [PATCH] ci: send Unconfirmed Issues to DingTalk (#50810) Co-authored-by: afc163 --- .github/workflows/issue-schedule.yml | 97 ++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 .github/workflows/issue-schedule.yml diff --git a/.github/workflows/issue-schedule.yml b/.github/workflows/issue-schedule.yml new file mode 100644 index 0000000000..7f78cb7180 --- /dev/null +++ b/.github/workflows/issue-schedule.yml @@ -0,0 +1,97 @@ +name: Issue Schedule +on: + workflow_dispatch: + schedule: + - cron: '30 1 * * *' + +jobs: + send-message: + runs-on: ubuntu-latest + steps: + - name: Send Unconfirmed Issues to DingTalk + uses: actions/github-script@v7 + env: + DINGDING_BOT_TOKEN: ${{ secrets.DINGDING_BOT_TOKEN }} + actionTitle: '近 7 天未确认的 issue' + with: + script: | + const dingdingTokenKey = process.env.DINGDING_BOT_TOKEN; + + const fromNow = (data) => { + const relativeTimeFormat = new Intl.RelativeTimeFormat('zh-CN'); + const date = new Date(data); + const now = new Date(); + + const diffInSeconds = Math.floor((now - date) / 1000); + const diffInMinutes = Math.floor(diffInSeconds / 60); + const diffInHours = Math.floor(diffInMinutes / 60); + const diffInDays = Math.floor(diffInHours / 24); + + if (diffInDays > 0) { + return relativeTimeFormat.format(-diffInDays, 'day'); + } else if (diffInHours > 0) { + return relativeTimeFormat.format(-diffInHours, 'hour'); + } else if (diffInMinutes > 0) { + return relativeTimeFormat.format(-diffInMinutes, 'minute'); + } else { + return relativeTimeFormat.format(-diffInSeconds, 'second'); + } + }; + + const response = await fetch('https://api.github.com/search/issues?q=repo:ant-design/ant-design&is:open+is:issue+label:unconfirmed&per_page=100'); + const data = await response.json(); + const issueList = []; + for (const item of data.items) { + const { created_at, html_url, pull_request, state, title, labels } = item; + const createdAt = new Date(created_at); + const now = new Date(); + const diffTime = Math.abs(now - createdAt); + const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); + + const isUnconfirmed = labels.some(label => label.name === 'unconfirmed'); + + if (!isUnconfirmed) { + continue; + } + + if (diffDays > 7) { + break; + } + + if (!pull_request && !html_url.includes('pull') && state === 'open') { + issueList.push({ + html_url, + created_at, + title + }) + } + } + + const actionTitle = process.env.actionTitle + `(${issueList.length})`; + + const markdownList = `

${actionTitle}

\n\n` + + issueList.map(issue => `- [${issue.title}](${issue.html_url}) ${fromNow(issue.created_at)}`).join('\n') + + `\n\n > 🫵🏻 快去帮忙处理吧,社区需要你的帮助!`; + + console.log(markdownList); + + try { + await fetch( + `https://oapi.dingtalk.com/robot/send?access_token=${dingdingTokenKey}`, + { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + msgtype: 'markdown', + markdown: { + title: actionTitle, + text: markdownList, + }, + }), + } + ); + } catch (error) { + console.log('发送失败, error:', error); + }