mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-12 15:05:19 +00:00
refactor(bitbucket): Extract duplicated code to a function
This commit is contained in:
@@ -39,6 +39,18 @@ export const getBitbucketCloneUrl = (
|
|||||||
: `https://${bitbucketProvider.bitbucketUsername}:${bitbucketProvider.appPassword}@${repoClone}`;
|
: `https://${bitbucketProvider.bitbucketUsername}:${bitbucketProvider.appPassword}@${repoClone}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getBitbucketHeaders = (bitbucketProvider: {
|
||||||
|
apiToken?: string | null;
|
||||||
|
bitbucketUsername?: string | null;
|
||||||
|
appPassword?: string | null;
|
||||||
|
}) => {
|
||||||
|
return bitbucketProvider.apiToken
|
||||||
|
? { Authorization: `Bearer ${bitbucketProvider.apiToken}` }
|
||||||
|
: {
|
||||||
|
Authorization: `Basic ${Buffer.from(`${bitbucketProvider.bitbucketUsername}:${bitbucketProvider.appPassword}`).toString("base64")}`,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
export const cloneBitbucketRepository = async (
|
export const cloneBitbucketRepository = async (
|
||||||
entity: ApplicationWithBitbucket | ComposeWithBitbucket,
|
entity: ApplicationWithBitbucket | ComposeWithBitbucket,
|
||||||
logPath: string,
|
logPath: string,
|
||||||
@@ -257,11 +269,7 @@ export const getBitbucketRepositories = async (bitbucketId?: string) => {
|
|||||||
while (url) {
|
while (url) {
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: bitbucketProvider.apiToken
|
headers: getBitbucketHeaders(bitbucketProvider),
|
||||||
? { Authorization: `Bearer ${bitbucketProvider.apiToken}` }
|
|
||||||
: {
|
|
||||||
Authorization: `Basic ${Buffer.from(`${bitbucketProvider.bitbucketUsername}:${bitbucketProvider.appPassword}`).toString("base64")}`,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
@@ -302,11 +310,7 @@ export const getBitbucketBranches = async (
|
|||||||
try {
|
try {
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: bitbucketProvider.apiToken
|
headers: getBitbucketHeaders(bitbucketProvider),
|
||||||
? { Authorization: `Bearer ${bitbucketProvider.apiToken}` }
|
|
||||||
: {
|
|
||||||
Authorization: `Basic ${Buffer.from(`${bitbucketProvider.bitbucketUsername}:${bitbucketProvider.appPassword}`).toString("base64")}`,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
@@ -355,11 +359,7 @@ export const testBitbucketConnection = async (
|
|||||||
try {
|
try {
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: bitbucketProvider.apiToken
|
headers: getBitbucketHeaders(bitbucketProvider),
|
||||||
? { Authorization: `Bearer ${bitbucketProvider.apiToken}` }
|
|
||||||
: {
|
|
||||||
Authorization: `Basic ${Buffer.from(`${bitbucketProvider.bitbucketUsername}:${bitbucketProvider.appPassword}`).toString("base64")}`,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
|||||||
Reference in New Issue
Block a user