Skip to content

Commit 272c7fb

Browse files
authored
Merge pull request #183 from fairdataihub/central-api
feat: ✨ Probot transfer midpoint
2 parents d0cac2e + b718c07 commit 272c7fb

47 files changed

Lines changed: 5270 additions & 541 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ For detailed instructions on setting up running the application locally, please
8080

8181
## How Codefair is developed
8282

83-
Codefair is developed using [Probot](https://probot.github.io/docs/) and is deployed on a server as a serverless function. The GitHub app is configured to receive webhooks for important actions such as pushing code, opening or closing issues, opening or merging pull requests and commenting on discussions.
84-
By leveraging a serverless environment on a server, Codefair can automatically scale to handle the workload of the GitHub app. The app is written in [Node.js](https://nodejs.org/en) and utilizes the [Octokit library](https://github.com/octokit) to interact with the GitHub API enabling seamless integration with GitHub's features and functionality.
83+
Codefair is developed using [Octokit](https://github.com/octokit) and [Nuxt](https://nuxt.com/), and is deployed on a virtual machine hosted on Azure. The GitHub app is configured to receive webhooks for important actions such as pushing code, opening or closing issues, opening or merging pull requests, and commenting on discussions. These events drive Codefair's automated workflows, enabling seamless integration with GitHub's features and functionality.
8584

8685
## Contributing
8786

bot/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build stage
2-
FROM node:20-slim AS builder
2+
FROM node:22-slim AS builder
33

44
# Combine RUN commands to reduce layers and cleanup in the same layer
55
RUN apt-get update -y \
@@ -26,7 +26,7 @@ RUN yarn install --frozen-lockfile --production \
2626
&& yarn cache clean
2727

2828
# App stage
29-
FROM node:20-slim
29+
FROM node:22-slim
3030

3131
LABEL maintainer="FAIR Data Innovations Hub <contact@fairdataihub.org>"
3232
LABEL description="Your coding assistant to make research software reusable without breaking a sweat!"

bot/Dockerfile.dev

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build stage
2-
FROM node:20-slim AS builder
2+
FROM node:22-slim AS builder
33

44
# Combine RUN commands to reduce layers and cleanup in the same layer
55
RUN apt-get update -y \
@@ -19,7 +19,7 @@ RUN yarn install --frozen-lockfile --production \
1919
&& yarn cache clean
2020

2121
# App stage
22-
FROM node:20-slim
22+
FROM node:22-slim
2323

2424
LABEL maintainer="FAIR Data Innovations Hub <contact@fairdataihub.org>"
2525
LABEL description="Your coding assistant to make research software reusable without breaking a sweat!"

bot/handlers/issue.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ export function registerIssueHandlers(app, db) {
9494
});
9595

9696
if (installation) {
97+
// Repository is managed by the Nuxt central API
98+
if (installation.use_central_api) {
99+
logwatch.info(
100+
`[issues.edited] ${context.payload.repository.name} uses central API, skipping Probot handler`
101+
);
102+
return;
103+
}
104+
97105
// Verify for repository name change
98106
verifyRepoName(
99107
installation.repo,
@@ -153,6 +161,15 @@ export function registerIssueHandlers(app, db) {
153161
const issueAuthor = context.payload.issue.user.login;
154162

155163
if (issueTitle === ISSUE_TITLE && issueAuthor === `${GH_APP_NAME}[bot]`) {
164+
const installation = await db.installation.findUnique({
165+
where: { id: repository.id },
166+
});
167+
if (installation?.use_central_api) {
168+
logwatch.info(
169+
`[issues.reopened] ${repository.name} uses central API, skipping Probot handler`
170+
);
171+
return;
172+
}
156173
// Check if the repository is empty
157174
const emptyRepo = await isRepoEmpty(context, owner, repository.name);
158175

bot/handlers/pullRequest.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ export function registerPullRequestHandlers(app, db) {
6363
}
6464
}
6565

66-
// Re-render dashboard from database (no compliance checks needed - code hasn't merged yet)
67-
logwatch.info("PR opened, re-rendering dashboard to show PR badge");
68-
await reRenderDashboard(context, owner, repository, "");
66+
// skip for central-API repos
67+
if (!installation.use_central_api) {
68+
logwatch.info("PR opened, re-rendering dashboard to show PR badge");
69+
await reRenderDashboard(context, owner, repository, "");
70+
}
6971
});
7072

7173
// When a pull request is closed
@@ -79,6 +81,10 @@ export function registerPullRequestHandlers(app, db) {
7981
const { repository } = context.payload;
8082
const prTitle = context.payload.pull_request.title;
8183

84+
const installation = await db.installation.findUnique({
85+
where: { id: repository.id },
86+
});
87+
8288
// Clear PR URL from database based on PR type
8389
if (prTitle === PR_TITLES.license) {
8490
const response = await db.licenseRequest.update({
@@ -105,11 +111,11 @@ export function registerPullRequestHandlers(app, db) {
105111
}
106112
}
107113

108-
// Re-render dashboard from database (no compliance checks needed)
109-
// If PR was merged, the push event will trigger full compliance checks
110-
// If PR was closed without merge, we just need to remove the PR badge
111-
logwatch.info("PR closed, re-rendering dashboard to remove PR badge");
112-
await reRenderDashboard(context, owner, repository, "");
114+
// skip for central-API repos
115+
if (!installation.use_central_api) {
116+
logwatch.info("PR closed, re-rendering dashboard to remove PR badge");
117+
await reRenderDashboard(context, owner, repository, "");
118+
}
113119

114120
// Delete the branch
115121
const branchName = context.payload.pull_request.head.ref;

bot/handlers/push.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ export function registerPushHandler(app, db) {
4949

5050
if (!installation || installation.disabled) {
5151
return;
52+
}
53+
54+
// Repository is handled by the Nuxt central API
55+
if (installation.use_central_api) {
56+
logwatch.info(
57+
`[push] ${repository.name} uses central API, skipping Probot handler`
58+
);
59+
return;
5260
} else {
5361
// Verify if repository name has changed and update commit details to db
5462
verifyRepoName(installation.repo, repository, owner, db.installation);

0 commit comments

Comments
 (0)