diff --git a/public/images/gitlab.png b/public/images/gitlab.png new file mode 100644 index 000000000..85ec9e76f Binary files /dev/null and b/public/images/gitlab.png differ diff --git a/server/services/web.ts b/server/services/web.ts index c54e14b0d..76adabea4 100644 --- a/server/services/web.ts +++ b/server/services/web.ts @@ -24,9 +24,19 @@ import auth from "../routes/auth"; // Construct scripts CSP based on services in use by this installation const defaultSrc = ["'self'"]; -const scriptSrc = ["'self'", "gist.github.com", "www.googletagmanager.com"]; +const scriptSrc = [ + "'self'", + "gist.github.com", + "www.googletagmanager.com", + "gitlab.com", +]; -const styleSrc = ["'self'", "'unsafe-inline'", "github.githubassets.com"]; +const styleSrc = [ + "'self'", + "'unsafe-inline'", + "github.githubassets.com", + "gitlab.com", +]; if (env.isCloudHosted) { scriptSrc.push("cdn.zapier.com"); diff --git a/shared/editor/embeds/GitLabSnippet.test.ts b/shared/editor/embeds/GitLabSnippet.test.ts new file mode 100644 index 000000000..fbd1d5b90 --- /dev/null +++ b/shared/editor/embeds/GitLabSnippet.test.ts @@ -0,0 +1,31 @@ +import GitLabSnippet from "./GitLabSnippet"; + +describe("GitLabSnippet", () => { + const match = GitLabSnippet.ENABLED[0]; + + test("to be enabled on snippet link", () => { + expect("https://gitlab.com/-/snippets/1234".match(match)).toBeTruthy(); + expect( + "https://gitlab.com/gitlab-org/gitlab/-/snippets/2256824".match(match) + ).toBeTruthy(); + expect( + "https://gitlab.com/group/project/sub-project/sub-sub-project/test/-/snippets/9876".match( + match + ) + ).toBeTruthy(); + }); + + test("to not be enabled elsewhere", () => { + expect("https://gitlab.com".match(match)).toBe(null); + expect("https://gitlab.com/gitlab-org".match(match)).toBe(null); + expect("https://gitlab.com/gitlab-org/gitlab".match(match)).toBe(null); + expect("https://gitlab.com/gitlab-org/gitlab/-/issues".match(match)).toBe( + null + ); + expect( + "https://gitlab.com/gitlab-org/gitlab/-/merge_requests/137948".match( + match + ) + ).toBe(null); + }); +}); diff --git a/shared/editor/embeds/GitLabSnippet.tsx b/shared/editor/embeds/GitLabSnippet.tsx new file mode 100644 index 000000000..05bb38883 --- /dev/null +++ b/shared/editor/embeds/GitLabSnippet.tsx @@ -0,0 +1,38 @@ +import * as React from "react"; +import styled from "styled-components"; +import { EmbedProps as Props } from "."; + +const GITLAB_NAMESPACE_REGEX = "(([a-zA-Z\\d-]+)/)"; + +const Iframe = styled.iframe` + margin-top: 8px; +`; + +function GitLabSnippet(props: Props) { + const snippetUrl = new URL(props.attrs.href); + const id = snippetUrl.pathname.split("/").pop(); + const snippetLink = `${snippetUrl}.js`; + const snippetScript = ``; + const styles = ""; + const iframeHtml = `
,
component: Gist,
}),
+ new EmbedDescriptor({
+ title: "GitLab Snippet",
+ keywords: "code",
+ icon:
,
+ component: GitLabSnippet,
+ }),
new EmbedDescriptor({
title: "Gliffy",
keywords: "diagram",