markdown 从Google表单提交中创建一个新的GitHub问题
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 从Google表单提交中创建一个新的GitHub问题相关的知识,希望对你有一定的参考价值。
Wiring up a Google Form to GitHub is not that difficult with a little bit of [Apps Script](https://developers.google.com/apps-script/) automation. All you need is a Google account, a GitHub account, and a web browser...
### Set up your GitHub Personal Access Token
Personal access tokens provide an easy way to interact with the [GitHub API](https://developer.github.com/v3/) 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](https://github.com/settings/tokens) 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._
### Set up the Form & Spreadsheet
1. Create a [Google Form](https://www.google.com/forms/about/).
2. From the **Responses** tab, click the More icon.
3. Select **Choose a response destination**.
4. Select **New spreadsheet: Creates a new spreadsheet in Google Sheets for responses**.
5. 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.
2. Click **Tools > Script editor...** to launch the App Script editor coding environment. This Script will be [bound to your sheet](https://developers.google.com/apps-script/guides/bound), so you can listen for form submissions and fire off a new issue to your GitHub repo.
3. Delete the boilerplate code in the `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);
}
```
4. 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 (typically _Timestamp_).
5. In my example, I'm collecting information from users who wish to make license changes to a web service. I'm building a simple [markdown table](https://help.github.com/articles/github-flavored-markdown/#tables), which includes some of the form data in the body of my issue.
6. Reference the [GitHub Issues API](https://developer.github.com/v3/issues/#create-an-issue) for a full list of options for programmatically creating a new issue.
7. Once we've built the `title` and `body` of the issue, we can build the HTTP request using App Script's [URL Fetch Service](https://developers.google.com/apps-script/reference/url-fetch/).
8. 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**.
2. Click to add a trigger
- **Run**: onFormSubmit
- **Events**: From spreadsheet, On form submit
3. Click **Save** and accept any authorizations to access your forms and access web services on your behalf.
4. This trigger will listen to form submissions and pass the data to your function, which POSTs the new issue to your GitHub repo.
### Conclusion
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.
以上是关于markdown 从Google表单提交中创建一个新的GitHub问题的主要内容,如果未能解决你的问题,请参考以下文章