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 7 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,88 @@ public sealed class GetSourceLinkUrl : GetSourceLinkUrlGitTask | |
protected override string HostsItemGroupName => "SourceLinkBitbucketGitHost"; | ||
protected override string ProviderDisplayName => "Bitbucket.Git"; | ||
|
||
protected override string BuildSourceLinkUrl(Uri contentUri, Uri gitUri, string relativeUrl, string revisionId, ITaskItem hostItem) | ||
=> UriUtilities.Combine(UriUtilities.Combine(contentUri.ToString(), relativeUrl), "raw/" + revisionId + "/*"); | ||
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) | ||
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.
Style: keep the parameter on the previous line. We either indent all parameters or none. 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. Done |
||
{ | ||
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 && isEnterpriseEdition) | ||
{ | ||
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.
This should be default. Customer who uses repository hosted on bitbucket.org shouldn't need to specify anything in their project file.
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.
When using a server hosted in different domain we should default to enterprise edition and the latest version with the option to specify an older version.
In reply to: 280532565 [](ancestors = 280532565)
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.
Done.
Now for bitbucket.org cloud hosting there is no need to provide SourceLinkBitbucketGitHost configuration in csproj.
When the domain is different than bitbucket.org it defaults to enterprise edition and the latest version.