mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
refactor: recreate message when is deleted
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { authGithub } from "../utils/providers/github";
|
||||
import { updatePreviewDeployment } from "./preview-deployment";
|
||||
|
||||
export type Github = typeof github.$inferSelect;
|
||||
export const createGithub = async (
|
||||
@@ -97,7 +98,31 @@ export const getIssueComment = (
|
||||
|
||||
return finished;
|
||||
};
|
||||
|
||||
interface CommentExists {
|
||||
owner: string;
|
||||
repository: string;
|
||||
comment_id: number;
|
||||
githubId: string;
|
||||
}
|
||||
export const issueCommentExists = async ({
|
||||
owner,
|
||||
repository,
|
||||
comment_id,
|
||||
githubId,
|
||||
}: CommentExists) => {
|
||||
const github = await findGithubById(githubId);
|
||||
const octokit = authGithub(github);
|
||||
try {
|
||||
await octokit.rest.issues.getComment({
|
||||
owner: owner || "",
|
||||
repo: repository || "",
|
||||
comment_id: comment_id,
|
||||
});
|
||||
return true;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
interface Comment {
|
||||
owner: string;
|
||||
repository: string;
|
||||
@@ -106,7 +131,6 @@ interface Comment {
|
||||
comment_id: number;
|
||||
githubId: string;
|
||||
}
|
||||
|
||||
export const updateIssueComment = async ({
|
||||
owner,
|
||||
repository,
|
||||
@@ -126,3 +150,43 @@ export const updateIssueComment = async ({
|
||||
comment_id: comment_id,
|
||||
});
|
||||
};
|
||||
|
||||
interface CommentCreate {
|
||||
appName: string;
|
||||
owner: string;
|
||||
repository: string;
|
||||
issue_number: string;
|
||||
previewDomain: string;
|
||||
githubId: string;
|
||||
previewDeploymentId: string;
|
||||
}
|
||||
|
||||
export const createPreviewDeploymentComment = async ({
|
||||
owner,
|
||||
repository,
|
||||
issue_number,
|
||||
previewDomain,
|
||||
appName,
|
||||
githubId,
|
||||
previewDeploymentId,
|
||||
}: CommentCreate) => {
|
||||
const github = await findGithubById(githubId);
|
||||
const octokit = authGithub(github);
|
||||
|
||||
const runningComment = getIssueComment(
|
||||
appName,
|
||||
"initializing",
|
||||
previewDomain,
|
||||
);
|
||||
|
||||
const issue = await octokit.rest.issues.createComment({
|
||||
owner: owner || "",
|
||||
repo: repository || "",
|
||||
issue_number: Number.parseInt(issue_number),
|
||||
body: `### Dokploy Preview Deployment\n\n${runningComment}`,
|
||||
});
|
||||
|
||||
return await updatePreviewDeployment(previewDeploymentId, {
|
||||
pullRequestCommentId: `${issue.data.id}`,
|
||||
}).then((response) => response[0]);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user