feat(client): transform app url to editor (#41858)
This commit is contained in:
@ -8,6 +8,7 @@ import {
|
|||||||
projectFormValuesSelector
|
projectFormValuesSelector
|
||||||
} from '../redux';
|
} from '../redux';
|
||||||
import { tap, mapTo } from 'rxjs/operators';
|
import { tap, mapTo } from 'rxjs/operators';
|
||||||
|
import { transformEditorLink } from '../utils';
|
||||||
import envData from '../../../../../config/env.json';
|
import envData from '../../../../../config/env.json';
|
||||||
|
|
||||||
const { forumLocation } = envData;
|
const { forumLocation } = envData;
|
||||||
@ -63,7 +64,7 @@ function createQuestionEpic(action$, state$, { window }) {
|
|||||||
}
|
}
|
||||||
${
|
${
|
||||||
projectFormValues
|
projectFormValues
|
||||||
?.map(([key, val]) => `${key}: ${val}\n`)
|
?.map(([key, val]) => `${key}: ${transformEditorLink(val)}\n`)
|
||||||
?.join('') || filesToMarkdown(files)
|
?.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);
|
const statusInt = parseInt(status, 10);
|
||||||
return (statusInt >= 200 && statusInt < 400) || statusInt === 402;
|
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>'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user