Skip to content

Commit de43c45

Browse files
committed
Upgrade to microfeedback-core 2
1 parent 5a87ff6 commit de43c45

5 files changed

Lines changed: 1565 additions & 43 deletions

File tree

app.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@
1111
"description": "Comma-separated list of GitHub repos that may be posted to. If '*', allow posting to any repo.",
1212
"required": false,
1313
"value": "*"
14+
},
15+
"AKISMET_API_KEY": {
16+
"description": "Akismet API key to use for spam detection",
17+
"required": false
18+
},
19+
"ENABLE_AKISMET": {
20+
"description": "Whether to use the Akismet API for syntax checking. Set to 'false' if AKISMET_API_KEY is set but you don't want spam checking.",
21+
"required": false
22+
},
23+
"PERSPECTIVE_API_KEY": {
24+
"description": "Perspective API key to use for toxicity scoring",
25+
"required": false
26+
},
27+
"ENABLE_PERSPECTIVE": {
28+
"description": "Whether to use the Perspective API for toxicity scoring. Set to 'false' if PERSPECTIVE_API_KEY is set but you don't want toxicity scoring.",
29+
"required": false
1430
}
1531
},
1632
"buildpacks": [

index.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ const issueTemplate = `
6161
{{&osTable}}
6262
{{/osTable}}
6363
64+
{{#perspectiveTable}}
65+
### Perspective API
66+
67+
{{&perspectiveTable}}
68+
{{/perspectiveTable}}
69+
6470
{{#extraTable}}
6571
### Extra information
6672
@@ -75,7 +81,7 @@ Reported via *[{{pkg.name}}]({{&pkg.repository}}) v{{pkg.version}}*.
7581
`;
7682
mustache.parse(issueTemplate);
7783

78-
const makeIssue = ({body, extra, screenshotURL}, req) => {
84+
const makeIssue = ({body, extra, perspective, screenshotURL}, req) => {
7985
let suffix = '';
8086
if (req && req.headers.referer) {
8187
suffix = ` on ${req.headers.referer}`;
@@ -106,10 +112,15 @@ const makeIssue = ({body, extra, screenshotURL}, req) => {
106112
const osEntries = Object.entries(userAgent.os).filter(e => e[1]);
107113
view.osTable = makeTable(['Key', 'Value'], osEntries, false);
108114
}
115+
// Format perspective information as table
116+
if (perspective) {
117+
view.perspectiveTable = makeTable(['Key', 'Value'], Object.entries(perspective));
118+
}
109119
// Format extra information as table
110120
if (extra) {
111121
view.extraTable = makeTable(['Key', 'Value'], Object.entries(extra));
112122
}
123+
// TODO: Add spam label if akismet.spam is true
113124
return {title, body: mustache.render(issueTemplate, view)};
114125
};
115126

@@ -120,7 +131,7 @@ function getAllowedRepos() {
120131
return process.env.ALLOWED_REPOS.split(',').map(each => each.trim());
121132
}
122133

123-
const GitHubBackend = async (input, req) => {
134+
const GitHubBackend = async ({input, perspective, akismet}, req) => {
124135
// Match /<username>/<repo>/ in the URL
125136
// TODO: Allow base64-encoded repo URL
126137
const {pathname} = url.parse(req.url);
@@ -131,14 +142,21 @@ const GitHubBackend = async (input, req) => {
131142
throw createError(400, `Repo "${repo}" not allowed.`);
132143
}
133144
const issueURL = `https://api.github.com/repos/${repo}/issues`;
145+
const {body, extra, screenshotURL} = input;
134146
try {
135147
const {data} = await axios({
136148
method: 'POST',
137149
url: issueURL,
138150
params: {
139151
access_token: GH_TOKEN,
140152
},
141-
data: makeIssue(input, req),
153+
data: makeIssue({
154+
body,
155+
extra,
156+
screenshotURL,
157+
perspective,
158+
akismet,
159+
}, req),
142160
});
143161
return data;
144162
} catch (err) {

0 commit comments

Comments
 (0)