mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
This commit is contained in:
parent
b533ab9298
commit
097bf8596e
2 changed files with 33 additions and 5 deletions
|
@ -70,6 +70,24 @@ test('Repository url parsing', () => {
|
|||
org: 'foo',
|
||||
protocol: 'ssh',
|
||||
});
|
||||
|
||||
const repo8 = RepositoryUtils.buildRepository('https://github.com/apache/sqoop/a/b');
|
||||
expect(repo8).toEqual({
|
||||
uri: 'github.com/apache_sqoop_a/b',
|
||||
url: 'https://github.com/apache/sqoop/a/b',
|
||||
name: 'b',
|
||||
org: 'apache_sqoop_a',
|
||||
protocol: 'https',
|
||||
});
|
||||
|
||||
const repo9 = RepositoryUtils.buildRepository('https://github.com/apache/sqoop/tree/master');
|
||||
expect(repo9).toEqual({
|
||||
uri: 'github.com/apache_sqoop_tree/master',
|
||||
url: 'https://github.com/apache/sqoop/tree/master',
|
||||
name: 'master',
|
||||
org: 'apache_sqoop_tree',
|
||||
protocol: 'https',
|
||||
});
|
||||
});
|
||||
|
||||
test('Repository url parsing with non standard segments', () => {
|
||||
|
@ -104,10 +122,10 @@ test('Repository url parsing with non standard segments', () => {
|
|||
test('Repository url parsing with port', () => {
|
||||
const repo1 = RepositoryUtils.buildRepository('ssh://mine@mydomain.com:27017/gitolite-admin');
|
||||
expect(repo1).toEqual({
|
||||
uri: 'mydomain.com:27017/mine/gitolite-admin',
|
||||
uri: 'mydomain.com:27017/_/gitolite-admin',
|
||||
url: 'ssh://mine@mydomain.com:27017/gitolite-admin',
|
||||
name: 'gitolite-admin',
|
||||
org: 'mine',
|
||||
org: '_',
|
||||
protocol: 'ssh',
|
||||
});
|
||||
|
||||
|
|
|
@ -15,13 +15,23 @@ import { parseLspUrl, toCanonicalUrl } from './uri_util';
|
|||
export class RepositoryUtils {
|
||||
// Generate a Repository instance by parsing repository remote url
|
||||
public static buildRepository(remoteUrl: string): Repository {
|
||||
const repo = GitUrlParse(remoteUrl);
|
||||
const repo = GitUrlParse(remoteUrl.trim());
|
||||
let host = repo.source ? repo.source : '';
|
||||
if (repo.port !== null) {
|
||||
host = host + ':' + repo.port;
|
||||
}
|
||||
const name = repo.name ? repo.name : '_';
|
||||
const org = repo.owner ? repo.owner.split('/').join('_') : '_';
|
||||
|
||||
// Remove the leading `/` and tailing `.git` if necessary.
|
||||
const pathname =
|
||||
repo.pathname && repo.git_suffix
|
||||
? repo.pathname.substr(1, repo.pathname.length - 5)
|
||||
: repo.pathname.substr(1);
|
||||
|
||||
// The pathname should look like `a/b/c` now.
|
||||
const segs = pathname.split('/').filter(s => s.length > 0);
|
||||
|
||||
const org = segs.length >= 2 ? segs.slice(0, segs.length - 1).join('_') : '_';
|
||||
const name = segs.length >= 1 ? segs[segs.length - 1] : '_';
|
||||
const uri: RepositoryUri = host ? `${host}/${org}/${name}` : repo.full_name;
|
||||
return {
|
||||
uri,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue