The Pocket Science Lab Android app has various functionalities which have been already implemented but it been on the verge of development, many functionalities are yet to be implemented completely, one such functionality is how the users report the issues of the app, to which comes the idea of using a Google form inside the app for the users to fill it and the issue get directly opened in Github.
Submitting a Github issue through a Google forms requires two things:-
-
- A Github access token which gives access to open a new issue.
-
-
- To generate a Github access token one must follow these steps[2]
- Go to the personal settings.
- To generate a Github access token one must follow these steps[2]
-
-
-
-
- Select Developers settings option from it.
- In Developers settings option Go to personal access tokens and generate an access token.
-
- A fully-structured Google form which has all the details about the issue i.e the title of the issue, the body of the issue, label, etc..
- Using a Google account create a Google Form which have all the relevant questions about that issue such as title of the issue, body of the issue, label etc..
-
Once done with all the steps follow these steps to send a Github issue[1]
-
- Click the Responses tab, in it click the More icon.
- Select Choose a response destination.
- Select New spreadsheet: Creates a new spreadsheet in Google Sheets for responses.
- Click Create to create and open the sheet.
Configure the App Script Logic[1]
-
- You should have a newly created blank spreadsheet with headers automatically generated from your form.
- Click Tools > Script editor… to launch the App Script editor coding environment. This Script will be bound to your sheet, so you can listen for form submissions and fire off a new issue to your GitHub repo.
- In the script editor write the following code
function onFormSubmit(e) {
var title = e.values[1];
var body = e.values[2];
var label = "User opened issue"
var payload = {
"title": title,
"body": a_body,
"label": label,
};
var options = {
"method": "POST",
"contentType": "application/json",
"payload": JSON.stringify(payload)
};
var response = UrlFetchApp.fetch("https://api.github.com/repos/abhinavraj23/AgeGroup/issues?access_token="+ghToken, options)
}
Note:The 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
The following google-app script uses GitHub Issues API for posting a new issue in Github.
4.Give your app script project a name and save it .
Set up the Trigger[1]
-
-
-
- From within the app script editor, click Resources > Current project’s triggers.
- Click to add a trigger
- Run: onFormSubmit
- Events: From spreadsheet, On form submit
- Click Save and accept any authorizations to access your forms and access web services on your behalf.
- This trigger will listen to form submissions and pass the data to your function, which POSTs the new issue to your GitHub repo.
-
-
Thus using these steps one can submit an issue in github through a Google Form and thus the Google Forms can be used in the app as the users can send the issues using a google form, and through this method one can also get the email-id of the user for further contact and thus this is a very useful method.
Resources
-
-
- Bmcbride, google-form-to-github-issue,gist.github.com: https://gist.github.com/bmcbride/62600e48274961819084#set-up-the-trigger
- Github help, Creating personal access token,help.github.com: https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/
-