Skip to content

Commit

Permalink
refactor - added requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Chigala committed Mar 19, 2024
1 parent dd26345 commit 755131e
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 17 deletions.
4 changes: 2 additions & 2 deletions app/api/trigger/route.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { createAppRoute } from "@trigger.dev/nextjs";
import { client } from "@/trigger";
import { triggerDotDevClient } from "@/trigger";

import "@/jobs";

//this route is used to send and receive data with Trigger.dev
export const { POST, dynamic } = createAppRoute(client);
export const { POST, dynamic } = createAppRoute(triggerDotDevClient);

//uncomment this to set a higher max duration (it must be inside your plan limits). Full docs: https://vercel.com/docs/functions/serverless-functions/runtimes#max-duration
//export const maxDuration = 60;
3 changes: 3 additions & 0 deletions env.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,8 @@ export const env = createEnv({
GITHUB_APP_PRIVATE_KEY: process.env.GITHUB_APP_PRIVATE_KEY,
GITHUB_APP_SLUG: process.env.GITHUB_APP_SLUG,
GITHUB_APP_ACCESS_TOKEN: process.env.GITHUB_APP_ACCESS_TOKEN,
TRIGGER_API_KEY: process.env.TRIGGER_API_KEY,
TRIGGER_API_URL: process.env.TRIGGER_API_URL,
NEXT_PUBLIC_TRIGGER_PUBLIC_API_KEY: process.env.NEXT_PUBLIC_TRIGGER_PUBLIC_API_KEY,
},
});
27 changes: 19 additions & 8 deletions jobs/issueReminder.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
import { getOctokitInstance } from "@/lib/github/utils";
import { client } from "@/trigger";
import { triggerDotDevClient } from "@/trigger";
import { eventTrigger } from "@trigger.dev/sdk";
import { z } from "zod";

client.defineJob({

//TODO: This doesn't look so good rightnow.

// 1. create a waitUntil function to wait for an instance when a pull request is created(would need to listen for a pullrequest webhook) for the issue by the commenter

// 2. if no pull request is created after 36hrs(this would be the timeout of the waitUntil function), which is the time out send a reminder(this should be a task!)

// 3. io.wait(12hrs), another task to check if a pull request has been created, if not, send a comment to the issue that the commenter has been unassigned from the issue and anyone can take it up.

// Extract the pull request checker into it's own function for DRY purposes

triggerDotDevClient.defineJob({
// This is the unique identifier for your Job, it must be unique across all Jobs in your project.
id: "issue-remainder-job",
name: "issue remainder job",
id: "issue-reminder-job",
name: "issue reminder job",
version: "0.0.1",
// This is triggered by an event using eventTrigger. You can also trigger Jobs with webhooks, on schedules, and more: https://trigger.dev/docs/documentation/concepts/triggers/introduction
trigger: eventTrigger({
name: "issue.remainder",
name: "issue.reminder",
schema: z.object({
issueNumber: z.number(),
repo: z.string(),
Expand All @@ -27,7 +38,7 @@ client.defineJob({
//wait for 36hrs
await io.wait("waiting for 36hrs",36 * 60 * 60);

//make this a task so that it can return the completed value from the prev run
//made this a task so it can return the completed value from the prev run
await io.runTask("pull-request-checker", async () => {
const { data: issue } = await octokit.issues.get({
owner: owner,
Expand All @@ -39,7 +50,7 @@ client.defineJob({
io.logger.info("pull request has been created for the issue after 36hrs");
return;
} else {
//send a comment remainder to the issue
//send a comment reminder to the issue
io.logger.info("pull request has not been created for the issue after 36hrs, sending a reminder");
await octokit.issues.createComment({
owner,
Expand Down Expand Up @@ -80,4 +91,4 @@ client.defineJob({
});

},
});
});
4 changes: 4 additions & 0 deletions lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ export const GITHUB_APP_SLUG = env.GITHUB_APP_SLUG as string;
export const GITHUB_APP_ACCESS_TOKEN = env.GITHUB_APP_ACCESS_TOKEN as string;

export const OSS_GG_LABEL = "🕹️ oss.gg" as const;

// Trigger.dev
export const TRIGGER_API_KEY = env.TRIGGER_API_KEY as string;
export const TRIGGER_API_URL = env.TRIGGER_API_URL as string;
8 changes: 4 additions & 4 deletions lib/github/hooks/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { assignUserPoints } from "@/lib/points/service";
import { getRepositoryByGithubId } from "@/lib/repository/service";
import { createUser, getUser, getUserByGithubId } from "@/lib/user/service";
import { client } from "@/trigger";
import { triggerDotDevClient } from "@/trigger";
import { Webhooks } from "@octokit/webhooks";

import { getOctokitInstance } from "../utils";
Expand All @@ -20,7 +20,7 @@ export const onIssueOpened = async (webhooks: Webhooks) => {

//TODO:
//1. check if the issue has the oss label
//2. if it has the OSS label find all the users that are currently subscribed to the repo and have the right points, then send them an email
//2. if it has the OSS label find all the users that are currently subscribed to the repo, have the right points/permission, then send them an email

// const isProjectRegistered = await getProject(projectId)
// if (!isProjectRegistered) {
Expand Down Expand Up @@ -109,8 +109,8 @@ export const onAssignCommented = async (webhooks: Webhooks) => {
});

//send trigger event to wait for 36hrs then send a reminder if the user has not created a pull request
await client.sendEvent({
name: "issue.remainder",
await triggerDotDevClient.sendEvent({
name: "issue.reminder",
payload: {
issueNumber,
repo,
Expand Down
7 changes: 4 additions & 3 deletions trigger.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { TriggerClient } from "@trigger.dev/sdk";
import { TRIGGER_API_KEY, TRIGGER_API_URL } from "@/lib/constants";

export const client = new TriggerClient({
export const triggerDotDevClient = new TriggerClient({
id: "testing-bHhV",
apiKey: process.env.TRIGGER_API_KEY,
apiUrl: process.env.TRIGGER_API_URL,
apiKey: TRIGGER_API_KEY,
apiUrl: TRIGGER_API_URL,
});

0 comments on commit 755131e

Please sign in to comment.