Skip to content

Commit

Permalink
Merge pull request #79 from godaddy/probot-deprecations
Browse files Browse the repository at this point in the history
[fix] Replace various deprecated API calls into Probot
  • Loading branch information
decompil3d committed Feb 3, 2021
2 parents 4da5434 + 4b646e8 commit bc52a63
Show file tree
Hide file tree
Showing 13 changed files with 669 additions and 694 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,7 @@
# CHANGELOG

- Replace various deprecated API calls into Probot in preparation for `probot@11`

## 4.0.1

- Update dependencies
Expand Down
8 changes: 6 additions & 2 deletions index.js
Expand Up @@ -3,17 +3,21 @@ const setupDocsRoutes = require('./docs');

/**
* @typedef {import('probot').Application} ProbotApp
* @typedef {import('express').Router} ExpressRouter
* @typedef {(path?: string) => ExpressRouter} GetRouterFn
*/

/**
* This is the main entrypoint to your Probot app
* @param {ProbotApp} app Application
* @param {Object} helpers Helpers
* @param {GetRouterFn} helpers.getRouter Function to get an Express router
*/
function appFn(app) {
function appFn(app, { getRouter }) {
if (!process.env.DISABLE_DOCS_ROUTE) {
const docsPath = process.env.DOCS_PATH || '/docs';
app.log.info('Setting up docs route at ' + docsPath);
const router = app.route(docsPath);
const router = getRouter(docsPath);
setupDocsRoutes(router);
}

Expand Down
1,284 changes: 622 additions & 662 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -41,7 +41,7 @@
"node-fetch": "^2.6.1",
"p-reduce": "^2.1.0",
"prismjs": "^1.20.0",
"probot": "^10.9.0",
"probot": "^10.19.0",
"resolve-cwd": "^3.0.0"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions plugins/required-file/index.js
Expand Up @@ -82,7 +82,7 @@ class RequiredFilePlugin extends BasePlugin {
const message = '⚠️ ' + (typeof file === 'object' && file.message ||
`You're missing a change to ${filePath}, which is a requirement for changes to this repo.`);

const existsRes = await context.github.repos.getContent({
const existsRes = await context.octokit.repos.getContent({
...context.repo(),
path: filePath
});
Expand All @@ -94,7 +94,7 @@ class RequiredFilePlugin extends BasePlugin {
* @typedef {import('@octokit/rest').PullsListFilesResponseItem} PullsListFilesResponseItem
* @type {PullsListFilesResponseItem[]}
*/
const filesInPR = await context.github.paginate(context.github.pulls.listFiles.endpoint.merge(
const filesInPR = await context.octokit.paginate(context.octokit.pulls.listFiles.endpoint.merge(
context.pullRequest()), res => res.data);

if (!filesInPR.some(f => {
Expand Down
6 changes: 3 additions & 3 deletions plugins/reviewers/index.js
Expand Up @@ -168,7 +168,7 @@ class ReviewerPlugin extends BasePlugin {
);
}

await context.github.pulls.requestReviewers({
await context.octokit.pulls.requestReviewers({
...context.pullRequest(),
reviewers: usersToRequest
});
Expand All @@ -183,7 +183,7 @@ class ReviewerPlugin extends BasePlugin {
* @returns {Promise<Object>} parsed package.json
*/
async getPackageJson(context) {
const pkg = await context.github.repos.getContent({
const pkg = await context.octokit.repos.getContent({
...context.repo(),
path: 'package.json'
});
Expand Down Expand Up @@ -223,7 +223,7 @@ class ReviewerPlugin extends BasePlugin {

return await pReduce(maybeUsers, async (memo, user) => {
try {
const res = await context.github.repos.checkCollaborator({
const res = await context.octokit.repos.checkCollaborator({
...context.repo(),
username: user
});
Expand Down
2 changes: 1 addition & 1 deletion plugins/welcome/index.js
Expand Up @@ -35,7 +35,7 @@ class WelcomePlugin extends BasePlugin {
if (!message) return;

// Get all issues for repo with user as creator
const response = await context.github.issues.listForRepo(context.repo({
const response = await context.octokit.issues.listForRepo(context.repo({
state: 'all',
creator: context.payload.pull_request.user.login
}));
Expand Down
6 changes: 3 additions & 3 deletions processor.js
Expand Up @@ -118,7 +118,7 @@ module.exports = async function processPR(context) { // eslint-disable-line comp
context.log.info(logData, 'Finished processing PR');
const comment = commenter.flushToString();
if (comment) {
await context.github.issues.createComment({
await context.octokit.issues.createComment({
...context.repo(),
issue_number: context.payload.number,
body: comment
Expand All @@ -135,7 +135,7 @@ module.exports = async function processPR(context) { // eslint-disable-line comp
async function getRepoConfig(context) {
let pullieRcRes = {};
try {
pullieRcRes = await context.github.repos.getContent({
pullieRcRes = await context.octokit.repos.getContent({
...context.repo(),
path: '.pullierc'
});
Expand All @@ -157,7 +157,7 @@ async function getRepoConfig(context) {
async function getOrgConfig(context) {
let pullieRcRes = {};
try {
pullieRcRes = await context.github.repos.getContent({
pullieRcRes = await context.octokit.repos.getContent({
owner: context.payload.repository.owner.login,
repo: '.github',
path: '.pullierc'
Expand Down
39 changes: 24 additions & 15 deletions test/integration/index.test.js
Expand Up @@ -5,7 +5,7 @@ const path = require('path');
/** @type {(url: string, options?: RequestInit) => Promise<Response>} */
const fetch = require('node-fetch');
const pullieApp = require('../../');
const { Probot } = require('probot');
const { Server, Probot } = require('probot');
const { assumeValidResponse } = require('./helpers');
const openPRPayload = require('../fixtures/payloads/open-pr.json');
const mockOrgPullieRC = require('../fixtures/payloads/mock-org-pullierc.json');
Expand Down Expand Up @@ -109,12 +109,11 @@ describe('Pullie (integration)', function () {
});

before(function () {
process.env.GHE_HOST = 'github.test.fake';
process.env.JIRA_PROTOCOL = 'https';
process.env.JIRA_HOST = 'jira.test.fake';
process.env.JIRA_USERNAME = 'test_user';
process.env.JIRA_PASSWORD = 'test_password';
pullie = new Probot({ id: 123, privateKey: mockCert });
pullie = new Probot({ appId: 123, privateKey: mockCert, baseUrl: 'https://github.test.fake/api/v3' });
pullie.load(pullieApp);
});

Expand Down Expand Up @@ -143,16 +142,22 @@ describe('Pullie (integration)', function () {
});

describe('Docs', function () {
/** @type {import('probot').Server} */
let server;
let baseUrl;
before(function () {
pullie.start();
before(async function () {
server = new Server({
Probot: Probot.defaults({ appId: 123, privateKey: mockCert })
});
await server.load(pullieApp);
const httpServer = await server.start();
// @ts-ignore
const { port } = pullie.httpServer.address();
const { port } = httpServer.address();
baseUrl = `http://localhost:${port}/docs`;
});

after(function (done) {
pullie.httpServer.close(done);
after(async function () {
await server.stop();
});

it('serves documentation at host root', async function () {
Expand All @@ -173,20 +178,24 @@ describe('Pullie (integration)', function () {
});

describe('No Docs', function () {
/** @type {import('probot').Server} */
let server;
let baseUrl;

before(function () {
before(async function () {
process.env.DISABLE_DOCS_ROUTE = 'true';
pullie = new Probot({ id: 123, privateKey: mockCert });
pullie.load(pullieApp);
pullie.start();
server = new Server({
Probot: Probot.defaults({ appId: 123, privateKey: mockCert })
});
await server.load(pullieApp);
const httpServer = await server.start();
// @ts-ignore
const { port } = pullie.httpServer.address();
const { port } = httpServer.address();
baseUrl = `http://localhost:${port}/docs`;
});

after(function (done) {
pullie.httpServer.close(done);
after(async function () {
await server.stop();
});

it('does not initialize the docs route when DISABLE_DOCS_ROUTE is set', async function () {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/plugins/required-file.test.js
Expand Up @@ -94,7 +94,7 @@ describe('RequiredFilePlugin', function () {

beforeEach(function () {
mockContext = {
github: {
octokit: {
pulls: {
listFiles: {
endpoint: {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/plugins/reviewers.test.js
Expand Up @@ -33,7 +33,7 @@ describe('ReviewersPlugin', function () {
};

mockContext = {
github: {
octokit: {
pulls: {
requestReviewers: requestReviewersStub
},
Expand Down
4 changes: 2 additions & 2 deletions test/unit/plugins/welcome.test.js
Expand Up @@ -23,7 +23,7 @@ describe('WelcomePlugin', function () {
addCommentStub.reset();

mockContext = {
github: {
octokit: {
issues: {
listForRepo: function () {
return Promise.resolve({
Expand Down Expand Up @@ -101,7 +101,7 @@ describe('WelcomePlugin', function () {
it('will do nothing if the user is already part of the repo', async function () {
mockContext = {
...mockContext,
github: {
octokit: {
issues: {
listForRepo: function () {
return Promise.resolve({
Expand Down
2 changes: 1 addition & 1 deletion test/unit/processor.test.js
Expand Up @@ -53,7 +53,7 @@ const mockContext = {
warn: warnLogStub,
error: errorLogStub
},
github: {
octokit: {
issues: {
createComment: createCommentStub
},
Expand Down

0 comments on commit bc52a63

Please sign in to comment.