Skip to content

WIP migrate to latest Firebase Functions #161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37,262 changes: 9,807 additions & 27,455 deletions functions/package-lock.json

Large diffs are not rendered by default.

69 changes: 33 additions & 36 deletions functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,45 @@
},
"main": "dist/index.js",
"dependencies": {
"@firebase/app": "^0.5.4",
"@google-cloud/bigquery": "^4.7.0",
"@google-cloud/logging": "^7.1.0",
"@google-cloud/pubsub": "^1.5.0",
"@octokit/plugin-retry": "^2.2.0",
"@octokit/rest": "^18.0.0",
"chalk": "^2.1.0",
"date-fns": "^1.28.5",
"diff": "^3.2.0",
"firebase-admin": "^9.2.0",
"firebase-functions": "^3.20.1",
"mailgun-js": "^0.22.0",
"marked": "^0.7.0",
"moment": "^2.29.4",
"mustache": "^2.3.0",
"node-fetch": "^3.1.1"
"@firebase/app": "^0.13.1",
"@google-cloud/bigquery": "^8.1.0",
"@google-cloud/logging": "^11.2.0",
"@google-cloud/pubsub": "^5.0.0",
"@octokit/plugin-retry": "^8.0.1",
"@octokit/rest": "^22.0.0",
"chalk": "^5.4.1",
"date-fns": "^4.1.0",
"diff": "^8.0.2",
"firebase-admin": "^13.4.0",
"firebase-functions": "^6.3.2",
"google-auth-library": "^9.15.1",
"mailgun-js": "^0.6.7",
"marked": "^15.0.12",
"moment": "^2.30.1",
"mustache": "^4.2.0",
"node-fetch": "^3.3.2"
},
"devDependencies": {
"@types/chai": "^4.0.1",
"@types/chalk": "^0.4.31",
"@types/diff": "^3.2.0",
"@types/duplexify": "^3.6.0",
"@types/marked": "0.0.28",
"@types/mocha": "^2.2.47",
"@types/mustache": "^0.8.29",
"@types/node": "^12.7.5",
"@types/node-fetch": "^2.1.2",
"@types/request": "^2.48.4",
"@types/chai": "^5.2.2",
"@types/duplexify": "^3.6.4",
"@types/mocha": "^10.0.10",
"@types/mustache": "^4.2.6",
"@types/node": "^22.15.30",
"@types/node-fetch": "^2.6.12",
"@types/request": "^2.48.12",
"@types/simple-mock": "^0.8.1",
"chai": "^4.1.2",
"firebase-tools": "^11.22.0",
"mjml": "^4.6.3",
"mocha": "^10.2.0",
"prettier": "^1.15.3",
"request": "^2.88.0",
"chai": "^5.2.0",
"firebase-tools": "^14.6.0",
"mjml": "^4.15.3",
"mocha": "^11.6.0",
"prettier": "^3.5.3",
"request": "^2.88.2",
"simple-mock": "^0.8.0",
"ts-lint": "^4.5.1",
"ts-node": "^8.4.1",
"ts-node": "^10.9.2",
"ts-server": "0.0.15",
"tslint": "^5.20.0",
"typescript": "^3.6.3",
"typings": "^2.1.1"
"tslint": "^6.1.3",
"typescript": "^5.8.3"
},
"scripts": {
"test": "mocha",
Expand Down
10 changes: 5 additions & 5 deletions functions/src/badge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const SamScoreBadge = functions.https.onRequest(async (req, res) => {
const openIssues = repoResp.data.open_issues_count;

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

Expand All @@ -26,10 +26,10 @@ export const SamScoreBadge = functions.https.onRequest(async (req, res) => {
samScore < 0.5
? "brightgreen"
: samScore < 1.0
? "green"
: samScore < 2.0
? "yellow"
: "red";
? "green"
: samScore < 2.0
? "yellow"
: "red";

// Construct the Shield URL
const shieldURL = `https://img.shields.io/static/v1?label=SAM%20Score&message=${samScore}&color=${color}`;
Expand Down
40 changes: 20 additions & 20 deletions functions/src/bigquery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ const ISSUES_SCHEMA: TableSchema = {
name: "user",
type: "RECORD",
mode: "NULLABLE",
fields: [{ name: "login", type: "STRING", mode: "NULLABLE" }]
fields: [{ name: "login", type: "STRING", mode: "NULLABLE" }],
},
{
name: "assignee",
type: "RECORD",
mode: "NULLABLE",
fields: [{ name: "login", type: "STRING", mode: "NULLABLE" }]
fields: [{ name: "login", type: "STRING", mode: "NULLABLE" }],
},
{ name: "labels", type: "STRING", mode: "REPEATED" },
{ name: "created_at", type: "STRING", mode: "NULLABLE" },
{ name: "updated_at", type: "STRING", mode: "NULLABLE" },
{ name: "ingested", type: "TIMESTAMP", mode: "NULLABLE" }
]
{ name: "ingested", type: "TIMESTAMP", mode: "NULLABLE" },
],
};

const EVENTS_DATASET = "github_events";
Expand All @@ -51,8 +51,8 @@ const EVENTS_SCHEMA: TableSchema = {
mode: "NULLABLE",
fields: [
{ name: "id", type: "INTEGER", mode: "NULLABLE" },
{ name: "login", type: "STRING", mode: "NULLABLE" }
]
{ name: "login", type: "STRING", mode: "NULLABLE" },
],
},

// The repository where the event ocurred
Expand All @@ -62,59 +62,59 @@ const EVENTS_SCHEMA: TableSchema = {
mode: "NULLABLE",
fields: [
{ name: "id", type: "INTEGER", mode: "NULLABLE" },
{ name: "full_name", type: "STRING", mode: "NULLABLE" }
]
{ name: "full_name", type: "STRING", mode: "NULLABLE" },
],
},

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

// The time the event was captured
{ name: "ingested", type: "TIMESTAMP", mode: "NULLABLE" }
]
{ name: "ingested", type: "TIMESTAMP", mode: "NULLABLE" },
],
};

const bqClient = new BigQuery({
projectId: process.env.GCLOUD_PROJECT
projectId: process.env.GCLOUD_PROJECT,
});

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

export async function createEventsTable(org: string): Promise<void> {
await bqClient.dataset(EVENTS_DATASET).createTable(org, {
schema: EVENTS_SCHEMA
schema: EVENTS_SCHEMA,
});
}

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

export async function createIssuesTable(org: string): Promise<void> {
await bqClient.dataset(ISSUES_DATASET).createTable(org, {
schema: ISSUES_SCHEMA
schema: ISSUES_SCHEMA,
});

await bqClient.dataset(ISSUES_DATASET).createTable(`${org}_view`, {
view: {
query: getIssuesViewSql(org),
useLegacySql: false
}
useLegacySql: false,
},
});
}

export async function insertIssues(
org: string,
repo: string,
issueData: snapshot.Issue[],
ingested: Date
ingested: Date,
) {
const issues = Object.values(issueData).map(
i => new bigquery.Issue(i, repo, ingested)
(i) => new bigquery.Issue(i, repo, ingested),
);

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

export async function insertEvent(org: string, event: bigquery.Event) {
log.debug(
`Inserting event ${event.type}.${event.action} in org ${org} into BigQuery`
`Inserting event ${event.type}.${event.action} in org ${org} into BigQuery`,
);
log.debug("event", event);
const insertRes = await bqClient
Expand Down
26 changes: 13 additions & 13 deletions functions/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class BotConfig {
for (const name in this.config[org]) {
repos.push({
org: org,
name: name
name: name,
});
}
}
Expand All @@ -96,7 +96,7 @@ export class BotConfig {
custom_emails: false,
issue_labels: false,
issue_cleanup: false,
repo_reports: false
repo_reports: false,
};

const config = this.getRepoConfig(org, name);
Expand Down Expand Up @@ -150,7 +150,7 @@ export class BotConfig {
getRepoLabelConfig(
org: string,
name: string,
label: string
label: string,
): types.LabelConfig | undefined {
const repoConfig = this.getRepoConfig(org, name);

Expand All @@ -166,7 +166,7 @@ export class BotConfig {
getRepoTemplateConfig(
org: string,
name: string,
template: string
template: string,
): string | undefined {
const repoConfig = this.getRepoConfig(org, name);

Expand All @@ -185,7 +185,7 @@ export class BotConfig {
*/
getRepoReportingConfig(
org: string,
name: string
name: string,
): types.ReportConfig | undefined {
const repoConfig = this.getRepoConfig(org, name);

Expand All @@ -199,7 +199,7 @@ export class BotConfig {
*/
getRepoCleanupConfig(
org: string,
name: string
name: string,
): types.CleanupConfig | undefined {
const repoConfig = this.getRepoConfig(org, name);
if (repoConfig && repoConfig.cleanup) {
Expand All @@ -213,7 +213,7 @@ export class BotConfig {
getRepoTemplateValidationConfig(
org: string,
name: string,
templatePath: string
templatePath: string,
): types.TemplateValidationConfig | undefined {
const repoConfig = this.getRepoConfig(org, name);
if (repoConfig && repoConfig.validation) {
Expand All @@ -227,15 +227,15 @@ export class BotConfig {
getRelevantLabel(
org: string,
name: string,
issue: types.internal.IssueOrPullRequest
issue: types.internal.IssueOrPullRequest,
): RelevantLabelResponse {
// Make sure we at least have configuration for this repository
const repo_mapping = this.getRepoConfig(org, name);
if (!repo_mapping) {
log.debug(`No config for ${org}/${name} in: `, this.config);

return {
error: "No config found"
error: "No config found",
};
}

Expand All @@ -244,7 +244,7 @@ export class BotConfig {

// Iterate through issue labels, see if one of the existing ones works
// TODO(samstern): Deal with needs_triage separately
const issueLabelNames: string[] = issue.labels.map(label => {
const issueLabelNames: string[] = issue.labels.map((label) => {
return label.name;
});

Expand All @@ -253,7 +253,7 @@ export class BotConfig {
if (label_mapping) {
return {
label: key,
new: false
new: false,
};
}
}
Expand All @@ -279,7 +279,7 @@ export class BotConfig {
return {
label,
new: true,
matchedRegex: regex.source
matchedRegex: regex.source,
};
} else {
log.debug(`Did not match regex for ${label}: ${labelInfo.regex}`);
Expand All @@ -289,7 +289,7 @@ export class BotConfig {
// Return undefined if none found
log.debug("No relevant label found");
return {
label: undefined
label: undefined,
};
}

Expand Down
Loading
Loading