Skip to content

Commit 6b24426

Browse files
authored
feat: initial version (#1)
1 parent c1d8d36 commit 6b24426

File tree

12 files changed

+2916
-3
lines changed

12 files changed

+2916
-3
lines changed

‎.github/workflows/deploy.yml‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# https://github.com/marketplace/actions/serverless
2+
name: Deploy
3+
4+
on:
5+
push:
6+
branches:
7+
- main
8+
workflow_dispatch: {}
9+
10+
jobs:
11+
deploy:
12+
name: deploy
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
- uses: actions/setup-node@v2
17+
with:
18+
node-version: 12
19+
- run: npm ci
20+
- name: serverless deploy
21+
uses: serverless/github-action@master
22+
with:
23+
args: deploy
24+
env:
25+
# probot/example-aws-lambda-serverless secrets provided by @gr2m
26+
SERVERLESS_ACCESS_KEY: ${{secrets.SERVERLESS_ACCESS_KEY }}
27+
AWS_ACCESS_KEY_ID: ${{secrets.AWS_ACCESS_KEY_ID }}
28+
AWS_SECRET_ACCESS_KEY: ${{secrets.AWS_SECRET_ACCESS_KEY }}

‎.github/workflows/release.yml‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Release
2+
on:
3+
push:
4+
branches:
5+
- main
6+
7+
jobs:
8+
release:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
- uses: actions/setup-node@v2
13+
with:
14+
node-version: 12
15+
- run: npx semantic-release
16+
env:
17+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN }}

‎.github/workflows/test.yml‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Test
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
types: [opened, synchronize]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v2
15+
- uses: actions/setup-node@v2
16+
- run: npm ci
17+
- run: npm test

‎.gitignore‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# package directories
2+
node_modules
3+
4+
# Serverless directories
5+
.serverless

‎README.md‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# 🚧 WORK IN PROGRESS - See [#1](https://github.com/probot/example-aws-lambda-serverless/pull/1)
2-
31
# Probot & AWS Lambda example
42

53
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/).
@@ -22,7 +20,24 @@ Follow the instructions to register a new GitHub app.
2220

2321
## Deployment
2422

25-
🚧 TBD
23+
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/).
24+
25+
If you use this example as a template, make sure to update [`serverless.yml`](serverless.yml) and set new values for
26+
27+
-`service`
28+
-`app`
29+
-`org`
30+
31+
Make sure to create the following parameters on [https://app.serverless.com](https://app.serverless.com):
32+
33+
-`APP_ID`
34+
-`PRIVATE_KEY`
35+
-`WEBHOOK_SECRET`
36+
37+
For continuous deployment via GitHub action, copy [this repository's deploy workflow](.github/workflows/deploy.yml) and create the following secrets:
38+
39+
1.`SERVERLESS_ACCESS_KEY` - You can create a Serverless access key at `https://app.serverless.com/<your org>/settings/accessKeys`
40+
2.`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` - you will likely find your AWS credentials in `~/.aws/credentials`
2641

2742
## License
2843

‎app.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @param{import('probot').Probot} app
3+
*/
4+
module.exports=(app)=>{
5+
app.log("Yay! The app was loaded!");
6+
7+
app.on("issues.opened",async(context)=>{
8+
returncontext.octokit.issues.createComment(
9+
context.issue({body: "Hello, World!"})
10+
);
11+
});
12+
};

‎app.yml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
default_events:
2+
- issues
3+
4+
default_permissions:
5+
issues: write
6+
metadata: read

‎handler.js‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"use strict";
2+
3+
const{ createProbot }=require("probot");
4+
constapp=require("./app");
5+
6+
constprobot=createProbot();
7+
constloadingApp=probot.load(app);
8+
9+
module.exports.webhooks=async(event,context)=>{
10+
try{
11+
awaitloadingApp;
12+
13+
// Ends function immediately after callback
14+
context.callbackWaitsForEmptyEventLoop=false;
15+
16+
// this could will be simpler once we ship `verifyAndParse()`
17+
// see https://github.com/octokit/webhooks.js/issues/379
18+
awaitprobot.webhooks.verifyAndReceive({
19+
id:
20+
event.headers["X-GitHub-Delivery"]||
21+
event.headers["x-github-delivery"],
22+
name: event.headers["X-GitHub-Event"]||event.headers["x-github-event"],
23+
signature:
24+
event.headers["X-Hub-Signature-256"]||
25+
event.headers["x-hub-signature-256"],
26+
payload: JSON.parse(event.body),
27+
});
28+
29+
return{
30+
statusCode: 200,
31+
body: '{"ok":true}',
32+
};
33+
}catch(error){
34+
console.log(error);
35+
36+
return{
37+
statusCode: error.status||500,
38+
error: "ooops",
39+
};
40+
}
41+
};

0 commit comments

Comments
(0)