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 support for Bitbucket Enterprise #128

Closed
tmat opened this issue Jul 18, 2018 · 12 comments
Closed

Add support for Bitbucket Enterprise #128

tmat opened this issue Jul 18, 2018 · 12 comments
Milestone

Comments

@tmat
Copy link
Member

tmat commented Jul 18, 2018

Package Microsoft.SourceLink.Bitbucket.Enterprise.

In order to support on-prem Bitbucket we need a documentation on URL formats it uses for cloning repositories and accessing raw files. Are these the only URL formats? https://github.com/ctaggart/SourceLink/blob/master/SourceLink.Create.CommandLine/BitBucketServerUrlConverter.cs

Is there a difference between Server and Data Center?

@danjagnow
Copy link

I make no claims that this is an authoritative answer, but I do have access to a Bitbucket Server installation. From a Bitbucket server, the URL looks like this when I go to clone a repository:

https://username@bitbucket.mycompany.com/scm/projectname/reponame.git

Bitbucket has a Learn more about cloning repositories help link that takes you to the Atlassian help for git clone. If you scroll down to the Git URLs heading, it lists the following Git URL protocols:

  • ssh://[user@]host.xz[:port]/path/to/repo.git/
  • git://host.xz[:port]/path/to/repo.git/
  • http[s]://host.xz[:port]/path/to/repo.git/

Specifying the base URL for Bitbucket Server has a little information about the HTTP(S) protocol. Enabling SSH access to Git repositories in Bitbucket Server contains information about setting the SSH base URL. I didn't see anything immediately obvious for the Git protocol.

I'm not aware of any URL format differences between Server and Data Center, but I don't have any experience with Bitbucket Data Center.

@Clanrat
Copy link

Clanrat commented Aug 8, 2018

Depending on the BitBucket server version the url for the raw file will look different.

For bitbucket 4.7 and later the following format is supported
http://yourserver.com/projects/{projectKey}/repos/{repositoryKey}/raw/{pathToFile}.extension?at={commitHash}

BitBucket server versions before 4.7 has the following format
http://host/projects/{project}/repos/{repo}/browse/path/to/file.ext?raw (not sure about where the commit hash is placed)

4.7 release notes
BSERV-4036

We are running bit bucket server 4.14 and running a modified version of the Microsoft.SourceLink.Bitbucket.Git package using the url conversion in the file linked without any issues.

@tmat tmat added this to the 1.0.0 milestone Aug 14, 2018
@quasarea
Copy link

In our case it is;
Atlassian Bitbucket v4.5.2 and Atlassian Bitbucket v4.6.1:
https://stash1.company.com/projects/TEAM/repos/component/browse/Jenkinsfile?at=59e28fda4986b1cb2a265893c359490330cac810&raw

@quasarea
Copy link

we overcome this issue by updating BuildSourceLinkUrl method in GetSOurceLinkUrl.cs:

var splits = relativeUrl.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
if (splits.Length != 3)
    throw new Exception($"Expected three parts (separated by '/') in relativeUrl, but got: {relativeUrl}");

splits[0] = "projects";
splits[1] = splits[1].ToUpper() + "/repos";
splits[2] = splits[2] + $"/browse/*?at={revisionId}&raw";

relativeUrl = string.Join("/", splits);

var result = UriUtilities.Combine(contentUri.ToString(), relativeUrl);
return result;

but then I found ctaggart/SourceLink#361 pointing that SourceLinkUrl can be used to customised url structure

@Culan
Copy link

Culan commented Oct 27, 2018

But is it possible to use SourceLinkUrl with the dotnet / sourcelink?

I’m in the situation that i can’t use ctaggart / sourcelink because our build server is using ssh to our on prem bitbucket server and dotnet / sourcelink bitbucket package generates wrong URL ( for cloud bitbucket ) and SourceLinkUrl parameter in the csproj doesn’t seem to have any effect.

@adam-sajdak
Copy link
Contributor

I was doing some quick research about this entire issue of different urls for Bitbucket Cloud vs Enterprise in specific versions. Right now we have at least three different scenarios:

  • Bitbucket Cloud
  • Bitbucket Enterprise version prior to 4.7
  • Bitbucket Enterprise version 4.7 and above

Implementing BuildSourceLinkUrl method for individual scenario is quite simple.
I would assume that we would like to have just one Microsoft.SourceLink.Bitbucket.Git package that works for all above scenarios? Please correct me if I am wrong.
Then the way to do it would be similar to TFS problem with VirtualDirectory, right? In GetSourceLinkUrl class we simply could set:
protected override bool SupportsImplicitHost => false;
Then in csproj add such config:
<ItemGroup> <SourceLinkBitbucketGitHost Include="bitbucket.org" IsEnterprise="true/false" Version=4.7""/> </ItemGroup>

And then use these settings in BuildSourceLinkUrl method the same way Tfs is using VirtualDirectory.

The problem is, as soon as I put
protected override bool SupportsImplicitHost => false;
and I rebuild sourcelink project and try to use Microsoft.SourceLink.Bitbucket.Git package created by me then sourcelink stops to work and when I am trying to use it the warning is displayed:
Source control information is not available - the generated source link is empty.

I would like to contribute to sourcelink project but I am kind of stuck right now.

@tmat
Copy link
Member Author

tmat commented Feb 5, 2019

@adam-sajdak Thanks for looking into this. Could you send your changes in a PR?

@adam-sajdak
Copy link
Contributor

@tmat I finally got time to wrap this up. Here is the pull request:
#246
Actually everything works fine right now and it seems that this package supports both Cloud and Enterprise edition in different versions. Please have a look at it.

@Lonli-Lokli
Copy link

@adam-sajdak I think you should sign CLA in pull request first?

I am waiting for this PR to be merged, thanks for it!

@mitulpatel83
Copy link

Please expedite this PR and the subsequent build. It's exactly what we desperately need.

@kysel
Copy link

kysel commented Feb 27, 2019

I think that It is now waiting for @adam-sajdak to sign CLA. Hope he'll sign it soon.

@tmat
Copy link
Member Author

tmat commented Jun 22, 2019

Implemented by #246

@tmat tmat closed this as completed Jun 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants