-
Notifications
You must be signed in to change notification settings - Fork 252
Bitbucket Server Root Context #113
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
Conversation
Please see the unit tests for more details. Basically, take the context parts before 'scm' and add them to the new URL before the other parts. Instead of taking fixed indexes for the path elements, base everything off the index of the found 'scm' path element.
The idea for these type of things (which could exist in gitlab or github) is to use the git config to set this ala #92 - so not a bitbucket specific issue. Did you try this yet? We could merge the fix for bitbucket only although I think using the config here makes more sense. |
Good points, but this is a different use case. For the GitLab case, you're trying to change a remote URL to a completely different URL, e.g. (from the unit tests):
This means that the remote URL does not have all of the information required for creating the browser URL, so you need to source it in from somewhere else ( In the Bitbucket Server case that I added now, all of the information is in the remote URL, it just wasn't used before:
Before my change, the In this case, no external information needs to be sourced in from I was able to remove one further Does this make sense? |
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.
Assuming this is how Bitbucket servers handles URLs (which I have no experience in, so wouldn't know), this PR accomplishes the task given without affecting current functionality. Well commented and tested.
test/git-open.bats
Outdated
@@ -269,6 +269,35 @@ setup() { | |||
|
|||
} | |||
|
|||
|
|||
@test "bitbucket server with different root context" { |
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: Please add colon here (bitbucket:
) so the CI output looks nice. Same on the following unit test.
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.
Ah yes, thanks for noticing this. I also saw that some of the basic Bitbucket Server tests were duplicated in an earlier commit - I'll fix this at the same time as the naming...
Also removed some duplicated tests that were introduced during a previous merge.
I've fixed the naming of the test cases, and I've removed some duplicated tests for Bitbucket Server functionality as well. It looks like they were introduced as part of a previous commit/merge when the test suite was refactored. |
test/git-open.bats
Outdated
assert_output "https://mybb.domain.com/root/context/projects/~first.last/repos/rrr/browse?at=develop" || | ||
assert_output "https://mybb.domain.com/root/context/projects/~first.last/repos/rrr/browse?at=refs%2Fheads%2Fdevelop" || | ||
assert_output "https://mybb.domain.com/root/context/projects/~first.last/repos/rrr/browse?at=refs/heads/develop" | ||
|
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.
#nitpick - remove the space?
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.
Saw this too, but it's indentation for the chained ||
.
We could possibly reduce duplicate strings by making use of assert_output --regexp
, although it would be less readable. Like so:
assert_output --regexp "https://mybb.domain.com/root/context/projects/~first.last/repos/rrr/browse\?at=(refs(/|%2F)heads(/|%2F))?develop"
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've simply copied this part from the other existing unit tests, including the ||
chaining and the indentation.
Not a huge fan of the regexp check, due to readability...
I see, so you want to change the url before the code here hits for bitbucket: Lines 130 to 134 in 8caa9ad
|
Sorry to keep coming back to this - but is anything preventing this from getting merged? Let me know and I'll look into making any additional changes if required... |
👍 |
Thanks for merging! |
Bitbucket Server Root Context
I've finally found the time to take a look at the optional root context for self-hosted instances of Bitbucket Server. In our example, the Bitbucket server instance is not located at
https://bitbucket.example.com/scm/ppp/test-repo.git
but has an added
/git/
before thescm
part:https://bitbucket.example.com/git/scm/ppp/test-repo.git
We had discussed this a while back in #83 (comment), but haven't had an implementation that took anything before the
scm
part into account.I've refactored the Bitbucket logic to match the logic that was added for TFS, where the check for the
scm
part is now down from the back of the URL (the third to last item in the URL), instead of checking from the front.No changes in the existing functionality, it just added support for self-hosted instances of Bitbucket Server that use an additional root context in the server deployment. Any optional path elements found before the
scm
match are now added to the final URL as part of the path transformation for Bitbucket Server. Please see the new unit tests for additional examples.