Skip to content

Commit 2bf1b87

Browse files
committed
Implemented artifact link to git branches.
1 parent 145f832 commit 2bf1b87

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

src/HistoryDiffPageScript.js

+38-3
Original file line numberDiff line numberDiff line change
@@ -388,19 +388,21 @@ async function TryGetHTMLLinkNameAndUrlForArtifactLink(artifactLink)
388388
}
389389

390390
// TODO:
391-
// - Resolve project and repository ids for better display?
391+
// - Resolve project and repository ids for better display? I.e. in the history, show the project and repository names?
392392
// - Support all other artifact link types.
393393
// - Maybe call routeUrl() at the start of the initialization to trigger the REST request as early as possible?
394+
// - TFS code references? (Compare e.g. constructLinkToContentFromRouteId())
394395

395396
const [, artifactTool, artifactType, artifactId] = matches;
396397
if (artifactTool === 'Git') {
398+
// Example: vstfs:///Git/Commit/2d63f741-0ba0-4bc6-b730-896745fab2c0%2Fc0d1232d-66e9-4d5e-b5a0-50366bc67991%2F2054d8fcd16469d4398b2c73d9da828aaed98e41
397399
if (artifactType === 'Commit') {
398400
const details = artifactId.split('%2F');
399401
if (details.length !== 3) {
400402
return undefined;
401403
}
402404

403-
// Compare the 'VersionControl/Scripts/CommitArtifact.js' file in the ADO Server installation.
405+
// Compare 'VersionControl/Scripts/CommitArtifact.js' and 'wit-linked-work-dropdown-content\Util\Artifact.js' in the ADO Server installation.
404406
const [projectGuid, repositoryId, commitId] = details;
405407

406408
/*
@@ -414,14 +416,47 @@ async function TryGetHTMLLinkNameAndUrlForArtifactLink(artifactLink)
414416
],
415417
*/
416418
const url = await gLocationService.routeUrl(
417-
"ms.vss-code-web.commit-route",
419+
'ms.vss-code-web.commit-route',
418420
{
419421
project: projectGuid,
420422
'vc.GitRepositoryName': repositoryId,
421423
parameters: commitId
422424
});
423425
return [commitId, url];
424426
}
427+
// Example: vstfs:///Git/Ref/2d63f741-0ba0-4bc6-b730-896745fab2c0%2Fc0d1232d-66e9-4d5e-b5a0-50366bc67991%2FGBmain
428+
else if (artifactType === 'Ref') {
429+
const details = artifactId.split('%2F');
430+
if (details.length !== 3) {
431+
return undefined;
432+
}
433+
434+
// Compare 'wit-linked-work-dropdown-content\Util\Artifact.js' as well as
435+
// constructLinkToContentFromRouteId() in 'Search\Scenarios\Shared\Utils.js' in the ADO Server installation.
436+
// Git branches are prefixed with 'GB' (I guess it stands for 'Git Branch'?) (TFS branches are prefixed with 'T').
437+
const [projectGuid, repositoryId, branchNameWithGB] = details;
438+
if (branchNameWithGB.indexOf('GB') !== 0) {
439+
// TODO: Is 'Git/Ref' used only for branches, or also for other things?
440+
return undefined;
441+
}
442+
const branchName = branchNameWithGB.substring(2);
443+
444+
/*
445+
"routeTemplates": [
446+
"{project}/{team}/_git/{vc.GitRepositoryName}",
447+
"{project}/_git/{vc.GitRepositoryName}",
448+
"_git/{project}"
449+
],
450+
*/
451+
const url = await gLocationService.routeUrl(
452+
'ms.vss-code-web.files-route-git',
453+
{
454+
project: projectGuid,
455+
'vc.GitRepositoryName': repositoryId,
456+
version: branchNameWithGB
457+
});
458+
return [branchName, url];
459+
}
425460
}
426461

427462
// Unknown artifact link.

0 commit comments

Comments
 (0)