mirror of
https://github.com/outline/outline.git
synced 2026-06-13 03:14:59 +03:00
chore: Remove gitbeaker dep on client (#11517)
Add dupe detection to gitlab install
This commit is contained in:
@@ -39,7 +39,7 @@ const Container = styled(Text)`
|
||||
border-radius: 4px;
|
||||
position: relative;
|
||||
font-size: 14px;
|
||||
margin: 1em 0 0;
|
||||
margin: 1em 0;
|
||||
|
||||
svg {
|
||||
flex-shrink: 0;
|
||||
|
||||
@@ -47,6 +47,10 @@ function GitLab() {
|
||||
You need to accept the permissions in GitLab to connect{" "}
|
||||
{{ appName }} to your workspace. Try again?
|
||||
</Trans>
|
||||
) : error === "duplicate_account" ? (
|
||||
<Trans>
|
||||
The GitLab account is already connected to this workspace.
|
||||
</Trans>
|
||||
) : (
|
||||
<Trans>
|
||||
Something went wrong while authenticating your request. Please try
|
||||
|
||||
@@ -184,6 +184,24 @@ router.get(
|
||||
customUrl,
|
||||
});
|
||||
|
||||
// Check if another integration already exists with the same installation
|
||||
const duplicateIntegration = await Integration.findOne({
|
||||
where: {
|
||||
service: IntegrationService.GitLab,
|
||||
teamId: user.teamId,
|
||||
settings: { gitlab: { installation: { id: userInfo.id } } },
|
||||
...(existingIntegration
|
||||
? { id: { [Op.ne]: existingIntegration.id } }
|
||||
: {}),
|
||||
},
|
||||
transaction,
|
||||
});
|
||||
|
||||
if (duplicateIntegration) {
|
||||
ctx.redirect(GitLabUtils.errorUrl("duplicate_account"));
|
||||
return;
|
||||
}
|
||||
|
||||
let authentication: IntegrationAuthentication;
|
||||
|
||||
if (pendingAuth) {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { Gitlab } from "@gitbeaker/rest";
|
||||
import env from "@shared/env";
|
||||
import { integrationSettingsPath } from "@shared/utils/routeHelpers";
|
||||
import { UnfurlResourceType } from "@shared/types";
|
||||
@@ -97,20 +96,6 @@ export class GitLabUtils {
|
||||
return `${this.url}?install_request=true`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Gitbeaker client instance.
|
||||
*
|
||||
* @param accessToken - The access token for authentication.
|
||||
* @param customUrl - Optional custom GitLab URL from integration settings.
|
||||
* @returns A configured Gitbeaker client.
|
||||
*/
|
||||
public static createClient(accessToken: string, customUrl?: string) {
|
||||
return new Gitlab({
|
||||
host: this.getGitlabUrl(customUrl),
|
||||
oauthToken: accessToken,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a GitLab URL and extracts resource identifiers.
|
||||
*
|
||||
@@ -192,57 +177,6 @@ export class GitLabUtils {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches an issue from a GitLab project.
|
||||
*
|
||||
* @param accessToken - The access token for authentication.
|
||||
* @param projectPath - The project path (owner/repo).
|
||||
* @param issueIid - The issue IID (internal ID within the project).
|
||||
* @param customUrl - Optional custom GitLab URL from integration settings.
|
||||
* @returns The issue data.
|
||||
*/
|
||||
public static async getIssue(
|
||||
accessToken: string,
|
||||
projectPath: string,
|
||||
issueIid: number,
|
||||
customUrl?: string
|
||||
) {
|
||||
const client = this.createClient(accessToken, customUrl);
|
||||
|
||||
const issues = await client.Issues.all({
|
||||
projectId: projectPath,
|
||||
iids: [issueIid],
|
||||
withLabelsDetails: true,
|
||||
});
|
||||
|
||||
if (!issues || issues.length === 0) {
|
||||
throw new Error(`Issue ${issueIid} not found in project ${projectPath}`);
|
||||
}
|
||||
|
||||
return issues[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a merge request from a GitLab project.
|
||||
*
|
||||
* @param accessToken - The access token for authentication.
|
||||
* @param projectPath - The project path (owner/repo).
|
||||
* @param mrIid - The merge request IID (internal ID within the project).
|
||||
* @param customUrl - Optional custom GitLab URL from integration settings.
|
||||
* @returns The merge request data.
|
||||
*/
|
||||
public static async getMergeRequest(
|
||||
accessToken: string,
|
||||
projectPath: string,
|
||||
mrIid: number,
|
||||
customUrl?: string
|
||||
) {
|
||||
const client = this.createClient(accessToken, customUrl);
|
||||
// MergeRequests.show properly accepts projectId and mergerequestIId
|
||||
const mr = await client.MergeRequests.show(projectPath, mrIid);
|
||||
return mr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the color associated with a given status.
|
||||
*
|
||||
|
||||
@@ -1449,6 +1449,7 @@
|
||||
"Self-managed": "Self-managed",
|
||||
"Connect to a custom GitLab installation": "Connect to a custom GitLab installation",
|
||||
"You need to accept the permissions in GitLab to connect {{appName}} to your workspace. Try again?": "You need to accept the permissions in GitLab to connect {{appName}} to your workspace. Try again?",
|
||||
"The GitLab account is already connected to this workspace.": "The GitLab account is already connected to this workspace.",
|
||||
"Something went wrong while authenticating your request. Please try again.": "Something went wrong while authenticating your request. Please try again.",
|
||||
"The owner of GitLab account has been requested to install the application. Once approved, the connection will be completed.": "The owner of GitLab account has been requested to install the application. Once approved, the connection will be completed.",
|
||||
"Enable previews of GitLab issues and merge requests in documents by connecting a GitLab organization or specific repositories to {appName}.": "Enable previews of GitLab issues and merge requests in documents by connecting a GitLab organization or specific repositories to {appName}.",
|
||||
|
||||
Reference in New Issue
Block a user