feat(client): transform app url to editor (#41858)
parent
6e481cd193
commit
fd955635e5
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -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>'
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue