From 4ef4cb4be06232b74875d479721798b327bcb2a2 Mon Sep 17 00:00:00 2001 From: Max Risuhin Date: Sun, 2 Sep 2018 22:33:33 +0300 Subject: [PATCH] Script to trigger new GitHub issue creation on new Google Web Form user's submit. Signed-off-by: Max Risuhin --- Code.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Code.js diff --git a/Code.js b/Code.js new file mode 100644 index 0000000..107371c --- /dev/null +++ b/Code.js @@ -0,0 +1,38 @@ +var ISSUE_TYPE_COLUMN = 0; +var DESCRIPTION_COLUMN = 1; +var GOOGLE_DISK_URL_COLUMN = 2; + +var scriptProperties = PropertiesService.getScriptProperties(); + +function valueByIdx(responses, columnIdx) { + return responses[columnIdx].getResponse(); +} + +function onFormSubmit(e) { + var itemResponses = e.response.getItemResponses(); + + var title = "StatusIm Desktop issue"; + var fileURL = "\n https://drive.google.com/open?id="; + if (valueByIdx(itemResponses, GOOGLE_DISK_URL_COLUMN).constructor === Array) { + fileURL = fileURL + valueByIdx(itemResponses, GOOGLE_DISK_URL_COLUMN).join(fileURL); + } else { + fileURL = fileURL + valueByIdx(itemResponses, GOOGLE_DISK_URL_COLUMN); + } + var body = "Issue type: " + valueByIdx(itemResponses, ISSUE_TYPE_COLUMN) + "\n" + + "Description: " + valueByIdx(itemResponses, DESCRIPTION_COLUMN) + "\n" + + "Uploaded files: " + fileURL + "\n"; + + var payload = { + "title": title, + "body": body + }; + + var options = { + "method": "POST", + "contentType": "application/json", + "payload": JSON.stringify(payload) + }; + + var response = UrlFetchApp.fetch("https://api.github.com/repos/status-im/status-react-desktop-reports/issues?access_token=" + scriptProperties.getProperty('GitHubToken'), options); +} +