Skip to content

Commit

Permalink
Update GitHub regex to match http(s):// URLs in addition to SSH URLs (m…
Browse files Browse the repository at this point in the history
  • Loading branch information
smurching authored and aarondav committed Aug 3, 2018
1 parent dccc0d4 commit 6c30192
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion mlflow/server/js/src/components/RunView.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class RunView extends Component {
{run.source_version ?
<div className="run-info">
<span className="metadata-header">Git Commit: </span>
<span className="metadata-info">{run.source_version.substring(0, 20)}</span>
<span className="metadata-info">{Utils.renderVersion(run)}</span>
</div>
: null
}
Expand Down
10 changes: 6 additions & 4 deletions mlflow/server/js/src/utils/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,17 @@ class Utils {
return path.replace(/(.*[^/])\.[^/.]+$/, "$1")
}

static getGitHubRegex() {
return /[@/]github.com[:/]([^/.]+)\/([^/.]+)/;
}

static renderSource(run) {
if (run.source_type === "PROJECT") {
let res = Utils.dropExtension(Utils.baseName(run.source_name));
if (run.entry_point && run.entry_point !== "main") {
res += ":" + run.entry_point;
}
const GITHUB_RE = /[:@]github.com[:/]([^/.]+)\/([^/.]+)/;
const match = run.source_name.match(GITHUB_RE);
const match = run.source_name.match(Utils.getGitHubRegex());
if (match) {
const url = "https://github.com/" + match[1] + "/" + match[2];
res = <a href={url}>{res}</a>;
Expand All @@ -112,8 +115,7 @@ class Utils {
if (run.source_version) {
const shortVersion = run.source_version.substring(0, 6);
if (run.source_type === "PROJECT") {
const GITHUB_RE = /[:@]github.com[:/]([^/.]+)\/([^/.]+)/;
const match = run.source_name.match(GITHUB_RE);
const match = run.source_name.match(Utils.getGitHubRegex());
if (match) {
const url = "https://github.com/" + match[1] + "/" + match[2] + "/tree/" + run.source_version;
return <a href={url}>{shortVersion}</a>;
Expand Down
18 changes: 18 additions & 0 deletions mlflow/server/js/src/utils/Utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,21 @@ test("dropExtension", () => {
expect(Utils.dropExtension("/.foo")).toEqual("/.foo");
expect(Utils.dropExtension(".foo/.bar/.xyz")).toEqual(".foo/.bar/.xyz");
});

test("getGitHubRegex", () => {
const gitHubRegex = Utils.getGitHubRegex();
const urlAndExpected = [
["http://github.com/mlflow/mlflow-apps", ["/github.com/mlflow/mlflow-apps", "mlflow", "mlflow-apps"]],
["https://github.com/mlflow/mlflow-apps", ["/github.com/mlflow/mlflow-apps", "mlflow", "mlflow-apps"]],
["http://github.com/mlflow/mlflow-apps.git", ["/github.com/mlflow/mlflow-apps", "mlflow", "mlflow-apps"]],
["https://github.com/mlflow/mlflow-apps.git", ["/github.com/mlflow/mlflow-apps", "mlflow", "mlflow-apps"]],
["git@github.com:mlflow/mlflow-apps.git", ["/github.com/mlflow/mlflow-apps", "mlflow", "mlflow-apps"]],
["https://some-other-site.com?q=github.com/mlflow/mlflow-apps.git", null],
["ssh@some-server:mlflow/mlflow-apps.git", null],
]
urlAndExpected.forEach(lst => {
const url = lst[0];
const match = url.match(gitHubRegex);
expect(match == lst[1]);
})
})

0 comments on commit 6c30192

Please sign in to comment.