Skip to content

Instantly share code, notes, and snippets.

@qmihara
Created November 7, 2018 09:01
Show Gist options
  • Save qmihara/d70a25e1c33ddf9caacb28f061086a82 to your computer and use it in GitHub Desktop.
Save qmihara/d70a25e1c33ddf9caacb28f061086a82 to your computer and use it in GitHub Desktop.
var MAIL_SEARCH_QUERY = '[from:[email protected] is:unread APP_NAME "has completed processing"]';
var BITRISE_APP_SLUG = APP_SLUG;
var BITRISE_BUILD_TRIGGER_TOKEN = BUILD_TRIGGER_TOKEN;
var BRANCH_NAME = BRANCH_NAME;
var WORKFLOW_NAME = WORKFLOW_NAME;
var executeBitriseWorkflow = function() {
var payload = {
"payload": {
"hook_info": {
"type": "bitrise",
"build_trigger_token": BITRISE_BUILD_TRIGGER_TOKEN
},
"build_params": {
"branch": BRANCH_NAME,
"workflow_id": WORKFLOW_NAME
}
}
};
var headers = {
"Content-Type": "application/json"
};
var options = {
"method": "POST",
"headers": headers,
"payload": JSON.stringify(payload)
};
var url = "https://app.bitrise.io/app/" + BITRISE_APP_SLUG + "/build/start.json";
UrlFetchApp.fetch(url, options);
};
function main() {
var threads = GmailApp.search(MAIL_SEARCH_QUERY);
if (threads.length == 0) {
return;
}
executeBitriseWorkflow();
for (var i = 0; i < threads.length; i++) {
var thread = threads[i];
thread.markRead();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment