Skip to content

feat: initial version #1

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

Merged
merged 13 commits into from
Feb 3, 2021
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
28 changes: 28 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# https://github.com/marketplace/actions/serverless
name: Deploy

on:
push:
branches:
- main
workflow_dispatch: {}

jobs:
deploy:
name: deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 12
- run: npm ci
- name: serverless deploy
uses: serverless/github-action@master
with:
args: deploy
env:
# probot/example-aws-lambda-serverless secrets provided by @gr2m
SERVERLESS_ACCESS_KEY: ${{ secrets.SERVERLESS_ACCESS_KEY }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
17 changes: 17 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Release
on:
push:
branches:
- main

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 12
- run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17 changes: 17 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Test
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize]

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- run: npm ci
- run: npm test
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# package directories
node_modules

# Serverless directories
.serverless
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# 🚧 WORK IN PROGRESS - See [#1](https://github.com/probot/example-aws-lambda-serverless/pull/1)

# Probot & AWS Lambda example

This repository is an example of how to deploy the "Hello, World" of probot apps to [AWS Lambda](https://aws.amazon.com/lambda/) using [serverless](https://www.serverless.com/).
Expand All @@ -22,7 +20,24 @@ Follow the instructions to register a new GitHub app.

## Deployment

🚧 TBD
In order to deploy the app from you local environment, follow the [Serverless user guide for AWS](https://www.serverless.com/framework/docs/providers/aws/guide/quick-start/).

If you use this example as a template, make sure to update [`serverless.yml`](serverless.yml) and set new values for

- `service`
- `app`
- `org`

Make sure to create the following parameters on [https://app.serverless.com](https://app.serverless.com):

- `APP_ID`
- `PRIVATE_KEY`
- `WEBHOOK_SECRET`

For continuous deployment via GitHub action, copy [this repository's deploy workflow](.github/workflows/deploy.yml) and create the following secrets:

1. `SERVERLESS_ACCESS_KEY` - You can create a Serverless access key at `https://app.serverless.com/<your org>/settings/accessKeys`
2. `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` - you will likely find your AWS credentials in `~/.aws/credentials`

## License

Expand Down
12 changes: 12 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @param {import('probot').Probot} app
*/
module.exports = (app) => {
app.log("Yay! The app was loaded!");

app.on("issues.opened", async (context) => {
return context.octokit.issues.createComment(
context.issue({ body: "Hello, World!" })
);
});
};
6 changes: 6 additions & 0 deletions app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
default_events:
- issues

default_permissions:
issues: write
metadata: read
41 changes: 41 additions & 0 deletions handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"use strict";

const { createProbot } = require("probot");
const app = require("./app");

const probot = createProbot();
const loadingApp = probot.load(app);

module.exports.webhooks = async (event, context) => {
try {
await loadingApp;

// Ends function immediately after callback
context.callbackWaitsForEmptyEventLoop = false;

// this could will be simpler once we ship `verifyAndParse()`
// see https://github.com/octokit/webhooks.js/issues/379
await probot.webhooks.verifyAndReceive({
id:
event.headers["X-GitHub-Delivery"] ||
event.headers["x-github-delivery"],
name: event.headers["X-GitHub-Event"] || event.headers["x-github-event"],
signature:
event.headers["X-Hub-Signature-256"] ||
event.headers["x-hub-signature-256"],
payload: JSON.parse(event.body),
});

return {
statusCode: 200,
body: '{"ok":true}',
};
} catch (error) {
console.log(error);

return {
statusCode: error.status || 500,
error: "ooops",
};
}
};
Loading