Skip to content

Instantly share code, notes, and snippets.

@Atsumi3
Last active October 23, 2024 13:22
Show Gist options
  • Save Atsumi3/770afbb0cd2178c86c283622266aae79 to your computer and use it in GitHub Desktop.
Save Atsumi3/770afbb0cd2178c86c283622266aae79 to your computer and use it in GitHub Desktop.
AppStoreとGooglePlayの審査結果をSlackに通知する
// Description: AppStoreとGooglePlayの審査結果をSlackに通知する
// ポスト先のSlack Channel名
const SLACK_CHANNEL_NAME = "";
// https://hooks.slack.com/services/XXX/YYY/ZZZ
const SLACK_WEBHOOK_URL = "";
const MAX_BODY_LENGTH = 200;
const GOOGLE_APP_NAME = "";
const GOOGLE_FROM_ADDRESS_STORE_ = "[email protected]";
const GOOGLE_FROM_ADDRESS_ = "[email protected]";
const GOOGLE_SLACK_MESSAGE_ICON_ = ":google-play:";
const GOOGLE_SLACK_MESSAGE_USER_NAME_ = "Google Play Console";
const GOOGLE_SUBJECT_REVIEW_REJECT_JP_ = "ご対応のお願い";
const GOOGLE_SUBJECT_REVIEW_REJECT_EN_ = "Action Required";
const GOOGLE_SUBJECT_DEPLOY_ = "Your update is live";
const APPLE_APP_NAME = "";
const APPLE_FROM_ADDRESS_ = "[email protected]";
const APPLE_SLACK_MESSAGE_ICON_ = ":apple:";
const APPLE_SLACK_MESSAGE_USER_NAME_ = "AppStore";
const APPLE_SUBJECT_AVAILABLE_TEST_ = "is now available to test.";
const APPLE_SUBJECT_REVIEW_ACCEPT_ = "Your submission was accepted.";
const APPLE_SUBJECT_REVIEW_REJECT_ = "We noticed an issue with your submission.";
function omitMessage_(message) {
// 最大文字数に制限
let omittedMessage = message;
if (omittedMessage.length > MAX_BODY_LENGTH) {
omittedMessage = omittedMessage.substring(0, MAX_BODY_LENGTH) + '...'; // 超過時に省略記号を追加
}
return omittedMessage;
}
function postSlack_(payload) {
let options = {
'method': 'post',
'contentType': 'Content-type: application/json; charset=utf-8',
'payload': JSON.stringify(payload).replace(/":"/g, "\"\:\"")
}
let postResult = UrlFetchApp.fetch(SLACK_WEBHOOK_URL, options) || false;
if (!postResult || postResult.getResponseCode() != 200) {
Logger.log("Slackへのポストに失敗しました");
return;
}
}
function postSlackGoogle_(title, codeBlock) {
// Slack投稿用のペイロード作成
let payload = {
"username": `[${GOOGLE_APP_NAME}] ${GOOGLE_SLACK_MESSAGE_USER_NAME_}`,
"icon_emoji": `${GOOGLE_SLACK_MESSAGE_ICON_}`,
"channel": `${SLACK_CHANNEL_NAME}`,
"text": `${title}\n\`\`\`\n${omitMessage_(codeBlock)}\n\`\`\``
};
postSlack_(payload);
}
function postSlackApple_(title, codeBlock) {
// Slack投稿用のペイロード作成
let payload = {
"username": `[${APPLE_APP_NAME}] ${APPLE_SLACK_MESSAGE_USER_NAME_}`,
"icon_emoji": `${APPLE_SLACK_MESSAGE_ICON_}`,
"channel": `${SLACK_CHANNEL_NAME}`,
"text": `${title}\n\`\`\`\n${omitMessage_(codeBlock)}\n\`\`\``
};
postSlack_(payload);
}
// GMailからPlayStoreのメールを検索する.
function search_gmail_google(subject) {
let searchResult = GmailApp.search(`from:${GOOGLE_FROM_ADDRESS_STORE_} "${subject}" is:unread`, 0, 10);
return GmailApp.getMessagesForThreads(searchResult).map((e) => e[0]);
}
// GMailからAppStoreのメールを検索する.
function search_gmail_apple(subject) {
let searchResult = GmailApp.search(`from:${APPLE_FROM_ADDRESS_} "${subject}" is:unread`, 0, 10);
return GmailApp.getMessagesForThreads(searchResult).map((e) => e[0]);
}
// AppStore: TestFlightで配信
function run_testflight() {
let messages = search_gmail_apple(`"${APPLE_APP_NAME}" "${APPLE_SUBJECT_AVAILABLE_TEST_}"`);
messages.forEach((message) => {
postSlackApple_("TestFlightで配信されました", message.getSubject());
message.markRead();
});
}
// AppStore: 審査通過
function run_review_accepted_apple() {
let searchResult = search_gmail_apple(APPLE_SUBJECT_REVIEW_ACCEPT_);
let messages = searchResult.filter((e) => e.getPlainBody().match(`App Name: ${APPLE_APP_NAME}`));
messages.forEach((message) => {
postSlackApple_("審査が通りました", message.getPlainBody());
message.markRead();
});
}
// AppStore: 審査リジェクト
function run_review_rejected_apple() {
let searchResult = search_gmail_apple(APPLE_SUBJECT_REVIEW_REJECT_);
let messages = searchResult.filter((e) => e.getPlainBody().match(`App Name: ${APPLE_APP_NAME}`));
messages.forEach((message) => {
postSlackApple_("審査がリジェクトされました", message.getPlainBody());
message.markRead();
});
}
// GooglePlay: リリースされた
function run_deploy_store_google() {
let searchResult = search_gmail_google(GOOGLE_SUBJECT_DEPLOY_);
let messages = searchResult.filter((e) => e.getPlainBody().match(`Your update to ${GOOGLE_APP_NAME}`));
messages.forEach((message) => {
postSlackGoogle_("ストアに公開されました", message.getPlainBody());
message.markRead();
});
}
// GooglePlay: 審査リジェクト
function run_review_rejected_google() {
let searchResult = search_gmail_google(`"${GOOGLE_SUBJECT_REVIEW_REJECT_JP_}" OR "${GOOGLE_SUBJECT_REVIEW_REJECT_EN_}"`);
let messages = searchResult.filter((e) => e.getSubject().match(`${GOOGLE_APP_NAME}`));
messages.forEach((message) => {
postSlackGoogle_("審査がリジェクトされました", message.getPlainBody());
message.markRead();
});
}
function run() {
run_testflight();
run_review_accepted_apple();
run_review_rejected_apple();
run_deploy_store_google();
run_review_rejected_google();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment