Skip to content

Commit

Permalink
Migrate to Now 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tibdex authored and autorebase[bot] committed Dec 1, 2018
1 parent 54db53f commit f4a64b0
Show file tree
Hide file tree
Showing 7 changed files with 308 additions and 774 deletions.
7 changes: 3 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ jobs:
- checkout
- run: yarn install --frozen-lockfile
- run: sudo yarn global add now --prefix /usr/local
- run: echo "{\"alias\":\"$NOW_ALIAS\"}" > now.json
- run: now --public --no-clipboard --no-verify --token $NOW_TOKEN --env APP_ID=$APP_ID --env DEBUG=$DEBUG_ON_NOW --env LOG_LEVEL=$LOG_LEVEL_ON_NOW --env NODE_ENV=production --env PRIVATE_KEY=$PRIVATE_KEY --env SENTRY_DSN=$SENTRY_DSN --env WEBHOOK_SECRET=$WEBHOOK_SECRET
- run: now --token $NOW_TOKEN alias
- run: now --token $NOW_TOKEN rm backport --safe --yes
- run: now --no-clipboard --token $NOW_TOKEN
- run: now --token $NOW_TOKEN $NOW_ALIAS
- run: now --token $NOW_TOKEN rm $NOW_ALIAS --safe --yes

workflows:
version: 2
Expand Down
13 changes: 13 additions & 0 deletions now.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"builds": [{ "src": "app/index.js", "use": "@now/node" }],
"env": {
"APP_ID": "@backport-app-id",
"DEBUG": "@backport-debug",
"LOG_LEVEL": "@backport-log-level",
"PRIVATE_KEY": "@backport-base64-encoded-private-key",
"SENTRY_DSN": "@backport-sentry-dsn",
"WEBHOOK_SECRET": "@backport-webhook-secret"
},
"routes": [{ "src": "/", "dest": "app/index.js" }],
"version": 2
}
37 changes: 14 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,44 +1,35 @@
{
"dependencies": {
"@octokit/rest": "^15.12.0",
"@types/debug": "^0.0.31",
"@types/node": "^10.12.0",
"debug": "^4.0.1",
"probot-serverless-now": "^0.2.1",
"debug": "^4.1.0",
"github-backport": "^0.2.0",
"probot": "^7.2.0",
"shared-github-internals": "^0.2.0",
"typescript": "^3.1.3"
"shared-github-internals": "^0.2.0"
},
"description": "GitHub App to backport pull requests",
"devDependencies": {
"@types/jest": "^23.3.5",
"@octokit/rest": "^15.18.0",
"@types/debug": "^0.0.31",
"@types/jest": "^23.3.10",
"@types/node": "^10.12.10",
"jest": "^23.6.0",
"jest-junit": "^5.1.0",
"nodemon": "^1.18.4",
"prettier": "^1.14.3",
"smee-client": "^1.0.2",
"ts-jest": "^23.10.4",
"probot": "^7.4.0",
"prettier": "^1.15.2",
"ts-jest": "^23.10.5",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.15.0",
"uuid": "^3.3.2"
"tslint-config-prettier": "^1.17.0",
"typescript": "^3.2.1"
},
"engines": {
"node": ">= 8.12.0"
"node": ">= 8.10.0"
},
"main": "app",
"name": "backport",
"nodemonConfig": {
"exec": "yarn build && yarn start",
"watch": [
".env",
"src"
]
},
"private": true,
"scripts": {
"build": "tsc --build tsconfig.build.json",
"dev": "nodemon",
"prettier": "prettier --ignore-path .gitignore \"**/*.{js,json,md,ts,yml}\"",
"prestart": "yarn build",
"start": "probot run .",
"test": "jest",
"tslint": "tslint --format stylish --project ."
Expand Down
25 changes: 25 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Application, Context } from "probot";

import handleEvent from "./backport";

const appFn = (app: Application) => {
app.log("App loaded");

app.on(
["pull_request.labeled", "pull_request.closed"],
async (context: Context) => {
const { payload, github: octokit } = context;
const { number: pullRequestNumber, owner, repo } = context.issue();
await handleEvent({
// @ts-ignore The value is the good one even if the type doesn't match.
octokit,
owner,
payload,
pullRequestNumber,
repo,
});
},
);
};

export = appFn;
34 changes: 14 additions & 20 deletions src/backport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ test.each([

describe("error messages", () => {
const getLastIssueComment = async (pullRequestNumber: PullRequestNumber) => {
const { data: comments } = await octokit.issues.getComments({
const { data: comments } = await octokit.issues.listComments({
number: pullRequestNumber,
owner,
repo,
Expand Down Expand Up @@ -234,24 +234,18 @@ describe("error messages", () => {
await deleteReferences();
});

test(
"error and comment",
async () => {
await expect(
backport({
octokit,
owner,
payload: getMergedPullRequestPayload({ base }),
pullRequestNumber,
repo,
}),
).rejects.toThrow("backport failed");
const comment = await getLastIssueComment(pullRequestNumber);
expect(comment).toMatch(
new RegExp(`The backport to \`${base}\` failed`),
);
},
15000,
);
test("error and comment", async () => {
await expect(
backport({
octokit,
owner,
payload: getMergedPullRequestPayload({ base }),
pullRequestNumber,
repo,
}),
).rejects.toThrow("backport failed");
const comment = await getLastIssueComment(pullRequestNumber);
expect(comment).toMatch(new RegExp(`The backport to \`${base}\` failed`));
}, 15000);
});
});
24 changes: 3 additions & 21 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
import { Application, Context } from "probot";
import * as toLambda from "probot-serverless-now";

import handleEvent from "./backport";
import * as applicationFunction from "./app";

module.exports = (app: Application) => {
app.log("App loaded");

app.on(
["pull_request.labeled", "pull_request.closed"],
async (context: Context) => {
const { payload, github: octokit } = context;
const { number: pullRequestNumber, owner, repo } = context.issue();
await handleEvent({
// @ts-ignore The value is the good one even if the type doesn't match.
octokit,
owner,
payload,
pullRequestNumber,
repo,
});
},
);
};
export = toLambda(applicationFunction);
Loading

0 comments on commit f4a64b0

Please sign in to comment.