Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Code] improve repository index naming #33911

Merged
merged 1 commit into from
Mar 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions x-pack/plugins/code/common/repository_utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,16 @@ test('Repository url parsing with port', () => {
org: 'elastic',
});
});

test('Normalize repository index name', () => {
const indexName1 = RepositoryUtils.normalizeRepoUriToIndexName('github.com/elastic/Kibana');
const indexName2 = RepositoryUtils.normalizeRepoUriToIndexName('github.com/elastic/kibana');

expect(indexName1 === indexName2).toBeFalsy();
expect(indexName1).toEqual('github.com-elastic-kibana-e2b881a9');
expect(indexName2).toEqual('github.com-elastic-kibana-7bf00473');

const indexName3 = RepositoryUtils.normalizeRepoUriToIndexName('github.com/elastic-kibana/code');
const indexName4 = RepositoryUtils.normalizeRepoUriToIndexName('github.com/elastic/kibana-code');
expect(indexName3 === indexName4).toBeFalsy();
});
14 changes: 10 additions & 4 deletions x-pack/plugins/code/common/repository_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import crypto from 'crypto';
import GitUrlParse from 'git-url-parse';
import path from 'path';
import { Location } from 'vscode-languageserver';
Expand Down Expand Up @@ -66,10 +67,15 @@ export class RepositoryUtils {
}

public static normalizeRepoUriToIndexName(repoUri: RepositoryUri) {
return repoUri
.split('/')
.join('-')
.toLowerCase();
const hash = crypto
.createHash('md5')
.update(repoUri)
.digest('hex')
.substring(0, 8);
const segs: string[] = repoUri.split('/');
segs.push(hash);
// Elasticsearch index name is case insensitive
return segs.join('-').toLowerCase();
}

public static locationToUrl(loc: Location) {
Expand Down