Skip to content

Commit bb7126d

Browse files
authored
Merge pull request #161 from firebase/mc/cron-failure
migrate to latest Firebase Functions
2 parents 3487e3c + 8a6592d commit bb7126d

29 files changed

+10882
-28188
lines changed

functions/.mocharc.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"loader": "ts-node/esm",
3+
"extensions": ["ts"]
4+
}

functions/package-lock.json

Lines changed: 9919 additions & 27511 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

functions/package.json

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,46 @@
66
},
77
"main": "dist/index.js",
88
"dependencies": {
9-
"@firebase/app": "^0.5.4",
10-
"@google-cloud/bigquery": "^4.7.0",
11-
"@google-cloud/logging": "^7.1.0",
12-
"@google-cloud/pubsub": "^1.5.0",
13-
"@octokit/plugin-retry": "^2.2.0",
14-
"@octokit/rest": "^18.0.0",
15-
"chalk": "^2.1.0",
16-
"date-fns": "^1.28.5",
17-
"diff": "^3.2.0",
18-
"firebase-admin": "^9.2.0",
19-
"firebase-functions": "^3.20.1",
20-
"mailgun-js": "^0.22.0",
21-
"marked": "^0.7.0",
22-
"moment": "^2.29.4",
23-
"mustache": "^2.3.0",
24-
"node-fetch": "^3.1.1"
9+
"@firebase/app": "^0.13.1",
10+
"@google-cloud/bigquery": "^8.1.0",
11+
"@google-cloud/logging": "^11.2.0",
12+
"@google-cloud/pubsub": "^5.0.0",
13+
"@octokit/plugin-retry": "^8.0.1",
14+
"@octokit/rest": "^22.0.0",
15+
"chalk": "^5.4.1",
16+
"date-fns": "^4.1.0",
17+
"diff": "^8.0.2",
18+
"firebase-admin": "^13.4.0",
19+
"firebase-functions": "^6.3.2",
20+
"google-auth-library": "^9.15.1",
21+
"mailgun-js": "^0.6.7",
22+
"marked": "^15.0.12",
23+
"moment": "^2.30.1",
24+
"mustache": "^4.2.0",
25+
"node-fetch": "^3.3.2"
2526
},
2627
"devDependencies": {
27-
"@types/chai": "^4.0.1",
28-
"@types/chalk": "^0.4.31",
29-
"@types/diff": "^3.2.0",
30-
"@types/duplexify": "^3.6.0",
31-
"@types/marked": "0.0.28",
32-
"@types/mocha": "^2.2.47",
33-
"@types/mustache": "^0.8.29",
34-
"@types/node": "^12.7.5",
35-
"@types/node-fetch": "^2.1.2",
36-
"@types/request": "^2.48.4",
28+
"@types/chai": "^5.2.2",
29+
"@types/duplexify": "^3.6.4",
30+
"@types/express": "^5.0.3",
31+
"@types/mocha": "^10.0.10",
32+
"@types/mustache": "^4.2.6",
33+
"@types/node": "^22.15.30",
34+
"@types/node-fetch": "^2.6.12",
35+
"@types/request": "^2.48.12",
3736
"@types/simple-mock": "^0.8.1",
38-
"chai": "^4.1.2",
39-
"firebase-tools": "^11.22.0",
40-
"mjml": "^4.6.3",
41-
"mocha": "^10.2.0",
42-
"prettier": "^1.15.3",
43-
"request": "^2.88.0",
37+
"chai": "^5.2.0",
38+
"firebase-tools": "^14.6.0",
39+
"mjml": "^4.15.3",
40+
"mocha": "^11.6.0",
41+
"prettier": "^3.5.3",
42+
"request": "^2.88.2",
4443
"simple-mock": "^0.8.0",
4544
"ts-lint": "^4.5.1",
46-
"ts-node": "^8.4.1",
45+
"ts-node": "^10.9.2",
4746
"ts-server": "0.0.15",
48-
"tslint": "^5.20.0",
49-
"typescript": "^3.6.3",
50-
"typings": "^2.1.1"
47+
"tslint": "^6.1.3",
48+
"typescript": "^5.8.3"
5149
},
5250
"scripts": {
5351
"test": "mocha",

functions/src/badge.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const SamScoreBadge = functions.https.onRequest(async (req, res) => {
1717
const openIssues = repoResp.data.open_issues_count;
1818

1919
const searchResp = await api.search.issuesAndPullRequests({
20-
q: `repo:${org}/${repo} type:issue state:closed`
20+
q: `repo:${org}/${repo} type:issue state:closed`,
2121
});
2222
const closedIssues = searchResp.data.total_count;
2323

@@ -26,10 +26,10 @@ export const SamScoreBadge = functions.https.onRequest(async (req, res) => {
2626
samScore < 0.5
2727
? "brightgreen"
2828
: samScore < 1.0
29-
? "green"
30-
: samScore < 2.0
31-
? "yellow"
32-
: "red";
29+
? "green"
30+
: samScore < 2.0
31+
? "yellow"
32+
: "red";
3333

3434
// Construct the Shield URL
3535
const shieldURL = `https://img.shields.io/static/v1?label=SAM%20Score&message=${samScore}&color=${color}`;

functions/src/bigquery.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ const ISSUES_SCHEMA: TableSchema = {
1717
name: "user",
1818
type: "RECORD",
1919
mode: "NULLABLE",
20-
fields: [{ name: "login", type: "STRING", mode: "NULLABLE" }]
20+
fields: [{ name: "login", type: "STRING", mode: "NULLABLE" }],
2121
},
2222
{
2323
name: "assignee",
2424
type: "RECORD",
2525
mode: "NULLABLE",
26-
fields: [{ name: "login", type: "STRING", mode: "NULLABLE" }]
26+
fields: [{ name: "login", type: "STRING", mode: "NULLABLE" }],
2727
},
2828
{ name: "labels", type: "STRING", mode: "REPEATED" },
2929
{ name: "created_at", type: "STRING", mode: "NULLABLE" },
3030
{ name: "updated_at", type: "STRING", mode: "NULLABLE" },
31-
{ name: "ingested", type: "TIMESTAMP", mode: "NULLABLE" }
32-
]
31+
{ name: "ingested", type: "TIMESTAMP", mode: "NULLABLE" },
32+
],
3333
};
3434

3535
const EVENTS_DATASET = "github_events";
@@ -51,8 +51,8 @@ const EVENTS_SCHEMA: TableSchema = {
5151
mode: "NULLABLE",
5252
fields: [
5353
{ name: "id", type: "INTEGER", mode: "NULLABLE" },
54-
{ name: "login", type: "STRING", mode: "NULLABLE" }
55-
]
54+
{ name: "login", type: "STRING", mode: "NULLABLE" },
55+
],
5656
},
5757

5858
// The repository where the event ocurred
@@ -62,59 +62,59 @@ const EVENTS_SCHEMA: TableSchema = {
6262
mode: "NULLABLE",
6363
fields: [
6464
{ name: "id", type: "INTEGER", mode: "NULLABLE" },
65-
{ name: "full_name", type: "STRING", mode: "NULLABLE" }
66-
]
65+
{ name: "full_name", type: "STRING", mode: "NULLABLE" },
66+
],
6767
},
6868

6969
// The full JSON payload of the event
7070
{ name: "payload", type: "STRING", mode: "NULLABLE" },
7171

7272
// The time the event was captured
73-
{ name: "ingested", type: "TIMESTAMP", mode: "NULLABLE" }
74-
]
73+
{ name: "ingested", type: "TIMESTAMP", mode: "NULLABLE" },
74+
],
7575
};
7676

7777
const bqClient = new BigQuery({
78-
projectId: process.env.GCLOUD_PROJECT
78+
projectId: process.env.GCLOUD_PROJECT,
7979
});
8080

8181
export async function listEventsTables(): Promise<string[]> {
8282
const [tables] = await bqClient.dataset(EVENTS_DATASET).getTables();
83-
return tables.map(x => x.id || "");
83+
return tables.map((x) => x.id || "");
8484
}
8585

8686
export async function createEventsTable(org: string): Promise<void> {
8787
await bqClient.dataset(EVENTS_DATASET).createTable(org, {
88-
schema: EVENTS_SCHEMA
88+
schema: EVENTS_SCHEMA,
8989
});
9090
}
9191

9292
export async function listIssuesTables(): Promise<string[]> {
9393
const [tables] = await bqClient.dataset(ISSUES_DATASET).getTables();
94-
return tables.map(x => x.id || "");
94+
return tables.map((x) => x.id || "");
9595
}
9696

9797
export async function createIssuesTable(org: string): Promise<void> {
9898
await bqClient.dataset(ISSUES_DATASET).createTable(org, {
99-
schema: ISSUES_SCHEMA
99+
schema: ISSUES_SCHEMA,
100100
});
101101

102102
await bqClient.dataset(ISSUES_DATASET).createTable(`${org}_view`, {
103103
view: {
104104
query: getIssuesViewSql(org),
105-
useLegacySql: false
106-
}
105+
useLegacySql: false,
106+
},
107107
});
108108
}
109109

110110
export async function insertIssues(
111111
org: string,
112112
repo: string,
113113
issueData: snapshot.Issue[],
114-
ingested: Date
114+
ingested: Date,
115115
) {
116116
const issues = Object.values(issueData).map(
117-
i => new bigquery.Issue(i, repo, ingested)
117+
(i) => new bigquery.Issue(i, repo, ingested),
118118
);
119119

120120
if (issues.length === 0) {
@@ -132,7 +132,7 @@ export async function insertIssues(
132132

133133
export async function insertEvent(org: string, event: bigquery.Event) {
134134
log.debug(
135-
`Inserting event ${event.type}.${event.action} in org ${org} into BigQuery`
135+
`Inserting event ${event.type}.${event.action} in org ${org} into BigQuery`,
136136
);
137137
log.debug("event", event);
138138
const insertRes = await bqClient

functions/src/config.ts

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export class BotConfig {
8080
for (const name in this.config[org]) {
8181
repos.push({
8282
org: org,
83-
name: name
83+
name: name,
8484
});
8585
}
8686
}
@@ -96,7 +96,7 @@ export class BotConfig {
9696
custom_emails: false,
9797
issue_labels: false,
9898
issue_cleanup: false,
99-
repo_reports: false
99+
repo_reports: false,
100100
};
101101

102102
const config = this.getRepoConfig(org, name);
@@ -150,7 +150,7 @@ export class BotConfig {
150150
getRepoLabelConfig(
151151
org: string,
152152
name: string,
153-
label: string
153+
label: string,
154154
): types.LabelConfig | undefined {
155155
const repoConfig = this.getRepoConfig(org, name);
156156

@@ -166,7 +166,7 @@ export class BotConfig {
166166
getRepoTemplateConfig(
167167
org: string,
168168
name: string,
169-
template: string
169+
template: string,
170170
): string | undefined {
171171
const repoConfig = this.getRepoConfig(org, name);
172172

@@ -185,7 +185,7 @@ export class BotConfig {
185185
*/
186186
getRepoReportingConfig(
187187
org: string,
188-
name: string
188+
name: string,
189189
): types.ReportConfig | undefined {
190190
const repoConfig = this.getRepoConfig(org, name);
191191

@@ -199,7 +199,7 @@ export class BotConfig {
199199
*/
200200
getRepoCleanupConfig(
201201
org: string,
202-
name: string
202+
name: string,
203203
): types.CleanupConfig | undefined {
204204
const repoConfig = this.getRepoConfig(org, name);
205205
if (repoConfig && repoConfig.cleanup) {
@@ -213,7 +213,7 @@ export class BotConfig {
213213
getRepoTemplateValidationConfig(
214214
org: string,
215215
name: string,
216-
templatePath: string
216+
templatePath: string,
217217
): types.TemplateValidationConfig | undefined {
218218
const repoConfig = this.getRepoConfig(org, name);
219219
if (repoConfig && repoConfig.validation) {
@@ -227,15 +227,15 @@ export class BotConfig {
227227
getRelevantLabel(
228228
org: string,
229229
name: string,
230-
issue: types.internal.IssueOrPullRequest
230+
issue: types.internal.IssueOrPullRequest,
231231
): RelevantLabelResponse {
232232
// Make sure we at least have configuration for this repository
233233
const repo_mapping = this.getRepoConfig(org, name);
234234
if (!repo_mapping) {
235235
log.debug(`No config for ${org}/${name} in: `, this.config);
236236

237237
return {
238-
error: "No config found"
238+
error: "No config found",
239239
};
240240
}
241241

@@ -244,16 +244,27 @@ export class BotConfig {
244244

245245
// Iterate through issue labels, see if one of the existing ones works
246246
// TODO(samstern): Deal with needs_triage separately
247-
const issueLabelNames: string[] = issue.labels.map(label => {
248-
return label.name;
249-
});
247+
const issueLabelNames: (string | undefined)[] = issue.labels
248+
.filter((label) => {
249+
return label !== undefined;
250+
})
251+
.map((label) => {
252+
if (typeof label === "string") {
253+
return label;
254+
}
255+
return label.name;
256+
});
250257

251258
for (const key of issueLabelNames) {
259+
if (!key) {
260+
// After typescript 5.5 this check can be removed?
261+
continue;
262+
}
252263
const label_mapping = this.getRepoLabelConfig(org, name, key);
253264
if (label_mapping) {
254265
return {
255266
label: key,
256-
new: false
267+
new: false,
257268
};
258269
}
259270
}
@@ -274,12 +285,12 @@ export class BotConfig {
274285
const regex = new RegExp(labelInfo.regex);
275286

276287
// If the regex matches, choose the label and email then break out
277-
if (regex.test(issue.body)) {
288+
if (regex.test(issue.body ?? "")) {
278289
log.debug("Matched label: " + label, JSON.stringify(labelInfo));
279290
return {
280291
label,
281292
new: true,
282-
matchedRegex: regex.source
293+
matchedRegex: regex.source,
283294
};
284295
} else {
285296
log.debug(`Did not match regex for ${label}: ${labelInfo.regex}`);
@@ -289,7 +300,7 @@ export class BotConfig {
289300
// Return undefined if none found
290301
log.debug("No relevant label found");
291302
return {
292-
label: undefined
303+
label: undefined,
293304
};
294305
}
295306

0 commit comments

Comments
 (0)