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:
parent
3feead31d9
commit
f65822ca7e
@ -51,7 +51,12 @@ import {
|
|||||||
findPreviewDeploymentById,
|
findPreviewDeploymentById,
|
||||||
updatePreviewDeployment,
|
updatePreviewDeployment,
|
||||||
} from "./preview-deployment";
|
} from "./preview-deployment";
|
||||||
import { getIssueComment, updateIssueComment } from "./github";
|
import {
|
||||||
|
createPreviewDeploymentComment,
|
||||||
|
getIssueComment,
|
||||||
|
issueCommentExists,
|
||||||
|
updateIssueComment,
|
||||||
|
} from "./github";
|
||||||
import { type Domain, getDomainHost } from "./domain";
|
import { type Domain, getDomainHost } from "./domain";
|
||||||
export type Application = typeof applications.$inferSelect;
|
export type Application = typeof applications.$inferSelect;
|
||||||
|
|
||||||
@ -401,6 +406,27 @@ export const deployPreviewApplication = async ({
|
|||||||
githubId: application?.githubId || "",
|
githubId: application?.githubId || "",
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
|
const commentExists = await issueCommentExists({
|
||||||
|
...issueParams,
|
||||||
|
});
|
||||||
|
if (!commentExists) {
|
||||||
|
const result = await createPreviewDeploymentComment({
|
||||||
|
...issueParams,
|
||||||
|
previewDomain,
|
||||||
|
appName: previewDeployment.appName,
|
||||||
|
githubId: application?.githubId || "",
|
||||||
|
previewDeploymentId,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!result) {
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "NOT_FOUND",
|
||||||
|
message: "Pull request comment not found",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
issueParams.comment_id = Number.parseInt(result?.pullRequestCommentId);
|
||||||
|
}
|
||||||
const buildingComment = getIssueComment(
|
const buildingComment = getIssueComment(
|
||||||
application.name,
|
application.name,
|
||||||
"running",
|
"running",
|
||||||
@ -487,6 +513,27 @@ export const deployRemotePreviewApplication = async ({
|
|||||||
githubId: application?.githubId || "",
|
githubId: application?.githubId || "",
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
|
const commentExists = await issueCommentExists({
|
||||||
|
...issueParams,
|
||||||
|
});
|
||||||
|
if (!commentExists) {
|
||||||
|
const result = await createPreviewDeploymentComment({
|
||||||
|
...issueParams,
|
||||||
|
previewDomain,
|
||||||
|
appName: previewDeployment.appName,
|
||||||
|
githubId: application?.githubId || "",
|
||||||
|
previewDeploymentId,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!result) {
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "NOT_FOUND",
|
||||||
|
message: "Pull request comment not found",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
issueParams.comment_id = Number.parseInt(result?.pullRequestCommentId);
|
||||||
|
}
|
||||||
const buildingComment = getIssueComment(
|
const buildingComment = getIssueComment(
|
||||||
application.name,
|
application.name,
|
||||||
"running",
|
"running",
|
||||||
|
@ -7,6 +7,7 @@ import {
|
|||||||
import { TRPCError } from "@trpc/server";
|
import { TRPCError } from "@trpc/server";
|
||||||
import { eq } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
import { authGithub } from "../utils/providers/github";
|
import { authGithub } from "../utils/providers/github";
|
||||||
|
import { updatePreviewDeployment } from "./preview-deployment";
|
||||||
|
|
||||||
export type Github = typeof github.$inferSelect;
|
export type Github = typeof github.$inferSelect;
|
||||||
export const createGithub = async (
|
export const createGithub = async (
|
||||||
@ -97,7 +98,31 @@ export const getIssueComment = (
|
|||||||
|
|
||||||
return finished;
|
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 {
|
interface Comment {
|
||||||
owner: string;
|
owner: string;
|
||||||
repository: string;
|
repository: string;
|
||||||
@ -106,7 +131,6 @@ interface Comment {
|
|||||||
comment_id: number;
|
comment_id: number;
|
||||||
githubId: string;
|
githubId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const updateIssueComment = async ({
|
export const updateIssueComment = async ({
|
||||||
owner,
|
owner,
|
||||||
repository,
|
repository,
|
||||||
@ -126,3 +150,43 @@ export const updateIssueComment = async ({
|
|||||||
comment_id: comment_id,
|
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]);
|
||||||
|
};
|
||||||
|
@ -205,8 +205,6 @@ export const createPreviewDeployment = async (
|
|||||||
|
|
||||||
application.appName = appName;
|
application.appName = appName;
|
||||||
|
|
||||||
console.log(application);
|
|
||||||
|
|
||||||
await manageDomain(application, newDomain);
|
await manageDomain(application, newDomain);
|
||||||
|
|
||||||
await db
|
await db
|
||||||
|
Loading…
Reference in New Issue
Block a user