Skip to content

Commit 0a2649a

Browse files
Add GitHub bot app using Probot with /health route (#2012)
* Add GitHub app using Probot with /health route Co-Authored-By: yujonglee <[email protected]> * Scaffold GitHub app using Probot CLI with basic-ts template and /health route Co-Authored-By: yujonglee <[email protected]> * Fix dprint formatting issues Co-Authored-By: yujonglee <[email protected]> * done * Fix getRouter to be optional for test environment Co-Authored-By: yujonglee <[email protected]> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 9aea4fb commit 0a2649a

File tree

16 files changed

+2129
-324
lines changed

16 files changed

+2129
-324
lines changed

.github/workflows/bot_cd.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
on:
2+
workflow_dispatch:
3+
push:
4+
paths:
5+
- "apps/bot/**"
6+
branches:
7+
- main
8+
9+
jobs:
10+
deploy:
11+
runs-on: depot-ubuntu-24.04-8
12+
timeout-minutes: 60
13+
concurrency: bot-fly-deploy
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: superfly/flyctl-actions/setup-flyctl@master
17+
- run: flyctl deploy --config apps/bot/fly.toml --remote-only
18+
env:
19+
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}

.github/workflows/bot_ci.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
on:
2+
workflow_dispatch:
3+
pull_request:
4+
branches:
5+
- main
6+
paths:
7+
- apps/bot/**
8+
jobs:
9+
ci:
10+
runs-on: depot-ubuntu-24.04-8
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: pnpm/action-setup@v4
14+
- uses: actions/setup-node@v4
15+
with:
16+
node-version: 22
17+
cache: pnpm
18+
- run: pnpm install --frozen-lockfile
19+
- run: pnpm -F @hypr/bot typecheck
20+
- run: pnpm -F @hypr/bot test

apps/bot/.dockerignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
**/node_modules/
2+
**/.git
3+
**/README.md
4+
**/LICENSE
5+
**/.vscode
6+
**/npm-debug.log
7+
**/coverage
8+
**/.env
9+
**/.editorconfig
10+
**/dist
11+
**/*.pem
12+
Dockerfile

apps/bot/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
node_modules
2+
npm-debug.log
3+
*.pem
4+
!mock-cert.pem
5+
.env
6+
coverage
7+
lib

apps/bot/Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# https://pnpm.io/docker#example-3-build-on-cicd
2+
FROM node:22-slim AS node-base
3+
WORKDIR /repo
4+
5+
ENV PNPM_HOME="/pnpm"
6+
ENV PATH="$PNPM_HOME:$PATH"
7+
ENV CI=true
8+
RUN corepack enable
9+
10+
FROM node-base AS deps
11+
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
12+
COPY apps/bot/package.json apps/bot/package.json
13+
RUN pnpm fetch --filter @hypr/bot
14+
15+
FROM deps AS build
16+
COPY apps/bot apps/bot
17+
RUN pnpm install --filter @hypr/bot --frozen-lockfile
18+
RUN pnpm --filter @hypr/bot run build
19+
RUN pnpm deploy --filter @hypr/bot --prod --legacy /runtime
20+
21+
FROM node:22-slim AS runtime
22+
WORKDIR /app
23+
ENV NODE_ENV="production"
24+
COPY --from=build /runtime ./
25+
CMD ["node", "node_modules/probot/bin/probot.js", "run", "./lib/index.js"]

apps/bot/app.yml

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# This is a GitHub App Manifest. These settings will be used by default when
2+
# initially configuring your GitHub App.
3+
#
4+
# NOTE: changing this file will not update your GitHub App settings.
5+
# You must visit github.com/settings/apps/your-app-name to edit them.
6+
#
7+
# Read more about configuring your GitHub App:
8+
# https://probot.github.io/docs/development/#configuring-a-github-app
9+
#
10+
# Read more about GitHub App Manifests:
11+
# https://developer.github.com/apps/building-github-apps/creating-github-apps-from-a-manifest/
12+
13+
# The list of events the GitHub App subscribes to.
14+
# Uncomment the event names below to enable them.
15+
default_events:
16+
# - check_run
17+
# - check_suite
18+
# - commit_comment
19+
# - create
20+
# - delete
21+
# - deployment
22+
# - deployment_status
23+
# - fork
24+
# - gollum
25+
# - issue_comment
26+
- issues
27+
# - label
28+
# - milestone
29+
# - member
30+
# - membership
31+
# - org_block
32+
# - organization
33+
# - page_build
34+
# - project
35+
# - project_card
36+
# - project_column
37+
# - public
38+
# - pull_request
39+
# - pull_request_review
40+
# - pull_request_review_comment
41+
# - push
42+
# - release
43+
# - repository
44+
# - repository_import
45+
# - status
46+
# - team
47+
# - team_add
48+
# - watch
49+
50+
# The set of permissions needed by the GitHub App. The format of the object uses
51+
# the permission name for the key (for example, issues) and the access type for
52+
# the value (for example, write).
53+
# Valid values are `read`, `write`, and `none`
54+
default_permissions:
55+
# Repository creation, deletion, settings, teams, and collaborators.
56+
# https://developer.github.com/v3/apps/permissions/#permission-on-administration
57+
# administration: read
58+
59+
# Checks on code.
60+
# https://developer.github.com/v3/apps/permissions/#permission-on-checks
61+
# checks: read
62+
63+
# Repository contents, commits, branches, downloads, releases, and merges.
64+
# https://developer.github.com/v3/apps/permissions/#permission-on-contents
65+
# contents: read
66+
67+
# Deployments and deployment statuses.
68+
# https://developer.github.com/v3/apps/permissions/#permission-on-deployments
69+
# deployments: read
70+
71+
# Issues and related comments, assignees, labels, and milestones.
72+
# https://developer.github.com/v3/apps/permissions/#permission-on-issues
73+
issues: write
74+
75+
# Search repositories, list collaborators, and access repository metadata.
76+
# https://developer.github.com/v3/apps/permissions/#metadata-permissions
77+
metadata: read
78+
79+
# Retrieve Pages statuses, configuration, and builds, as well as create new builds.
80+
# https://developer.github.com/v3/apps/permissions/#permission-on-pages
81+
# pages: read
82+
83+
# Pull requests and related comments, assignees, labels, milestones, and merges.
84+
# https://developer.github.com/v3/apps/permissions/#permission-on-pull-requests
85+
# pull_requests: read
86+
87+
# Manage the post-receive hooks for a repository.
88+
# https://developer.github.com/v3/apps/permissions/#permission-on-repository-hooks
89+
# repository_hooks: read
90+
91+
# Manage repository projects, columns, and cards.
92+
# https://developer.github.com/v3/apps/permissions/#permission-on-repository-projects
93+
# repository_projects: read
94+
95+
# Retrieve security vulnerability alerts.
96+
# https://developer.github.com/v4/object/repositoryvulnerabilityalert/
97+
# vulnerability_alerts: read
98+
99+
# Commit statuses.
100+
# https://developer.github.com/v3/apps/permissions/#permission-on-statuses
101+
# statuses: read
102+
103+
# Organization members and teams.
104+
# https://developer.github.com/v3/apps/permissions/#permission-on-members
105+
# members: read
106+
107+
# View and manage users blocked by the organization.
108+
# https://developer.github.com/v3/apps/permissions/#permission-on-organization-user-blocking
109+
# organization_user_blocking: read
110+
111+
# Manage organization projects, columns, and cards.
112+
# https://developer.github.com/v3/apps/permissions/#permission-on-organization-projects
113+
# organization_projects: read
114+
115+
# Manage team discussions and related comments.
116+
# https://developer.github.com/v3/apps/permissions/#permission-on-team-discussions
117+
# team_discussions: read
118+
119+
# Manage the post-receive hooks for an organization.
120+
# https://developer.github.com/v3/apps/permissions/#permission-on-organization-hooks
121+
# organization_hooks: read
122+
123+
# Get notified of, and update, content references.
124+
# https://developer.github.com/v3/apps/permissions/
125+
# organization_administration: read
126+
# The name of the GitHub App. Defaults to the name specified in package.json
127+
# name: My Probot App
128+
129+
# The homepage of your GitHub App.
130+
# url: https://example.com/
131+
132+
# A description of the GitHub App.
133+
# description: A description of my awesome app
134+
135+
# Set to true when your GitHub App is available to the public or false when it is only accessible to the owner of the app.
136+
# Default: true
137+
# public: false

apps/bot/fly.toml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# fly.toml app configuration file generated for hyprnote-bot on 2025-11-30T18:55:28+09:00
2+
#
3+
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
4+
#
5+
6+
app = 'hyprnote-bot'
7+
primary_region = 'sjc'
8+
9+
[build]
10+
dockerfile = "Dockerfile"
11+
12+
[deploy]
13+
strategy = 'bluegreen'
14+
15+
[http_service]
16+
internal_port = 3000
17+
force_https = true
18+
auto_stop_machines = 'stop'
19+
auto_start_machines = true
20+
min_machines_running = 1
21+
processes = ['app']
22+
23+
[http_service.concurrency]
24+
type = 'connections'
25+
hard_limit = 25
26+
soft_limit = 20
27+
28+
[[http_service.checks]]
29+
interval = '10s'
30+
timeout = '2s'
31+
grace_period = '5s'
32+
method = 'get'
33+
path = '/health'
34+
35+
[[vm]]
36+
memory = '1gb'
37+
cpu_kind = 'shared'
38+
cpus = 1

apps/bot/package.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "@hypr/bot",
3+
"version": "1.0.0",
4+
"private": true,
5+
"scripts": {
6+
"build": "tsc",
7+
"typecheck": "tsc --noEmit",
8+
"start": "probot run ./lib/index.js",
9+
"test": "vitest run"
10+
},
11+
"dependencies": {
12+
"probot": "^13.4.5"
13+
},
14+
"devDependencies": {
15+
"@types/node": "^20.0.0",
16+
"nock": "^14.0.5",
17+
"smee-client": "^2.0.0",
18+
"vitest": "^2.0.0",
19+
"typescript": "^5.8.3"
20+
},
21+
"overrides": {
22+
"@types/pg": "8.15.1"
23+
},
24+
"engines": {
25+
"node": ">= 18"
26+
},
27+
"type": "module"
28+
}

apps/bot/src/index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { ApplicationFunctionOptions, Probot } from "probot";
2+
3+
export default (app: Probot, { getRouter }: ApplicationFunctionOptions) => {
4+
if (getRouter) {
5+
const router = getRouter("/");
6+
7+
router.get("/health", (_req, res) => {
8+
res.send("OK");
9+
});
10+
}
11+
12+
app.on("issues.opened", async (context) => {
13+
const issueComment = context.issue({
14+
body: "Thanks for opening this issue!",
15+
});
16+
await context.octokit.issues.createComment(issueComment);
17+
});
18+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"action": "opened",
3+
"issue": {
4+
"number": 1,
5+
"user": {
6+
"login": "hiimbex"
7+
}
8+
},
9+
"repository": {
10+
"name": "testing-things",
11+
"owner": {
12+
"login": "hiimbex"
13+
}
14+
},
15+
"installation": {
16+
"id": 2
17+
}
18+
}

0 commit comments

Comments
 (0)