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

Add custom domain git (change git regex) #7933

Merged
merged 9 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 30 additions & 0 deletions mlflow/server/js/src/common/utils/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,22 @@ class Utils {
return /[@/]bitbucket.org[:/]([^/.]+)\/([^/#]+)#?(.*)/;
}

/**
* Regular expression for URLs containing the string 'git'.
* It can be a custom git domain (e.g. https://git.custom.in/repo/dir#file/dir).
* Excluding the first overall match, there are three groups:
* git url, repo directory, and file directory.
* (e.g. group1: https://custom.git.domain, group2: repo/directory, group3: project/directory)
*/
static getGitRegex() {
return /(.*?[@/][^?]*git.*?)[:/]([^#]+)(?:#(.*))?/;
}

static getGitRepoUrl(sourceName) {
const gitHubMatch = sourceName.match(Utils.getGitHubRegex());
const gitLabMatch = sourceName.match(Utils.getGitLabRegex());
const bitbucketMatch = sourceName.match(Utils.getBitbucketRegex());
const gitMatch = sourceName.match(Utils.getGitRegex());
let url = null;
if (gitHubMatch || gitLabMatch) {
const baseUrl = gitHubMatch ? 'https://github.com/' : 'https://gitlab.com/';
Expand All @@ -266,6 +278,12 @@ class Utils {
if (bitbucketMatch[3]) {
url = url + '/src/master/' + bitbucketMatch[3];
}
} else if (gitMatch) {
const [, baseUrl, repoDir, fileDir] = gitMatch;
url = baseUrl.replace(/git@/, 'https://') + '/' + repoDir.replace(/.git/, '');
if (fileDir) {
url = url + '/tree/master/' + fileDir;
}
}
return url;
}
Expand All @@ -274,6 +292,7 @@ class Utils {
const gitHubMatch = sourceName.match(Utils.getGitHubRegex());
const gitLabMatch = sourceName.match(Utils.getGitLabRegex());
const bitbucketMatch = sourceName.match(Utils.getBitbucketRegex());
const gitMatch = sourceName.match(Utils.getGitRegex());
let url = null;
if (gitHubMatch || gitLabMatch) {
const baseUrl = gitHubMatch ? 'https://github.com/' : 'https://gitlab.com/';
Expand All @@ -298,6 +317,17 @@ class Utils {
sourceVersion +
'/' +
bitbucketMatch[3];
} else if (gitMatch) {
// eslint-disable-next-line no-unused-vars
const [_fullUrl, baseUrl, repoDir, fileDir] = gitMatch;
harupy marked this conversation as resolved.
Show resolved Hide resolved
url =
baseUrl.replace(/git@/, 'https://') +
'/' +
repoDir.replace(/.git/, '') +
'/tree/' +
sourceVersion +
'/' +
fileDir;
}
return url;
}
Expand Down
24 changes: 24 additions & 0 deletions mlflow/server/js/src/common/utils/Utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,30 @@ test('getGitHubRegex', () => {
});
});

test('getRegex', () => {
const gitRegex = Utils.getGitRegex();
const urlAndExpected = [
[
'https://custom.git.domain/repo/directory#project/directory',
['https://custom.git.domain', 'repo/directory', 'project/directory'],
],
[
'git@git.custom.in/repo/directory#project/directory',
['git@git.custom.in', 'repo/directory', 'project/directory'],
],
['https://some-other-site.com?q=github.com/mlflow/mlflow-apps.git', [undefined]],
['ssh@some-server:mlflow/mlflow-apps.git', [undefined]],
];
urlAndExpected.forEach((lst) => {
const url = lst[0];
const match = url.match(gitRegex);
if (match) {
match[2] = match[2].replace(/.git/, '');
}
expect([].concat(match?.slice(1))).toEqual(lst[1]);
});
});

test('getMetricPlotStateFromUrl', () => {
const url0 =
'?runs=["runUuid1","runUuid2"]&plot_metric_keys=[]' +
Expand Down