mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-29 22:58:49 +00: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 { eq } from "drizzle-orm";
|
||||||
import type { NextApiRequest, NextApiResponse } from "next";
|
import type { NextApiRequest, NextApiResponse } from "next";
|
||||||
import { db } from "@/server/db";
|
import { db } from "@/server/db";
|
||||||
@@ -146,12 +151,8 @@ export default async function handler(
|
|||||||
|
|
||||||
const commitedPaths = await extractCommitedPaths(
|
const commitedPaths = await extractCommitedPaths(
|
||||||
req.body,
|
req.body,
|
||||||
application.bitbucketOwner,
|
application.bitbucket,
|
||||||
application.bitbucket?.apiToken ||
|
|
||||||
application.bitbucket?.appPassword ||
|
|
||||||
"",
|
|
||||||
application.bitbucketRepository || "",
|
application.bitbucketRepository || "",
|
||||||
!!application.bitbucket?.apiToken,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const shouldDeployPaths = shouldDeploy(
|
const shouldDeployPaths = shouldDeploy(
|
||||||
@@ -358,10 +359,8 @@ export const getProviderByHeader = (headers: any) => {
|
|||||||
|
|
||||||
export const extractCommitedPaths = async (
|
export const extractCommitedPaths = async (
|
||||||
body: any,
|
body: any,
|
||||||
bitbucketUsername: string | null,
|
bitbucket: Bitbucket | null,
|
||||||
credential: string | null,
|
repository: string,
|
||||||
repository: string | null,
|
|
||||||
useApiToken: boolean,
|
|
||||||
) => {
|
) => {
|
||||||
const changes = body.push?.changes || [];
|
const changes = body.push?.changes || [];
|
||||||
|
|
||||||
@@ -370,15 +369,12 @@ export const extractCommitedPaths = async (
|
|||||||
.filter(Boolean);
|
.filter(Boolean);
|
||||||
const commitedPaths: string[] = [];
|
const commitedPaths: string[] = [];
|
||||||
for (const commit of commitHashes) {
|
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 {
|
try {
|
||||||
const headers = useApiToken
|
const response = await fetch(url, {
|
||||||
? { Authorization: `Bearer ${credential}` }
|
headers: getBitbucketHeaders(bitbucket!),
|
||||||
: {
|
});
|
||||||
Authorization: `Basic ${Buffer.from(`${bitbucketUsername}:${credential}`).toString("base64")}`,
|
|
||||||
};
|
|
||||||
const response = await fetch(url, { headers });
|
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
for (const value of data.values) {
|
for (const value of data.values) {
|
||||||
|
|||||||
Reference in New Issue
Block a user