Skip to content

Commit 9acbb12

Browse files
authored
feat: Azure Functions v4 support (#164)
1 parent 69e86c6 commit 9acbb12

7 files changed

+140
-4
lines changed

README.md

+25-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,31 @@ module.exports = (app) => {
1818
};
1919
```
2020

21-
Then create a folder with `function.json` and `index.js`, e.g.
21+
### Azure Functions v4
22+
23+
In your Azure function file:
24+
25+
```js
26+
// src/functions/probot.js
27+
const { app } = require("@azure/functions");
28+
const {
29+
createAzureFunctionV4,
30+
createProbot,
31+
} = require("@probot/adapter-azure-functions");
32+
const probotapp = require("../app");
33+
34+
app.http("probot", {
35+
methods: ["POST"],
36+
authLevel: "anonymous",
37+
handler: createAzureFunctionV4(probotapp, {
38+
probot: createProbot(),
39+
}),
40+
});
41+
```
42+
43+
### Azure Functions v3
44+
45+
Create a folder with `function.json` and `index.js`, e.g.
2246

2347
```js
2448
// ProbotFunction/function.json

azure-function-v4.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module.exports = azureFunctionV4;
2+
3+
/**
4+
* @param {import('probot').Probot} probot
5+
* @param {import('@azure/functions').HttpRequest} request
6+
* @param {import('@azure/functions').InvocationContext} context
7+
* @returns {Promise<import('@azure/functions').HttpResponseInit>}
8+
*/
9+
async function azureFunctionV4(probot, request, context) {
10+
await probot.webhooks.verifyAndReceive({
11+
id: request.headers.get("X-GitHub-Delivery"),
12+
name: request.headers.get("X-GitHub-Event"),
13+
signature: request.headers.get("X-Hub-Signature-256"),
14+
payload: await request.text(),
15+
});
16+
17+
return {
18+
status: 200,
19+
body: "ok",
20+
};
21+
}

index.d.ts

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
declare module "@probot/adapter-azure-functions" {
2+
import ProbotExports = require("probot");
3+
4+
/**
5+
* @param {import('probot').ApplicationFunction} app
6+
* @param { { probot: import('probot').Probot } } options
7+
*/
8+
function createAzureFunction(app: ProbotExports.ApplicationFunction, { probot }: {
9+
probot: ProbotExports.Probot;
10+
}): any;
11+
12+
/**
13+
* @param {import('probot').ApplicationFunction} app
14+
* @param { { probot: import('probot').Probot } } options
15+
*/
16+
function createAzureFunctionV4(app: ProbotExports.ApplicationFunction, { probot }: {
17+
probot: ProbotExports.Probot;
18+
}): any;
19+
20+
const _exports: {
21+
createAzureFunction: typeof createAzureFunction;
22+
createAzureFunctionV4: typeof createAzureFunctionV4;
23+
Context: typeof ProbotExports.Context;
24+
ProbotOctokit: typeof import("@octokit/core").Octokit & import("@octokit/core/dist-types/types").Constructor<{
25+
retry: {
26+
retryRequest: (error: import("@octokit/request-error").RequestError, retries: number, retryAfter: number) => import("@octokit/request-error").RequestError;
27+
};
28+
} & {
29+
paginate: import("@octokit/plugin-paginate-rest").PaginateInterface;
30+
} & import("@octokit/plugin-rest-endpoint-methods/dist-types/generated/method-types").RestEndpointMethods & import("@octokit/plugin-rest-endpoint-methods/dist-types/types").Api & import("@probot/octokit-plugin-config/dist-types/types").API>;
31+
run: typeof ProbotExports.run;
32+
Probot: typeof ProbotExports.Probot;
33+
Server: typeof ProbotExports.Server;
34+
createNodeMiddleware: typeof ProbotExports.createNodeMiddleware;
35+
createProbot: typeof ProbotExports.createProbot;
36+
};
37+
38+
export = _exports;
39+
}
40+
//# sourceMappingURL=index.d.ts.map

index.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
const ProbotExports = require("probot");
22
const azureFunction = require("./azure-function");
3+
const azureFunctionV4 = require("./azure-function-v4");
34

4-
module.exports = { ...ProbotExports, createAzureFunction };
5+
module.exports = {
6+
...ProbotExports,
7+
createAzureFunction,
8+
createAzureFunctionV4,
9+
};
510

611
/**
712
*
@@ -15,3 +20,14 @@ function createAzureFunction(app, { probot }) {
1520

1621
return azureFunction.bind(null, probot);
1722
}
23+
24+
/**
25+
* @param {import('probot').ApplicationFunction} app
26+
* @param { { probot: import('probot').Probot } } options
27+
*/
28+
function createAzureFunctionV4(app, { probot }) {
29+
// load app once outside of the function to prevent double
30+
// event handlers in case of container reuse
31+
probot.load(app);
32+
return azureFunctionV4.bind(null, probot);
33+
}

package-lock.json

+15-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@
1919
"author": "Gregor Martynus (https://github.com/gr2m)",
2020
"license": "ISC",
2121
"repository": "github:probot/adapter-azure-functions",
22+
"types": "index.d.ts",
2223
"devDependencies": {
2324
"@azure/functions": "^3.2.0",
2425
"@types/jest": "^29.0.0",
2526
"jest": "^29.0.2",
2627
"nock": "^13.2.9",
27-
"prettier": "^2.7.1"
28+
"prettier": "^2.7.1",
29+
"typescript": "^5.2.2"
2830
},
2931
"dependencies": {
3032
"probot": "^12.2.7"

tsconfig.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
// Change this to match your project
3+
"include": ["./index.js"],
4+
"compilerOptions": {
5+
// Tells TypeScript to read JS files, as
6+
// normally they are ignored as source files
7+
"allowJs": true,
8+
// Generate d.ts files
9+
"declaration": true,
10+
// This compiler run should
11+
// only output d.ts files
12+
"emitDeclarationOnly": true,
13+
// go to js file when using IDE functions like
14+
// "Go to Definition" in VSCode
15+
"declarationMap": true,
16+
"esModuleInterop": true,
17+
"outFile": "index.d.ts"
18+
}
19+
}

0 commit comments

Comments
 (0)