mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-07-04 21:45:26 +02:00
refactor(bitbucket): simplify extractCommitedPaths function by using Bitbucket type and centralized header generation
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user