Skip to content

Commit

Permalink
fix(slo-stat-bot): upgrade to Probot 11 (#1389)
Browse files Browse the repository at this point in the history
Co-authored-by: Justin Beckwith <[email protected]>
  • Loading branch information
sofisl and JustinBeckwith authored Feb 11, 2021
1 parent b51117f commit 1f7654d
Show file tree
Hide file tree
Showing 8 changed files with 389 additions and 456 deletions.
773 changes: 350 additions & 423 deletions packages/slo-stat-bot/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/slo-stat-bot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"dependencies": {
"ajv": "^6.12.2",
"gcf-utils": "^6.1.1",
"gcf-utils": "^7.1.1",
"moment": "^2.27.0"
},
"devDependencies": {
Expand Down
22 changes: 11 additions & 11 deletions packages/slo-stat-bot/src/slo-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

// eslint-disable-next-line node/no-extraneous-import
import {Application, Context, ProbotOctokit} from 'probot';
import {Probot, Context, ProbotOctokit} from 'probot';
import {logger} from 'gcf-utils';
import {doesSloApply} from './slo-appliesTo';
import {isIssueCompliant, getFilePathContent} from './slo-compliant';
Expand Down Expand Up @@ -149,7 +149,7 @@ async function getIssueList(
repo,
state,
});
return issueList.data;
return issueList.data as IssueListForRepoItem[];
} catch (err) {
err.message = `Error in getting list of issues from repo ${repo}: ${err.message}`;
logger.error(err);
Expand All @@ -164,7 +164,7 @@ async function getIssueList(
* @param app type probot
* @returns void
*/
export = function handler(app: Application) {
export = function handler(app: Probot) {
app.on(
[
'pull_request.opened',
Expand Down Expand Up @@ -213,7 +213,7 @@ export = function handler(app: Application) {
const labels = labelsResponse.map(
(label: IssueLabelResponseItem) => label.name
);
const sloString = await getSloFile(context.github, owner, repo);
const sloString = await getSloFile(context.octokit, owner, repo);
const issueItem = {
owner,
repo,
Expand All @@ -224,7 +224,7 @@ export = function handler(app: Application) {
labels,
} as IssueItem;

await handleIssues(context.github, issueItem, sloString, labelName);
await handleIssues(context.octokit, issueItem, sloString, labelName);
}
);
app.on(['issues.closed', 'pull_request.closed'], async (context: Context) => {
Expand All @@ -241,7 +241,7 @@ export = function handler(app: Application) {

const labelName = await getOoSloLabelName(context);
if (labels?.includes(labelName)) {
await removeLabel(context.github, owner, repo, number, labelName);
await removeLabel(context.octokit, owner, repo, number, labelName);
}
});
app.on(
Expand Down Expand Up @@ -278,7 +278,7 @@ export = function handler(app: Application) {
const labels = labelsResponse.map(
(label: IssueLabelResponseItem) => label.name
);
const sloString = await getSloFile(context.github, owner, repo);
const sloString = await getSloFile(context.octokit, owner, repo);
const issueItem = {
owner,
repo,
Expand All @@ -290,20 +290,20 @@ export = function handler(app: Application) {
comment,
} as IssueItem;

await handleIssues(context.github, issueItem, sloString, labelName);
await handleIssues(context.octokit, issueItem, sloString, labelName);
}
);
app.on(['schedule.repository' as '*'], async (context: Context) => {
const owner = context.payload.organization.login;
const repo = context.payload.repository.name;

const issueList = await getIssueList(context.github, owner, repo);
const issueList = await getIssueList(context.octokit, owner, repo);

if (!issueList) {
return;
}

const sloString = await getSloFile(context.github, owner, repo);
const sloString = await getSloFile(context.octokit, owner, repo);
const labelName = await getOoSloLabelName(context);

for (const issue of issueList) {
Expand All @@ -325,7 +325,7 @@ export = function handler(app: Application) {
labels,
} as IssueItem;

await handleIssues(context.github, issueItem, sloString, labelName);
await handleIssues(context.octokit, issueItem, sloString, labelName);
}
});
};
4 changes: 2 additions & 2 deletions packages/slo-stat-bot/src/slo-compliant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export const getIssueCommentsList = async function getIssueCommentsList(
repo,
issue_number: number,
});
return listComments.data;
return listComments.data as IssuesListCommentsItem[];
} catch (err) {
logger.error(
`Error in getting issue comments for number ${number}\n ${err.message}`
Expand Down Expand Up @@ -259,7 +259,7 @@ export const getCollaborators = async function getCollaborators(
owner,
repo,
});
return collaboratorList.data;
return collaboratorList.data as ReposListCollaboratorsItem[];
} catch (err) {
logger.warn(`Error in getting list of collaborators \n ${err.message}`);
return null;
Expand Down
8 changes: 4 additions & 4 deletions packages/slo-stat-bot/src/slo-lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const handleSlos = async function handleSlos(
fileSha: string
) {
const sloString = await getFileShaContents(
context.github,
context.octokit,
owner,
repo,
fileSha
Expand All @@ -107,7 +107,7 @@ export const handleSlos = async function handleSlos(
const sloData = JSON.parse(sloString);
const res = await lint(schema, sloData);

await commentPR(context.github, owner, repo, number, res.isValid);
await commentPR(context.octokit, owner, repo, number, res.isValid);
await createCheck(context, res);
};

Expand Down Expand Up @@ -264,7 +264,7 @@ async function createCheck(context: Context, validationRes: ValidationResults) {
});
}
try {
await context.github.checks.create(checkParams);
await context.octokit.checks.create(checkParams);
} catch (err) {
logger.error(
`Error creating check in repo ${context.payload.repository.name} \n ${err.message}`
Expand All @@ -288,7 +288,7 @@ export async function handleLint(
repo: string,
number: number
) {
const fileList = await listFiles(context.github, owner, repo, number, 100);
const fileList = await listFiles(context.octokit, owner, repo, number, 100);

if (!fileList) {
return;
Expand Down
12 changes: 7 additions & 5 deletions packages/slo-stat-bot/test/slo-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ describe('slo-bot', () => {

beforeEach(() => {
probot = createProbot({
githubToken: 'abc123',
Octokit: ProbotOctokit.defaults({
retry: {enabled: false},
throttle: {enabled: false},
}),
overrides: {
githubToken: 'abc123',
Octokit: ProbotOctokit.defaults({
retry: {enabled: false},
throttle: {enabled: false},
}),
},
});

probot.load(handler);
Expand Down
12 changes: 7 additions & 5 deletions packages/slo-stat-bot/test/slo-label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ describe('slo-label', () => {

beforeEach(() => {
probot = createProbot({
githubToken: 'abc123',
Octokit: ProbotOctokit.defaults({
retry: {enabled: false},
throttle: {enabled: false},
}),
overrides: {
githubToken: 'abc123',
Octokit: ProbotOctokit.defaults({
retry: {enabled: false},
throttle: {enabled: false},
}),
},
});

probot.load(handler);
Expand Down
12 changes: 7 additions & 5 deletions packages/slo-stat-bot/test/slo-lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ describe('slo-lint', () => {

beforeEach(() => {
probot = createProbot({
githubToken: 'abc123',
Octokit: ProbotOctokit.defaults({
retry: {enabled: false},
throttle: {enabled: false},
}),
overrides: {
githubToken: 'abc123',
Octokit: ProbotOctokit.defaults({
retry: {enabled: false},
throttle: {enabled: false},
}),
},
});

probot.load(handler);
Expand Down

0 comments on commit 1f7654d

Please sign in to comment.