Skip to content

Commit 54e6dfb

Browse files
committed
Added discord webhook configuration
Added Exception case log Added discord.js Added whitespace Fixed discord webhook send
1 parent b88c5cc commit 54e6dfb

File tree

7 files changed

+131
-2
lines changed

7 files changed

+131
-2
lines changed

.github/workflows/fetch.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jobs:
2929
ISSUER_ID: ${{ secrets.ISSUER_ID }}
3030
BUNDLE_ID: ${{ secrets.BUNDLE_ID }}
3131
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
32+
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
3233
GH_TOKEN: ${{ secrets.GH_TOKEN }}
3334
GIST_ID: ${{ secrets.GIST_ID }}
34-
LANGUAGE: "ko"
35+
LANGUAGE: "ko"

README-JAPANESE.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ App Store Connect status botはアプリの審査状態をSlackにメッセー
4747
> ISSUER_ID : `Issuer ID`もここに入力します。
4848
> BUNDLE_ID : 状態の確認したいアプリの `bundle identifier`を入力します。 (2個以上のアプリの場合は、「 」 スペースを入れずに、「,」記号を使うと動作します。)
4949
> 2個以上のアプリの場合は、カンマ記号を使い、スペースを入れずに入力してください
50-
> SLACK_WEBHOOK : SlackのWebhook URLを入力します。
50+
> SLACK_WEBHOOK : SlackのWebhook URLを入力します。
51+
> DISCORD_WEBHOOK : DiscordのWebhook URLを入力します。 (optional)
5152
> GH_TOKEN: Githubのトークンを入力します。 (`gists``repo` 権限が必要です。 )
5253
> GIST_ID: gistファイルを作成し、 URLに存在するキーをコピーして入力します。
5354
- https://gist.github.com/techinpark/**9842e074b8ee46aef76fd0d493bae0ed**

README-KOREAN.md

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ App Store Connect status bot 은 앱스토어에 올라가 있는 나의 앱 심
4747
> ISSUER_ID : `Issuer ID`도 이곳에 입력합니다.
4848
> BUNDLE_ID : 상태를 확인하고 싶은 앱의 `bundle identifier` 을 입력해줍니다. (공백 없이 콤마로 구분하시면 2개이상의 앱도 가능합니다.)
4949
> SLACK_WEBHOOK : 슬랙 Webhook URL을 넣어줍니다.
50+
> DISCORD_WEBHOOK : 디스코드 Webhook URL을 넣어줍니다. (optional)
5051
> GH_TOKEN: 깃헙 토큰을 넣어줍니다 (`gists``repo` 권한이 필요합니다 )
5152
> GIST_ID: gist파일을 생성하고 URL에 존재하는 키값을 복사해서 넣어줍니다.
5253
- https://gist.github.com/techinpark/**9842e074b8ee46aef76fd0d493bae0ed**

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ To get your Key ID, copy it from App Store Connect by logging in to [App Store C
4747
> ISSUER_ID : Input Appstore connect `issuer_id`
4848
> BUNDLE_ID : Input your bundle_identifier of application you can input multiple bundle_id with comma and no whitespace
4949
> SLACK_WEBHOOK : Input your slack webhook url
50+
> DISCORD_WEBHOOK : Input your discord webhook url (optional)
5051
> GH_TOKEN: Input your github token, (need `gists` and `repo` scope).
5152
> GIST_ID: Input portion from your gist url:
5253
- https://gist.github.com/techinpark/**9842e074b8ee46aef76fd0d493bae0ed**

Sources/check_status.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const slack = require("./slack.js");
2+
const discord = require("./discord.js");
23
const exec = require("child_process").exec;
34
const dirty = require("dirty");
45
const { Octokit, App } = require("octokit");
@@ -38,7 +39,9 @@ const checkVersion = async (app) => {
3839
var lastAppInfo = db.get(appInfoKey);
3940
if (!lastAppInfo || lastAppInfo.status != app.status) {
4041
console.log("[*] status is different");
42+
4143
slack.post(app, db.get(submissionStartKey));
44+
discord.post(app, db.get(submissionStartKey));
4245

4346
if (app.status == "Waiting For Review") {
4447
db.set(submissionStartKey, new Date());

Sources/discord.js

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
const moment = require("moment");
2+
const path = require("path");
3+
const fetch = require("node-fetch");
4+
const { I18n } = require("i18n");
5+
6+
const webhookURL = process.env.DISCORD_WEBHOOK;
7+
const language = process.env.LANGUAGE;
8+
const i18n = new I18n();
9+
10+
i18n.configure({
11+
locales: ['en', 'ko', 'ja'],
12+
directory: path.join(__dirname, '../locales'),
13+
defaultLocale: 'en'
14+
});
15+
16+
i18n.setLocale(language || 'en');
17+
18+
function post(appInfo, submissionStartDate) {
19+
const status = i18n.__(appInfo.status);
20+
const message = i18n.__("Message", { appname: appInfo.name, status: status });
21+
const embed = discordEmbed(appInfo, submissionStartDate);
22+
23+
hook(message, embed);
24+
}
25+
26+
async function hook(message, embed) {
27+
const payload = {
28+
content: message,
29+
embeds: [embed]
30+
};
31+
32+
await fetch(webhookURL, {
33+
method: 'POST',
34+
headers: {
35+
'Content-Type': 'application/json',
36+
},
37+
body: JSON.stringify(payload),
38+
});
39+
}
40+
41+
function discordEmbed(appInfo, submissionStartDate) {
42+
const embed = {
43+
title: "App Store Connect",
44+
author: {
45+
name: appInfo.name,
46+
icon_url: appInfo.iconURL
47+
},
48+
url: `https://appstoreconnect.apple.com/apps/${appInfo.appID}/appstore`,
49+
fields: [
50+
{
51+
name: i18n.__("Version"),
52+
value: appInfo.version,
53+
inline: true,
54+
},
55+
{
56+
name: i18n.__("Status"),
57+
value: i18n.__(appInfo.status),
58+
inline: true,
59+
}
60+
],
61+
footer: {
62+
text: "appstore-status-bot",
63+
icon_url: "https://icons-for-free.com/iconfiles/png/512/app+store+apple+apps+game+games+store+icon-1320085881005897327.png"
64+
},
65+
timestamp: new Date()
66+
};
67+
68+
// Set elapsed time since "Waiting For Review" start
69+
if (
70+
submissionStartDate &&
71+
appInfo.status !== "Prepare for Submission" &&
72+
appInfo.status !== "Waiting For Review"
73+
) {
74+
const elapsedHours = moment().diff(moment(submissionStartDate), "hours");
75+
embed.fields.push({
76+
name: "Elapsed Time",
77+
value: `${elapsedHours} hours`,
78+
inline: true,
79+
});
80+
}
81+
82+
embed.color = colorForStatus(appInfo.status);
83+
84+
return embed;
85+
}
86+
87+
function colorForStatus(status) {
88+
const infoColor = 0x8e8e8e;
89+
const warningColor = 0xf4f124;
90+
const successColor1 = 0x1eb6fc;
91+
const successColor2 = 0x14ba40;
92+
const failureColor = 0xe0143d;
93+
const colorMapping = {
94+
"Prepare for Submission": infoColor,
95+
"Waiting For Review": infoColor,
96+
"In Review": successColor1,
97+
"Pending Contract": warningColor,
98+
"Waiting For Export Compliance": warningColor,
99+
"Pending Developer Release": successColor2,
100+
"Processing for App Store": successColor2,
101+
"Pending Apple Release": successColor2,
102+
"Ready for Sale": successColor2,
103+
Rejected: failureColor,
104+
"Metadata Rejected": failureColor,
105+
"Removed From Sale": failureColor,
106+
"Developer Rejected": failureColor,
107+
"Developer Removed From Sale": failureColor,
108+
"Invalid Binary": failureColor,
109+
};
110+
111+
return colorMapping[status];
112+
}
113+
114+
module.exports = {
115+
post: post,
116+
};

Sources/slack.js

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ function post(appInfo, submissionStartDate) {
2929
}
3030

3131
async function hook(message, attachment) {
32+
33+
if (!webhookURL) {
34+
console.log("No Slack webhook URL provided.");
35+
return;
36+
}
37+
3238
const webhook = new IncomingWebhook(webhookURL, {});
3339
await webhook.send({
3440
text: message,

0 commit comments

Comments
 (0)