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
Bitbucket enterprise support #246
Changes from 9 commits
ac86bfa
87100eb
c79589a
d26c71d
f6e2089
cb54756
412c495
3203cf1
2b52fc2
8593b65
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,101 @@ public sealed class GetSourceLinkUrl : GetSourceLinkUrlGitTask | |
protected override string HostsItemGroupName => "SourceLinkBitbucketGitHost"; | ||
protected override string ProviderDisplayName => "Bitbucket.Git"; | ||
|
||
private const string BitbucketCloudHostingUrl = "bitbucket.org"; | ||
private const string IsEnterpriseEditionMetadataName = "EnterpriseEdition"; | ||
private const string VersionMetadataName = "Version"; | ||
private const string VersionWithNewUrlFormat = "4.7"; | ||
|
||
protected override bool SupportsImplicitHost => false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If you keep this set to |
||
|
||
protected override string BuildSourceLinkUrl(Uri contentUri, Uri gitUri, string relativeUrl, string revisionId, ITaskItem hostItem) | ||
=> UriUtilities.Combine(UriUtilities.Combine(contentUri.ToString(), relativeUrl), "raw/" + revisionId + "/*"); | ||
{ | ||
var isEnterpriseEditionFlagAvailable = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This can be simplified as return boo.TryParse(..., out var isEnterpriseEditionValue) && isEnterpriseEditionValue ?
BuildSourceLinkUrlForEnterpriseEdition(contentUri, relativeUrl, revisionId, hostItem) :
BuildSourceLinkUrlForCloudEdition(contentUri, relativeUrl, revisionId); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tmat I modified pull request according to your suggestions.
Bottom line, now it will be not necessary to put |
||
bool.TryParse(hostItem.GetMetadata(IsEnterpriseEditionMetadataName), out var isEnterpriseEdition); | ||
|
||
if (isEnterpriseEditionFlagAvailable) | ||
{ | ||
if (isEnterpriseEdition) | ||
{ | ||
return BuildSourceLinkUrlForEnterpriseEdition(contentUri, relativeUrl, revisionId, hostItem); | ||
} | ||
else | ||
{ | ||
return BuildSourceLinkUrlForCloudEdition(contentUri, relativeUrl, revisionId); | ||
} | ||
} | ||
|
||
if (!BitbucketCloudHostingUrl.Equals(gitUri.GetHost(), StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
return BuildSourceLinkUrlForEnterpriseEdition(contentUri, relativeUrl, revisionId, hostItem); | ||
} | ||
else | ||
{ | ||
return BuildSourceLinkUrlForCloudEdition(contentUri, relativeUrl, revisionId); | ||
} | ||
|
||
} | ||
|
||
private string BuildSourceLinkUrlForEnterpriseEdition(Uri contentUri, string relativeUrl, string revisionId, | ||
ITaskItem hostItem) | ||
{ | ||
var bitbucketEnterpriseVersion = GetBitbucketEnterpriseVersion(hostItem); | ||
|
||
var splits = relativeUrl.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries); | ||
var isSshRepoUri = !(splits.Length == 3 && splits[0] == "scm"); | ||
var projectName = isSshRepoUri ? splits[0] : splits[1]; | ||
var repositoryName = isSshRepoUri ? splits[1] : splits[2]; | ||
|
||
var relativeUrlForBitbucketEnterprise = | ||
GetRelativeUrlForBitbucketEnterprise(projectName, repositoryName, revisionId, | ||
bitbucketEnterpriseVersion); | ||
|
||
var result = UriUtilities.Combine(contentUri.ToString(), relativeUrlForBitbucketEnterprise); | ||
|
||
return result; | ||
} | ||
|
||
private Version GetBitbucketEnterpriseVersion(ITaskItem hostItem) | ||
{ | ||
var bitbucketEnterpriseVersionAsString = hostItem.GetMetadata(VersionMetadataName); | ||
Version bitbucketEnterpriseVersion; | ||
if (!string.IsNullOrEmpty(bitbucketEnterpriseVersionAsString)) | ||
{ | ||
if (!Version.TryParse(bitbucketEnterpriseVersionAsString, out bitbucketEnterpriseVersion)) | ||
{ | ||
Log.LogError(CommonResources.ItemOfItemGroupMustSpecifyMetadata, hostItem.ItemSpec, | ||
HostsItemGroupName, VersionMetadataName); | ||
|
||
return null; | ||
} | ||
} | ||
else | ||
{ | ||
bitbucketEnterpriseVersion = Version.Parse(VersionWithNewUrlFormat); | ||
} | ||
|
||
return bitbucketEnterpriseVersion; | ||
} | ||
|
||
private static string BuildSourceLinkUrlForCloudEdition(Uri contentUri, string relativeUrl, string revisionId) | ||
{ | ||
return UriUtilities.Combine(UriUtilities.Combine(contentUri.ToString(), relativeUrl), | ||
"raw/" + revisionId + "/*"); | ||
} | ||
|
||
private static string GetRelativeUrlForBitbucketEnterprise(string projectName, string repositoryName, string commitId, Version bitbucketVersion) | ||
{ | ||
string relativeUrl; | ||
if (bitbucketVersion >= Version.Parse(VersionWithNewUrlFormat)) | ||
{ | ||
relativeUrl = $"projects/{projectName}/repos/{repositoryName}/raw/*?at={commitId}"; | ||
} | ||
else | ||
{ | ||
relativeUrl = $"projects/{projectName}/repos/{repositoryName}/browse/*?at={commitId}&raw"; | ||
} | ||
|
||
return relativeUrl; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo:
Edtition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think markdown will format these as you intended - on separate lines.
In reply to: 283563555 [](ancestors = 283563555)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's include the EnterpriseEdition and Version parameters to the example below.
In reply to: 283563725 [](ancestors = 283563725,283563555)