feat(client): transform app url to editor (#41858)

pull/41874/head
Shaun Hamilton 2021-04-20 22:47:42 +01:00 committed by GitHub
parent 6e481cd193
commit fd955635e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 1 deletions

View File

@ -8,6 +8,7 @@ import {
projectFormValuesSelector
} from '../redux';
import { tap, mapTo } from 'rxjs/operators';
import { transformEditorLink } from '../utils';
import envData from '../../../../../config/env.json';
const { forumLocation } = envData;
@ -63,7 +64,7 @@ function createQuestionEpic(action$, state$, { window }) {
}
${
projectFormValues
?.map(([key, val]) => `${key}: ${val}\n`)
?.map(([key, val]) => `${key}: ${transformEditorLink(val)}\n`)
?.join('') || filesToMarkdown(files)
}

View File

@ -0,0 +1,32 @@
/* global expect */
import { transformEditorLink } from '../utils';
describe('create-question-epic', () => {
describe('transformEditorLink', () => {
const links = [
{
input: 'https://some-project.camperbot.repl.co',
expected: 'https://replit.com/@camperbot/some-project'
},
{
input: 'https://some-project.glitch.me/',
expected: 'https://glitch.com/edit/#!/some-project'
},
{
input: 'https://github.com/user/repo-name',
expected: 'https://github.com/user/repo-name'
}
];
it('should correctly transform app links to editor links', () => {
links.forEach(link => {
expect(transformEditorLink(link.input)).toStrictEqual(link.expected);
});
});
it('should not transform editor links in GitHub submission', () => {
links.forEach(link => {
expect(transformEditorLink(link.expected)).toStrictEqual(link.expected);
});
});
});
});

View File

@ -13,3 +13,15 @@ export function isGoodXHRStatus(status) {
const statusInt = parseInt(status, 10);
return (statusInt >= 200 && statusInt < 400) || statusInt === 402;
}
export function transformEditorLink(url) {
return url
.replace(
/(?<=\/\/)(?<projectname>[^.]+)\.(?<username>[^.]+)\.repl\.co\/?/,
'replit.com/@$<username>/$<projectname>'
)
.replace(
/(?<=\/\/)(?<projectname>[^.]+)\.glitch\.me\/?/,
'glitch.com/edit/#!/$<projectname>'
);
}