From 8b88c85b37ac34d702059c9e6ac6214e6fe6b093 Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Sun, 21 Sep 2025 15:14:15 -0600 Subject: [PATCH] refactor(bitbucket): simplify extractCommitedPaths function by using Bitbucket type and centralized header generation --- .../pages/api/deploy/[refreshToken].ts | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/apps/dokploy/pages/api/deploy/[refreshToken].ts b/apps/dokploy/pages/api/deploy/[refreshToken].ts index ea6a081bb..63d927568 100644 --- a/apps/dokploy/pages/api/deploy/[refreshToken].ts +++ b/apps/dokploy/pages/api/deploy/[refreshToken].ts @@ -1,4 +1,9 @@ -import { IS_CLOUD, shouldDeploy } from "@dokploy/server"; +import { + type Bitbucket, + getBitbucketHeaders, + IS_CLOUD, + shouldDeploy, +} from "@dokploy/server"; import { eq } from "drizzle-orm"; import type { NextApiRequest, NextApiResponse } from "next"; import { db } from "@/server/db"; @@ -146,12 +151,8 @@ export default async function handler( const commitedPaths = await extractCommitedPaths( req.body, - application.bitbucketOwner, - application.bitbucket?.apiToken || - application.bitbucket?.appPassword || - "", + application.bitbucket, application.bitbucketRepository || "", - !!application.bitbucket?.apiToken, ); const shouldDeployPaths = shouldDeploy( @@ -358,10 +359,8 @@ export const getProviderByHeader = (headers: any) => { export const extractCommitedPaths = async ( body: any, - bitbucketUsername: string | null, - credential: string | null, - repository: string | null, - useApiToken: boolean, + bitbucket: Bitbucket | null, + repository: string, ) => { const changes = body.push?.changes || []; @@ -370,15 +369,12 @@ export const extractCommitedPaths = async ( .filter(Boolean); const commitedPaths: string[] = []; for (const commit of commitHashes) { - const url = `https://api.bitbucket.org/2.0/repositories/${bitbucketUsername}/${repository}/diffstat/${commit}`; + const url = `https://api.bitbucket.org/2.0/repositories/${bitbucket?.bitbucketUsername}/${repository}/diffstat/${commit}`; try { - const headers = useApiToken - ? { Authorization: `Bearer ${credential}` } - : { - Authorization: `Basic ${Buffer.from(`${bitbucketUsername}:${credential}`).toString("base64")}`, - }; - const response = await fetch(url, { headers }); + const response = await fetch(url, { + headers: getBitbucketHeaders(bitbucket!), + }); const data = await response.json(); for (const value of data.values) {