Skip to content

Commit bebcb2e

Browse files
authored
feat: initial version (#1)
1 parent b43dc13 commit bebcb2e

File tree

13 files changed

+2869
-2
lines changed

13 files changed

+2869
-2
lines changed

.github/dependabot.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: 2
2+
updates:
3+
# create PRs for out-of-range updates
4+
- package-ecosystem: "npm"
5+
directory: "/"
6+
schedule:
7+
interval: "daily"
8+
versioning-strategy: "increase"

.github/workflows/deploy.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Deploy
2+
on:
3+
push:
4+
branches:
5+
- main
6+
workflow_dispatch: {}
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- uses: actions/setup-node@v2
14+
with:
15+
node-version: 12
16+
- run: npm ci
17+
- uses: azure/login@v1
18+
with:
19+
# probot/example-azure-function credentials provided by @gr2m
20+
creds: ${{ secrets.AZURE_CREDENTIALS }}
21+
- name: "Run Azure Functions Action"
22+
uses: Azure/functions-action@v1
23+
id: fa
24+
with:
25+
app-name: "probot-example"
26+
package: "."
27+
# probot/example-azure-function credentials provided by @gr2m
28+
publish-profile: ${{ secrets.AZURE_FUNCTION_APP_PUBLISH_PROFILE }}

.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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.env
2+
node_modules

ProbotFunction/function.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"bindings": [
3+
{
4+
"authLevel": "Anonymous",
5+
"type": "httpTrigger",
6+
"direction": "in",
7+
"name": "req",
8+
"methods": ["post"]
9+
},
10+
{
11+
"type": "http",
12+
"direction": "out",
13+
"name": "res"
14+
}
15+
]
16+
}

ProbotFunction/index.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const { createProbot } = require("probot");
2+
const app = require("../app");
3+
4+
// create Probot instance using environment variables
5+
const probot = createProbot();
6+
7+
// load app once outside of the function to prevent double
8+
// event handlers in case of container reuse
9+
probot.load(app);
10+
11+
/**
12+
* @param {import('@azure/functions').Context} context
13+
* @param {import('@azure/functions').HttpRequest} req
14+
*/
15+
module.exports = async function (context, req) {
16+
// this will be simpler once we ship `verifyAndParse()`
17+
// see https://github.com/octokit/webhooks.js/issues/379
18+
await probot.webhooks.verifyAndReceive({
19+
id: req.headers["X-GitHub-Delivery"] || req.headers["x-github-delivery"],
20+
name: req.headers["X-GitHub-Event"] || req.headers["x-github-event"],
21+
signature:
22+
req.headers["X-Hub-Signature-256"] || req.headers["x-hub-signature-256"],
23+
payload: req.body,
24+
});
25+
26+
context.res = {
27+
status: "200",
28+
body: "ok",
29+
};
30+
};

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
1-
# 🚧 Work in progress, see [#1](https://github.com/probot/example-azure-function/pull/1)
2-
31
# Probot & Azure Functions example
42

53
This repository is an example of how to deploy the "Hello, World" of probot apps to [Azure Functions](https://azure.microsoft.com/en-us/services/functions).
64

5+
## Local setup
6+
7+
```
8+
npm install
9+
npm start
10+
```
11+
12+
Open http://localhost:3000 and follow instructions to register a GitHub App for testing. When done, an `.env` file with your app's credentials will exist.
13+
14+
## Deployment through GitHub Actions
15+
16+
1. Create `AZURE_CREDENTIALS` repository secret. See https://github.com/azure/login#configure-deployment-credentials for how to retrieve it from the Azure Console.
17+
2. Create `AZURE_FUNCTION_APP_PUBLISH_PROFILE` repository secret. See https://github.com/Azure/functions-action#using-publish-profile-as-deployment-credential-recommended for how to retrieve it from the Azure Console.
18+
719
## License
820

921
[ISC](LICENSE)

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+
return context.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

0 commit comments

Comments
 (0)