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 11 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
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2
updates:
# create PRs for out-of-range updates
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "daily"
versioning-strategy: "increase"
28 changes: 28 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Deploy
on:
push:
branches:
- main
workflow_dispatch: {}

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 12
- run: npm ci
- uses: azure/login@v1
with:
# probot/example-azure-function credentials provided by @gr2m
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: "Run Azure Functions Action"
uses: Azure/functions-action@v1
id: fa
with:
app-name: "probot-example"
package: "."
# probot/example-azure-function credentials provided by @gr2m
publish-profile: ${{ secrets.AZURE_FUNCTION_APP_PUBLISH_PROFILE }}
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env
node_modules
16 changes: 16 additions & 0 deletions ProbotFunction/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"bindings": [
{
"authLevel": "Anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": ["post"]
},
{
"type": "http",
"direction": "out",
"name": "res"
}
]
}
30 changes: 30 additions & 0 deletions ProbotFunction/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const { createProbot } = require("probot");
const app = require("../app");

// create Probot instance using environment variables
const probot = createProbot();

// load app once outside of the function to prevent double
// event handlers in case of container reuse
probot.load(app);

/**
* @param {import('@azure/functions').Context} context
* @param {import('@azure/functions').HttpRequest} req
*/
module.exports = async function (context, req) {
// this will be simpler once we ship `verifyAndParse()`
// see https://github.com/octokit/webhooks.js/issues/379
await probot.webhooks.verifyAndReceive({
id: req.headers["X-GitHub-Delivery"] || req.headers["x-github-delivery"],
name: req.headers["X-GitHub-Event"] || req.headers["x-github-event"],
signature:
req.headers["X-Hub-Signature-256"] || req.headers["x-hub-signature-256"],
payload: req.body,
});

context.res = {
status: "200",
body: "ok",
};
};
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
# 🚧 Work in progress, see [#1](https://github.com/probot/example-azure-function/pull/1)

# Probot & Azure Functions example

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).

## Local setup

```
npm install
npm start
```

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.

## Deployment through GitHub Actions

1. Create `AZURE_CREDENTIALS` repository secret. See https://github.com/azure/login#configure-deployment-credentials for how to retrieve it from the Azure Console.
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.

## License

[ISC](LICENSE)
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
Loading