You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-07-16 00:14:34 +02:00
Mobile: Plugin support: Simplify reporting plugin issues (#10319)
This commit is contained in:
@ -0,0 +1,17 @@
|
||||
import getPluginIssueReportUrl from './getPluginIssueReportUrl';
|
||||
|
||||
describe('getPluginIssueReportUrl', () => {
|
||||
test.each([
|
||||
[{ repository_url: 'http://github.com/laurent22/joplin' }, 'https://github.com/laurent22/joplin/issues'],
|
||||
[{ repository_url: 'https://www.github.com/laurent22/joplin' }, 'https://github.com/laurent22/joplin/issues'],
|
||||
[{ repository_url: 'https://www.github.com/laurent22/joplin.git' }, 'https://github.com/laurent22/joplin/issues'],
|
||||
[{ homepage_url: 'https://www.github.com/laurent22/joplin' }, 'https://github.com/laurent22/joplin/issues'],
|
||||
|
||||
[{ homepage_url: 'https://gitlab.com/laurent22/joplin' }, 'https://gitlab.com/laurent22/joplin/-/issues'],
|
||||
[{ homepage_url: 'https://www.gitlab.com/laurent22/joplin' }, 'https://gitlab.com/laurent22/joplin/-/issues'],
|
||||
|
||||
[{ homepage_url: 'https://example.com/laurent22/joplin' }, null],
|
||||
])('should return the issue URL (case %#)', async (manifest, expectedUrl) => {
|
||||
expect(getPluginIssueReportUrl(manifest)).toBe(expectedUrl);
|
||||
});
|
||||
});
|
@ -0,0 +1,31 @@
|
||||
import { PluginManifest } from './types';
|
||||
|
||||
type ManifestSlice = Pick<PluginManifest, 'repository_url'|'homepage_url'>;
|
||||
const getPluginIssueReportUrl = (pluginManifest: ManifestSlice): string|null => {
|
||||
const githubUrlExp = /^https?:\/\/(?:www\.)?github\.com\/([^/]+)\/([^/?]+)/;
|
||||
const gitlabUrlExp = /^https?:\/\/(?:www\.)?gitlab\.com\/([^/]+)\/([^/]+)/;
|
||||
|
||||
let githubUrlMatch = null;
|
||||
let gitlabUrlMatch = null;
|
||||
const urls = [pluginManifest.repository_url, pluginManifest.homepage_url].filter(url => !!url);
|
||||
|
||||
for (const url of urls) {
|
||||
githubUrlMatch ??= githubUrlExp.exec(url);
|
||||
gitlabUrlMatch ??= gitlabUrlExp.exec(url);
|
||||
}
|
||||
|
||||
if (githubUrlMatch) {
|
||||
const organization = githubUrlMatch[1];
|
||||
// Some plugins include a trailing .git after the repository name
|
||||
const project = githubUrlMatch[2].replace(/\.git$/, '');
|
||||
return `https://github.com/${organization}/${project}/issues`;
|
||||
} else if (gitlabUrlMatch) {
|
||||
const organization = gitlabUrlMatch[1];
|
||||
const project = gitlabUrlMatch[2];
|
||||
return `https://gitlab.com/${organization}/${project}/-/issues`;
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
export default getPluginIssueReportUrl;
|
Reference in New Issue
Block a user