Last active
November 13, 2023 04:23
-
-
Save motokiee/39a875e97349fe9325314bdae9d3af2a to your computer and use it in GitHub Desktop.
Post iTunes Connect Status to Slack with Gmail using Google Apps Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mailAddress = "YOUR_EMAIL_ADDRSS"; | |
var slackToken = "SLACK_TOKEN"; | |
var searchMailQuery = 'SEARCH_QUERY'; // example: '[from:[email protected] YOUR_APP_NAME]'; | |
var slackChannelId = "SLACK_CHANNEL_ID"; | |
function getAttachment(message) { | |
var subject = message.getSubject(); | |
var body = message.getPlainBody(); | |
var result = body.match("([0-9]\.[0-9])+(\.[0-9])?"); | |
if (!result) { | |
return null | |
} | |
var version = result[0]; | |
var statuses = [ | |
{ | |
"subject": subject, | |
"version": version, | |
"token": "Waiting For Review", | |
"text": "Waiting For Review" | |
}, | |
{ | |
"subject": subject, | |
"version": version, | |
"token": "Developer Rejected", | |
"text": "Developer Rejected" | |
}, | |
{ | |
"subject": subject, | |
"version": version, | |
"token": "In Review", | |
"text": "In Review" | |
}, | |
{ | |
"subject": subject, | |
"version": version, | |
"token": "New message from App Review", | |
"text": "New message from App Review" | |
}, | |
{ | |
"subject": subject, | |
"version": version, | |
"token": "Pending Developer Release", | |
"text": "Pending Developer Release" | |
}, | |
{ | |
"subject": subject, | |
"version": version, | |
"token": "Ready for Sale", | |
"text": "Ready for Sale" | |
}, | |
{ | |
"subject": subject, | |
"version": version, | |
"token": "now available to test", | |
"text": "now available to test" | |
}, | |
]; | |
for (var status in statuses) { | |
if (~subject.indexOf(statuses[status].token)) { | |
return statuses[status]; | |
} | |
} | |
return null; | |
} | |
function getFields(message) { | |
var attachment = getAttachment(message); | |
if (!attachment) { | |
return null | |
} | |
return attachment; | |
} | |
function postSlack(fields) { | |
var prop = PropertiesService.getScriptProperties().getProperties(); | |
var slackApp = SlackApp.create(prop.token); | |
var message = fields.text + "\n" | |
slackApp.postMessage(slackChannelId, message, { | |
username : "iOS v" + fields.version + " is " + fields.token, | |
icon_emoji : ":rocket:", | |
}); | |
} | |
function main() { | |
PropertiesService.getScriptProperties().setProperty("token", slackToken); | |
var threads = GmailApp.search(searchMailQuery); | |
for (var i = 0; i < threads.length; i++) { | |
var thread = threads[i]; | |
if (!thread.isUnread()) { | |
continue; | |
} | |
var messages = thread.getMessages(); | |
for (var j = 0; j < messages.length; j++) { | |
var message = messages[j]; | |
if (!message || !message.isUnread()) { | |
continue; | |
} | |
var fields = getFields(message); | |
if (!fields) { | |
continue; | |
} | |
postSlack(fields); | |
message.markRead(); | |
} | |
thread.markRead(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage
1. Add
SlackApp
Resource > Library
M3W5Ut3Q39AaIwLquryEPMwV62A3znfOO
22
This script support version 22. Other versions are not supported.
2. Resolve configs
3. Set up trigger
Edit > Trigger of the current project
main
Time driven
,Minute timer
andEvery 10 minutes
See below example.
How to debug
This script checks your unread App Store Connect Status email. If you want to debug the script, you need to change the email's status to unread.
IMPORTANT
To receive App Store Connect Status email, you need to set your territory on
App Store Connect Use > Notifications > App Status Report
on App Store Connect.Reference(Japanese)
http://tech.mercari.com/entry/2017/12/21/143000
https://speakerdeck.com/motokiee/iosfalsezi-dong-hua-toshi-zu-mihua-kodotoshe-ji-niji-zhong-suru