-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Issue reminder job #19
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
68adf6c
trigger.dev setup
Chigala 83cd2a1
created a trigger event to dispatch a remainder job
Chigala 7c186a5
converted private key to PKCS#8 format
Chigala dd26345
updated trigger credential in env.example file
Chigala 755131e
refactor - added requested changes
Chigala d62be6b
refactored the issue reminder code
Chigala 5bc87ed
added pull_request_open webhook
Chigala 0e50352
revert: constant var chagne for ossgg label
ShubhamPalriwala c08ec9b
Merge branch 'main' of https://github.com/formbricks/oss.gg into feat…
ShubhamPalriwala File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { createAppRoute } from "@trigger.dev/nextjs"; | ||
import { triggerDotDevClient } from "@/trigger"; | ||
|
||
import "@/jobs"; | ||
|
||
//this route is used to send and receive data with Trigger.dev | ||
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// export all your job files here | ||
|
||
export * from "./issueReminder" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import { extractIssueNumbers, getOctokitInstance } from "@/lib/github/utils"; | ||
import { triggerDotDevClient } from "@/trigger"; | ||
import { Octokit } from "@octokit/rest"; | ||
import { eventTrigger } from "@trigger.dev/sdk"; | ||
import { z } from "zod"; | ||
|
||
const findPullRequestByIssueAndCommenter = async ( | ||
octokit: Octokit, | ||
owner: string, | ||
repo: string, | ||
issueNumber: number, | ||
commenter: string | ||
) => { | ||
const { data: pullRequests } = await octokit.pulls.list({ | ||
owner, | ||
repo, | ||
state: "open", | ||
}); | ||
const pullRequest = pullRequests.find(async (pr) => { | ||
const openedBy = pr.user?.login; | ||
const prBody = pr.body; | ||
const prIssueNumber = extractIssueNumbers(prBody!); | ||
|
||
// Return the PR that matches the issue number and belongs to the commenter | ||
return prIssueNumber.includes(issueNumber) && openedBy === commenter; | ||
}); | ||
|
||
return pullRequest; | ||
}; | ||
|
||
triggerDotDevClient.defineJob({ | ||
// This is the unique identifier for your Job, it must be unique across all Jobs in your project. | ||
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.reminder", | ||
schema: z.object({ | ||
issueNumber: z.number(), | ||
repo: z.string(), | ||
owner: z.string(), | ||
commenter: z.string(), | ||
installationId: z.number(), | ||
}), | ||
}), | ||
run: async (payload, io, ctx) => { | ||
const { issueNumber, repo, owner, commenter, installationId } = payload; | ||
const octokit = getOctokitInstance(installationId); | ||
|
||
//wait for 36hrs | ||
await io.wait("waiting for 36hrs", 36 * 60 * 60); | ||
|
||
//made this a task so it doesn't get replayed | ||
const taskValue = await io.runTask("36-hrs", async () => { | ||
const pullRequest = await findPullRequestByIssueAndCommenter( | ||
octokit, | ||
owner, | ||
repo, | ||
issueNumber, | ||
commenter | ||
); | ||
|
||
if (!!pullRequest) { | ||
io.logger.info("pull request has been created for the issue after 36hrs"); | ||
return { completed: true }; | ||
} else { | ||
//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, | ||
repo, | ||
issue_number: issueNumber, | ||
body: ` @${commenter}, You have 12hrs left to create a pull request for this issue. `, | ||
}); | ||
return { completed: false }; | ||
} | ||
}); | ||
|
||
if (taskValue?.completed) { | ||
return; | ||
} else { | ||
await io.wait("waiting for 12hrs", 12 * 60 * 60); | ||
|
||
await io.runTask("48-hrs", async () => { | ||
const pullRequest = await findPullRequestByIssueAndCommenter( | ||
octokit, | ||
owner, | ||
repo, | ||
issueNumber, | ||
commenter | ||
); | ||
|
||
if (!!pullRequest) { | ||
io.logger.info("pull request has been created for the issue within 48hrs"); | ||
return; | ||
} else { | ||
io.logger.info("pull request has not been created for the issue after 12hrs"); | ||
await octokit.issues.createComment({ | ||
owner: owner, | ||
repo: repo, | ||
issue_number: issueNumber, | ||
body: `@${commenter} has been unassigned from the issue, anyone can now take it up.`, | ||
}); | ||
await octokit.issues.removeAssignees({ | ||
owner: owner, | ||
repo: repo, | ||
issue_number: issueNumber, | ||
assignees: [commenter], | ||
}); | ||
} | ||
}); | ||
} | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if we should include this in this PR as things work just fine for now. Can you revert this change please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I revert this, it'll throw an error when the trigger job runs. I think that was why you weren't able to see the comment, I had the same issue while I was testing.