Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit58e1bf5

Browse files
committed
Initial commit
0 parents  commit58e1bf5

File tree

6 files changed

+1330
-0
lines changed

6 files changed

+1330
-0
lines changed

‎.env.sample‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
APP_ID="11"
2+
PRIVATE_KEY_PATH="very/secure/location/gh_app_key.pem"
3+
WEBHOOK_SECRET="secret"

‎.gitignore‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Logs
2+
logs
3+
.env
4+
*.log
5+
npm-debug.log*
6+
yarn-debug.log*
7+
yarn-error.log*
8+
pnpm-debug.log*
9+
lerna-debug.log*
10+
11+
node_modules
12+
dist
13+
dist-ssr
14+
*.local
15+
16+
# Editor directories and files
17+
.vscode/*
18+
!.vscode/extensions.json
19+
.idea
20+
.DS_Store
21+
*.suo
22+
*.ntvs*
23+
*.njsproj
24+
*.sln
25+
*.sw?

‎app.js‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
importdotenvfrom"dotenv";
2+
importfsfrom"fs";
3+
importhttpfrom"http";
4+
import{App}from"octokit";
5+
import{createNodeMiddleware}from"@octokit/webhooks";
6+
7+
// Load environment variables from .env file
8+
dotenv.config();
9+
10+
// Set configured values
11+
constappId=process.env.APP_ID;
12+
constprivateKeyPath=process.env.PRIVATE_KEY_PATH;
13+
constprivateKey=fs.readFileSync(privateKeyPath,"utf8");
14+
constsecret=process.env.WEBHOOK_SECRET;
15+
constmessageForNewPRs=fs.readFileSync("./message.md","utf8");
16+
17+
// Create an authenticated Octokit client authenticated as a GitHub App
18+
constapp=newApp({ appId, privateKey,webhooks:{ secret}});
19+
20+
// Optional: Get & log the authenticated app's name
21+
const{ data}=awaitapp.octokit.request("/app");
22+
23+
// Read more about custom logging: https://github.com/octokit/core.js#logging
24+
app.octokit.log.debug(`Authenticated as '${data.name}'`);
25+
26+
// Subscribe to the "pull_request.opened" webhook event
27+
app.webhooks.on("pull_request.opened",async({ octokit, payload})=>{
28+
console.log(`Received a pull request event for #${payload.pull_request.number}`);
29+
awaitoctokit.rest.issues.createComment({
30+
owner:payload.repository.owner.login,
31+
repo:payload.repository.name,
32+
issue_number:payload.pull_request.number,
33+
body:messageForNewPRs,
34+
});
35+
});
36+
37+
// Optional: Handle errors
38+
app.webhooks.onError((error)=>{
39+
if(error.name==="AggregateError"){
40+
// Log Secret verification errors
41+
console.log(`Error processing request:${error.event}`);
42+
}else{
43+
console.log(error);
44+
}
45+
});
46+
47+
// Launch a web server to listen for GitHub webhooks
48+
constport=process.env.PORT||3000;
49+
constpath="/api/webhook";
50+
constlocalWebhookUrl=`http://localhost:${port}${path}`;
51+
52+
// See https://github.com/octokit/webhooks.js/#createnodemiddleware for all options
53+
constmiddleware=createNodeMiddleware(app.webhooks,{ path});
54+
55+
http.createServer(middleware).listen(port,()=>{
56+
console.log(`Server is listening for events at:${localWebhookUrl}`);
57+
console.log('Press Ctrl + C to quit.')
58+
});

‎message.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
👋 Hi there!
2+
3+
Thanks for opening a new PR. Please, consider following this[guide](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests) to make your PR easier to review.
4+
5+
Also, check this new feature to[use markdown helpers](https://github.blog/changelog/2023-03-15-introducing-the-github-markdown-helpers-public-beta/) in your PR.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp