|
1 | 1 | import type { Job } from "bullmq";
|
2 |
| -import { createProbot } from "probot"; |
3 |
| -import { SchedulerJobData } from "@wei/probot-scheduler"; |
| 2 | +import type { SchedulerJobData } from "@wei/probot-scheduler"; |
| 3 | +import type { Probot } from "probot"; |
4 | 4 | import logger from "@/src/utils/logger.ts";
|
5 | 5 | import { getPullConfig } from "@/src/utils/get-pull-config.ts";
|
6 | 6 | import { Pull } from "@/src/processor/pull.ts";
|
7 | 7 |
|
8 |
| -export default async function RepoJobProcessor(job: Job<SchedulerJobData>) { |
9 |
| - const log = logger.child({ |
10 |
| - jobId: job.id, |
11 |
| - jobData: job.data, |
12 |
| - }); |
| 8 | +export function getRepoProcessor(probot: Probot) { |
| 9 | + return async function RepoJobProcessor(job: Job<SchedulerJobData>) { |
| 10 | + const log = logger.child({ |
| 11 | + jobId: job.id, |
| 12 | + jobData: job.data, |
| 13 | + }); |
13 | 14 |
|
14 |
| - log.info("🏃 Processing repo job"); |
| 15 | + log.info("🏃 Processing repo job"); |
15 | 16 |
|
16 |
| - const { installation_id, owner, repo } = job.data; |
| 17 | + const { installation_id, owner, repo } = job.data; |
17 | 18 |
|
18 |
| - try { |
19 |
| - // Get Octokit |
20 |
| - const probot = createProbot({ overrides: { log } }); |
21 |
| - const octokit = await probot.auth(installation_id); |
| 19 | + try { |
| 20 | + const octokit = await probot.auth(installation_id); |
22 | 21 |
|
23 |
| - const config = await getPullConfig(octokit, log, job.data); |
24 |
| - if (!config) { |
25 |
| - log.info(`⚠️ No config found, skipping`); |
26 |
| - return; |
27 |
| - } |
| 22 | + const config = await getPullConfig(octokit, log, job.data); |
| 23 | + if (!config) { |
| 24 | + log.info(`⚠️ No config found, skipping`); |
| 25 | + return; |
| 26 | + } |
28 | 27 |
|
29 |
| - const pull = new Pull(octokit, { owner, repo, logger: log }, config); |
30 |
| - await pull.routineCheck(); |
| 28 | + const pull = new Pull(octokit, { owner, repo, logger: log }, config); |
| 29 | + await pull.routineCheck(); |
31 | 30 |
|
32 |
| - log.info(`✅ Repo job ${job.id} processed successfully`); |
33 |
| - } catch (error) { |
34 |
| - log.error(error, "❌ Repo job failed"); |
35 |
| - } |
| 31 | + log.info(`✅ Repo job ${job.id} processed successfully`); |
| 32 | + } catch (error) { |
| 33 | + log.error(error, "❌ Repo job failed"); |
| 34 | + } |
| 35 | + }; |
36 | 36 | }
|
0 commit comments