Skip to content
This repository was archived by the owner on Jan 19, 2024. It is now read-only.
Merged
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
8 changes: 4 additions & 4 deletions functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
"main": "lib/index.js",
"dependencies": {
"@firebase/app-types": "0.3.2",
"firebase-admin": "6.0.0",
"firebase-functions": "2.0.5",
"firebase-admin": "6.4.0",
"firebase-functions": "2.1.0",
"minimatch": "3.0.4",
"node-fetch": "2.2.0",
"probot": "7.3.1"
"probot": "7.4.0"
},
"devDependencies": {
"tslint": "5.11.0",
"typescript": "3.1.3"
"typescript": "3.2.2"
},
"private": true
}
2 changes: 1 addition & 1 deletion functions/src/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export interface MergeConfig {
};
mergeConflictComment: string;
mergeLabel: string;
mergeLinkedLabels: string[];
mergeLinkedLabels?: string[];
checks: {
noConflict: boolean;
requireReviews: boolean;
Expand Down
10 changes: 5 additions & 5 deletions functions/src/plugins/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ export class CommonTask extends Task {
const adminConfig = await this.admin.doc('config').get();
if(adminConfig.exists && (<AdminConfig>adminConfig.data()).allowInit) {
const github = await this.robot.auth();
const installations = await github.paginate(github.apps.getInstallations({}), pages => pages.data);
const installations = await github.paginate(github.apps.listInstallations({}), pages => (pages as any as Github.AnyResponse).data);
await Promise.all(installations.map(async installation => {
const authGithub = await this.robot.auth(installation.id);
const repositories = await authGithub.apps.getInstallationRepositories({});
await Promise.all(repositories.data.repositories.map(async (repository: Github.AppsGetInstallationRepositoriesResponseRepositoriesItem) => {
const repositories = await authGithub.apps.listRepos({});
await Promise.all(repositories.data.repositories.map(async (repository: Github.AppsListReposResponseRepositoriesItem) => {
await this.repositories.doc(repository.id.toString()).set({
id: repository.id,
name: repository.name,
Expand Down Expand Up @@ -97,12 +97,12 @@ export class CommonTask extends Task {
// list of existing opened PRs in the db
const dbPRs = dbPRSnapshots.docs.map(doc => doc.id);

const ghPRs = await github.paginate(github.pullRequests.getAll({
const ghPRs = await github.paginate(github.pullRequests.list({
owner,
repo,
state: 'open',
per_page: 100
}), pages => pages.data) as Github.PullRequestsGetAllResponse;
}), pages => (pages as any as Github.AnyResponse).data) as Github.PullRequestsListResponse;

ghPRs.forEach(async pr => {
const index = dbPRs.indexOf(pr.id.toString());
Expand Down
173 changes: 70 additions & 103 deletions functions/src/plugins/merge.ts

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions functions/src/plugins/size.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fetch from 'node-fetch';
import {Application, Context} from "probot";
import {Task} from "./task";
import {SizeConfig, appConfig as defaultAppConfig } from "../default";
import {SizeConfig, appConfig as defaultAppConfig, AppConfig} from "../default";
import {STATUS_STATE} from "../typings";
import Github from '@octokit/rest';

Expand Down Expand Up @@ -50,7 +50,7 @@ export class SizeTask extends Task {
}

async checkSize(context: Context): Promise<void> {
const appConfig = await context.config(CONFIG_FILE);
const appConfig = await context.config<AppConfig>(CONFIG_FILE);

if(!appConfig.size || appConfig.size.disabled) {
return;
Expand Down Expand Up @@ -179,7 +179,7 @@ export class SizeTask extends Task {

if (commentId !== undefined) {
try {
await context.github.issues.editComment({
await context.github.issues.updateComment({
owner,
repo,
comment_id: commentId,
Expand Down Expand Up @@ -223,11 +223,11 @@ export class SizeTask extends Task {
* @param artifacts
*/
async upsertNewArtifacts(context: Context, artifacts: BuildArtifact[]): Promise<void> {
this.logDebug(`[size] Storing artifacts for: ${context.payload.sha}, on branches [${context.payload.branches.map((b: Github.ReposGetBranchesResponseItem) => b.commit.url).join(', ')}]`);
this.logDebug(`[size] Storing artifacts for: ${context.payload.sha}, on branches [${context.payload.branches.map((b: Github.ReposListBranchesResponseItem) => b.commit.url).join(', ')}]`);

const updatedAt = context.payload.updated_at;
const branch = context.payload.branches
.find((b: Github.ReposGetBranchesResponseItem) => b.commit.sha === context.payload.commit.sha);
.find((b: Github.ReposListBranchesResponseItem) => b.commit.sha === context.payload.commit.sha);
const sizeArtifacts = this.repositories
.doc(context.payload.repository.id.toString())
.collection('sizeArtifacts');
Expand All @@ -238,7 +238,7 @@ export class SizeTask extends Task {
));

return sizeArtifacts.firestore.runTransaction(async transaction => {
const results = await transaction.getAll(...artifactDocs);
const results = await transaction.getAll(...artifactDocs as [any]);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to force this type to any, because Typescript throws an error saying that it "Expected at least 1 arguments, but got 0 or more.". Apparently it doesn't handle length on spread arrays very well.


for(let i = 0; i < results.length; ++i) {
if(results[i].exists) {
Expand Down
10 changes: 0 additions & 10 deletions functions/src/plugins/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,4 @@ export class Task {

return context.github.query(getResource, {url: resource.html_url});
}

async queryPR<T>(context: Context, query: string, params: { [key: string]: any, owner: string, repo: string, number: number }): Promise<T> {
return (await context.github.query(`query($owner: String!, $repo: String!, $number: Int!) {
repository(owner: $owner, name: $repo) {
pullRequest(number: $number) {
${query}
}
}
}`, params) as any).repository.pullRequest;
}
}
24 changes: 12 additions & 12 deletions functions/src/plugins/triage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,34 @@ export class TriageTask extends Task {
const adminConfig = await this.admin.doc('config').get();
if(adminConfig.exists && (<AdminConfig>adminConfig.data()).allowInit) {
const github = await this.robot.auth();
const installations = await github.paginate(github.apps.getInstallations({}), pages => pages.data);
const installations = await github.paginate(github.apps.listInstallations({}), pages => (pages as any as Github.AnyResponse).data);
await Promise.all(installations.map(async installation => {
const authGithub = await this.robot.auth(installation.id);
const repositories = await authGithub.apps.getInstallationRepositories({});
await Promise.all(repositories.data.repositories.map(async (repository: Github.AppsGetInstallationRepositoriesResponseRepositoriesItem) => {
const repositories = await authGithub.apps.listRepos({});
await Promise.all(repositories.data.repositories.map(async (repository: Github.AppsListReposResponseRepositoriesItem) => {
const context = new Context({payload: {repository}}, authGithub, this.robot.log);
const config = await this.getConfig(context);
if(config.disabled) {
return;
}
const {owner, repo} = context.repo();
const issues = await authGithub.paginate(authGithub.issues.getForRepo({
const issues = await authGithub.paginate(authGithub.issues.listForRepo({
owner,
repo,
state: 'open',
per_page: 100
}), page => page.data);
}), pages => (pages as any as Github.AnyResponse).data);

issues.forEach(async (issue: Github.IssuesGetForRepoResponseItem) => {
issues.forEach(async (issue: Github.IssuesListForRepoResponseItem) => {
// PRs are issues for github, but we don't want them here
if(!issue.pull_request) {
const isL1Triaged = this.isTriaged(config.l1TriageLabels, issue.labels.map((label: Github.IssuesGetForRepoResponseItemLabelsItem) => label.name));
const isL1Triaged = this.isTriaged(config.l1TriageLabels, issue.labels.map((label: Github.IssuesListForRepoResponseItemLabelsItem) => label.name));
if(!isL1Triaged) {
if(issue.milestone) {
await this.setMilestone(null, context.github, owner, repo, issue);
}
} else if(!issue.milestone || issue.milestone.number === config.defaultMilestone || issue.milestone.number === config.needsTriageMilestone) {
const isL2Triaged = this.isTriaged(config.l2TriageLabels || config.triagedLabels, issue.labels.map((label: Github.IssuesGetForRepoResponseItemLabelsItem) => label.name));
const isL2Triaged = this.isTriaged(config.l2TriageLabels || config.triagedLabels, issue.labels.map((label: Github.IssuesListForRepoResponseItemLabelsItem) => label.name));
if(isL2Triaged) {
if(!issue.milestone || issue.milestone.number !== config.defaultMilestone) {
await this.setMilestone(config.defaultMilestone, context.github, owner, repo, issue);
Expand Down Expand Up @@ -102,13 +102,13 @@ export class TriageTask extends Task {
}
}

setMilestone(milestoneNumber: number | null, github: Github, owner: string, repo: string, issue: Github.IssuesGetForRepoResponseItem): Promise<Github.Response<Github.IssuesEditResponse>> {
setMilestone(milestoneNumber: number | null, github: Github, owner: string, repo: string, issue: Github.IssuesListForRepoResponseItem): Promise<Github.Response<Github.IssuesUpdateResponse>> {
if(milestoneNumber) {
this.log(`Adding milestone ${milestoneNumber} to issue ${issue.html_url}`);
} else {
this.log(`Removing milestone from issue ${issue.html_url}`);
}
return github.issues.edit({owner, repo, number: issue.number, milestone: milestoneNumber}).catch(err => {
return github.issues.update({owner, repo, number: issue.number, milestone: milestoneNumber}).catch(err => {
throw err;
});
}
Expand All @@ -123,8 +123,8 @@ export class TriageTask extends Task {
async getConfig(context: Context): Promise<TriageConfig> {
const repositoryConfig = await context.config<AppConfig>(CONFIG_FILE, appConfig);
const config = repositoryConfig.triage;
config.defaultMilestone = parseInt(config.defaultMilestone, 10);
config.needsTriageMilestone = parseInt(config.needsTriageMilestone, 10);
config.defaultMilestone = parseInt(<unknown>config.defaultMilestone as string, 10);
config.needsTriageMilestone = parseInt(<unknown>config.needsTriageMilestone as string, 10);
return config;
}
}
24 changes: 12 additions & 12 deletions functions/src/plugins/triagePR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,34 @@ export class TriagePRTask extends Task {
const adminConfig = await this.admin.doc('config').get();
if(adminConfig.exists && (<AdminConfig>adminConfig.data()).allowInit) {
const github = await this.robot.auth();
const installations = await github.paginate(github.apps.getInstallations({}), pages => pages.data);
const installations = await github.paginate(github.apps.listInstallations({}), pages => (pages as any as Github.AnyResponse).data);
await Promise.all(installations.map(async installation => {
const authGithub = await this.robot.auth(installation.id);
const repositories = await authGithub.apps.getInstallationRepositories({});
await Promise.all(repositories.data.repositories.map(async (repository: Github.AppsGetInstallationRepositoriesResponseRepositoriesItem) => {
const repositories = await authGithub.apps.listRepos({});
await Promise.all(repositories.data.repositories.map(async (repository: Github.AppsListReposResponseRepositoriesItem) => {
const context = new Context({payload: {repository}}, authGithub, this.robot.log);
const config = await this.getConfig(context);
if(config.disabled) {
return;
}
const {owner, repo} = context.repo();
const issues = await authGithub.paginate(authGithub.issues.getForRepo({
const issues = await authGithub.paginate(authGithub.issues.listForRepo({
owner,
repo,
state: 'open',
per_page: 100
}), page => page.data);
}), pages => (pages as any as Github.AnyResponse).data);

issues.forEach(async (issue: Github.IssuesGetForRepoResponseItem) => {
issues.forEach(async (issue: Github.IssuesListForRepoResponseItem) => {
// We only want the PRs, not the issues
if(issue.pull_request) {
const isL1Triaged = this.isTriaged(config.l1TriageLabels, issue.labels.map((label: Github.IssuesGetForRepoResponseItemLabelsItem) => label.name));
const isL1Triaged = this.isTriaged(config.l1TriageLabels, issue.labels.map((label: Github.IssuesListForRepoResponseItemLabelsItem) => label.name));
if(!isL1Triaged) {
if(issue.milestone) {
await this.setMilestone(null, context.github, owner, repo, issue);
}
} else if(!issue.milestone || issue.milestone.number === config.defaultMilestone || issue.milestone.number === config.needsTriageMilestone) {
const isL2Triaged = this.isTriaged(config.l2TriageLabels || config.triagedLabels, issue.labels.map((label: Github.IssuesGetForRepoResponseItemLabelsItem) => label.name));
const isL2Triaged = this.isTriaged(config.l2TriageLabels || config.triagedLabels, issue.labels.map((label: Github.IssuesListForRepoResponseItemLabelsItem) => label.name));
if(isL2Triaged) {
if(!issue.milestone || issue.milestone.number !== config.defaultMilestone) {
await this.setMilestone(config.defaultMilestone, context.github, owner, repo, issue);
Expand Down Expand Up @@ -103,13 +103,13 @@ export class TriagePRTask extends Task {
}
}

setMilestone(milestoneNumber: number | null, github: Github, owner: string, repo: string, PR: Github.PullRequestsGetResponse|Github.IssuesGetForRepoResponseItem): Promise<Github.Response<Github.IssuesEditResponse>> {
setMilestone(milestoneNumber: number | null, github: Github, owner: string, repo: string, PR: Github.PullRequestsGetResponse|Github.IssuesListForRepoResponseItem): Promise<Github.Response<Github.IssuesUpdateResponse>> {
if(milestoneNumber) {
this.log(`Adding milestone ${milestoneNumber} to PR ${PR.html_url}`);
} else {
this.log(`Removing milestone from PR ${PR.html_url}`);
}
return github.issues.edit({owner, repo, number: PR.number, milestone: milestoneNumber}).catch(err => {
return github.issues.update({owner, repo, number: PR.number, milestone: milestoneNumber}).catch(err => {
throw err;
});
}
Expand All @@ -124,8 +124,8 @@ export class TriagePRTask extends Task {
async getConfig(context: Context): Promise<TriageConfig> {
const repositoryConfig = await context.config<AppConfig>(CONFIG_FILE, appConfig);
const config = repositoryConfig.triagePR;
config.defaultMilestone = parseInt(config.defaultMilestone, 10);
config.needsTriageMilestone = parseInt(config.needsTriageMilestone, 10);
config.defaultMilestone = parseInt(<unknown>config.defaultMilestone as string, 10);
config.needsTriageMilestone = parseInt(<unknown>config.needsTriageMilestone as string, 10);
return config;
}
}
17 changes: 17 additions & 0 deletions functions/src/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,20 @@ export const enum REVIEW_STATE {
Commented = 'COMMENTED',
Dismissed = 'DISMISSED'
}

export const enum AUTHOR_ASSOCIATION {
// Author has been invited to collaborate on the repository.
Collaborator = 'COLLABORATOR',
// Author has previously committed to the repository.
Contributor = 'CONTRIBUTOR',
// Author has not previously committed to GitHub.
FirstTimer = 'FIRST_TIMER',
// Author has not previously committed to the repository.
FirstTimeContributor = 'FIRST_TIME_CONTRIBUTOR',
// Author is a member of the organization that owns the repository.
Member = 'MEMBER',
// Author has no association with the repository.
None = 'NONE',
// Author is the owner of the repository.
Owner = 'OWNER'
}
Loading