-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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]: Pull Requests: Support Bitbucket Server #2598
[Bitbucket]: Pull Requests: Support Bitbucket Server #2598
Conversation
|
Thanks for your contribution to Shields! FYI I modified the name of the PR to put the service into brackets so the corresponding service tests would be run as part of the cheks |
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.
My gut feel is that we should strive to have a single service implementation that can support:
- public repos in BB
- private repos in BB (via self-hosted Shields instance)
- repos in BBS (via main Shields.io service for public, internet-accessible BBS instances and via self-hosted Shields instance for private/internal BBS instances)
Specifically, I'd like to know if we can have a single Bitbucket PR Service implementation (in bitbucket-pull-request.service.js
) that can support all of those options above.
It's a fairly common pattern we have in other services and I'd be surprised if we couldn't do the same here. The path
can be enhanced to support different options, the handle/fetch
functions can be updated accordingly to build and use the right url
, options
, etc, when required multiple schemas can be defined/used, etc.
I noticed that the API we're currently using for PRs on BB is relatively similar to the API that is being added here for BB server:
BB: /api/2.0/repositories/${user}/${repo}/pullrequests/
BBS: rest/api/1.0/projects/${project}/repos/${repo}/pull-requests
Given the usage of 1.0
I'm curious what the API version breakdown is between major BBS releases. For example does the 1.0 API spec still exist on BBS 5.x, 4.x, etc. as well as whether the 2.0 API spec exists on BBS (and starting with which major verison)
Yeah that makes sense. Even though Bitbucket Server "versions" its API, it looks like they never change the version (5.16.0, released a month ago, still lists As for unifying the service URL for both versions, I'm not familiar enough with the project to know how to add an optional parameter (thinking |
So the first thing we want to make sure we do here is ensure we don't break anyone using the existing PR badges for BB. Currently those folks are using the paths:
Therefore the route would need to support that pattern as well as the new type of pattern we want to add to support BBS. I'd think we'd want to have something like:
Obviously that regex starts to get a little tricky 😄 In similar instances with other services I've had to use static get route() {
return {
base: `bitbucket/${routePrefix}`,
format: '(?:(http|https)/(.+)/)?([^/]+)/([^/]+)',
capture: [ 'protocol', 'hostAndPath', 'user', 'repo'],
}
} Note in the base the With that kind of route we could update the async handle({ protocol, hostAndPath, user, repo }) {
let usingBitbucketServer = false
let url = `https://bitbucket.org/api/2.0/repositories/${user}/${repo}/pullrequests/`
if (hostAndPath) {
usingBitbucketServer = true
url = `${protocol}://${hostAndPath}/rest/api/1.0/projects/${user}/repos/${repo}/pull-requests`
}
...
} That's obviously a little raw and in need of some cleanup, but I think it conveys the idea well enough |
@calebcartwright Thanks for all the help. I finally had some time to circle back to this and was porting it from a legacy service I had created earlier in the year. I'll take a look at your suggestions tomorrow if I have some time. |
@calebcartwright I was able combine the new service with the existing one. I also followed your suggestions and used the object-style query strings, basic auth, and error code handlers. PTAL when you get a chance. (Tests failed because the service name in the PR title is no longer correct. I've fixed it but I don't have permissions to restart the CI builds that failed.) |
👍 thanks, will review shortly |
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 is looking great! I've added a couple final comments/requests inline below but I think this is nearly done
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.
Thanks again for this. Someone should come along shortly and merge this (note they may have some additional feedback/requested changes as well), but it LGTM.
The last thing I'll add is that you may want to consider adding some additional tests for the BBS paths (like the HTTP 40X response codes, etc.) similar to the tests for BB that validate those similar scenarios
@calebcartwright Thanks for all the help, I added extra tests for the other status codes. Is there an easy way to mock out the credentials so I can test the presence / absence of the basic auth header? It's the only test cases I think I'm missing. |
Great question! We do have a pattern that allows for stubbing the serverSecret values as part of the setup/teardown process of the test to cover those scenarios. One example is here in the Jira service |
Do you guys want this squashed? |
I think that's everything, although I need to read through #2626 to see if I have to migrate over any of the secrets we added. |
|
@paulmelnikow @calebcartwright Let me know if there's anything else that needs tweaked, I think this is ready for merging. |
Thanks @nlowe! giving this a final look over now |
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.
Thanks for all your work on this!
Add support for counting pull requests from a bitbucket server instance as requested in #1757. I didn't do build status since that can be handled by other badges.
Fixes #1757