Create a new GitHub Issue from a Google Form submission
Wiring up a Google Form to GitHub is not that difficult with a little bit of Apps Script automation. All you need is a Google account, a GitHub account, and a web browser...
Personal access tokens provide an easy way to interact with the GitHub API without having to mess with OAuth. If you don't already have a personal access token with repo or public_repo access, visit your GitHub settings page and generate a new token.
Be sure to copy your token some place safe and keep it secure. Once generated, you will not be able to view or copy the token again.
Code.gs
file and replace it with something similar to this:var ghToken = "my-personal-access-token";
function onFormSubmit(e) {
var title = e.values[2] + ": " + e.values[4];
var body = "| Contact Email | Organization Name | Change Date | Change Type | Plan | Licenses | Comments |\n" +
"|---|---|---|---|---|---|---|\n" +
"| "+e.values[1]+" | "+e.values[2]+" | "+e.values[3]+" | "+e.values[4]+" | "+e.values[5]+" | "+e.values[6]+" | "+e.values[7]+" |" ;
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/bmcbride/my-repo/issues?access_token="+ghToken, options);
}
onFormSubmit
function includes an event object e
, which includes the form/spreadsheet field values
as a simple array with values in the same order as they appear in the spreadsheet. e.values[0]
is the first spreadsheet column (typically Timestamp).title
and body
of the issue, we can build the HTTP request using App Script's URL Fetch Service.This exercise demonstrates how to utilize Google Forms as a front-end for capturing information, which can then be passed on to other services, such as GitHub, CartoDB, Fulcrum, etc.