How to build BitBucket Cloud add-on in Rails → add-on descriptor
29 May 2016In this part of the series I'm going to publish BitBucket Connect descriptor. This is a file that describes how you want to integrate with BitBucket.
This article is Part 2 in a 7-Part Series.
- Part 1 - How to build BitBucket Cloud add-on in Rails → bootstraping rails
- Part 2 - This Article
- Part 3 - How to build BitBucket Cloud add-on in Rails → installation
- Part 4 - How to build BitBucket Cloud add-on in Rails → lifecycle
- Part 5 - How to build BitBucket Cloud add-on in Rails → user interface
- Part 6 - How to build BitBucket Cloud add-on in Rails → accessing BitBucket API from JavaScript
- Part 7 - How to build BitBucket Cloud add-on in Rails → accessing BitBucket API from the server
Edit config/routes.rb
to add a new route that will serve the descriptor.
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
get '/bitbucket/descriptor', to: 'bitbucket#descriptor'
end
Lets create a controller that will serve it with rails g controller bitbucket
class BitbucketController < ApplicationController
def descriptor
render :descriptor, locals: {
base_url: ApplicationController.renderer.defaults[:http_host]
}
end
end
In Gemfile
uncomment jbuilder
:
gem 'jbuilder', '~> 2.0'
No it's time to create the descriptor view! You place it in app/views/bitbucket/descriptor.json.erb
{
"authentication": {
"type": "jwt"
},
"baseUrl": "<%= base_url %>",
"contexts": [
"personal"
],
"description": "Blah blah blah",
"key": "stars<%= "." + Rails.env unless Rails.env.production? %>",
"name": "Stars for BitBucket",
"scopes": [
"account",
"repository"
],
"vendor": {
"name": "Pawel Niewiadomski",
"url": "https://pawelniewiadomski.com"
}
}
Now you can test it out using httpie:
$ http http://localhost:3000/bitbucket/descriptor
HTTP/1.1 200 OK
Cache-Control: max-age=0, private, must-revalidate
Content-Type: application/json; charset=utf-8
ETag: W/"f81cce01429e9936f12c0d77b1840d9c"
Transfer-Encoding: chunked
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Request-Id: ea71011a-76dd-4ba2-9305-2e43cc09f625
X-Runtime: 0.301832
X-XSS-Protection: 1; mode=block
{
"authentication": {
"type": "jwt"
},
"baseUrl": "example.org",
"contexts": [
"personal"
],
"description": "Blah blah blah",
"key": "stars.development",
"name": "Stars for BitBucket",
"scopes": [
"account",
"repository"
],
"vendor": {
"name": "Pawel Niewiadomski",
"url": "https://pawelniewiadomski.com"
}
}
Now I'm ready to install it in BitBucket, that's something I'm going to cover in next part.