Skip to content

Instantly share code, notes, and snippets.

@dgehrett
Last active August 18, 2016 14:10
Show Gist options
  • Save dgehrett/6829168 to your computer and use it in GitHub Desktop.
Save dgehrett/6829168 to your computer and use it in GitHub Desktop.
Source code for a Code Climate Dashing widget for use with the Shopify Dashing framework (https://github.com/Shopify/dashing). It shows a single repository's GPA. See more widgets we've made at https://github.com/Homefinder/dashing-widgets

##Preview

Simple Dashing widget (and associated job) to display the Code Climate GPA for a github repository.

Created at Homefinder.com

Check out other widgets we've made at https://github.com/Homefinder/dashing-widgets

##Usage To use this widget, copy codeclimate.html, codeclimate.coffee, and codeclimate.scss into the /widgets/codeclimate directory. Put the code_climate.rb file in your /jobs folder. Copy codeclimate.png into the /assets/images directory.

Please refer to codeclimate.erb for an example of how to include this widget in your dashboard.

##Settings Set your Code Climate API token in code_climate.rb. You can get the repo id from the feed URL in code climate (https://codeclimate.com/repos/<repo_id>/feed)

Optionally, you can install this running dashing install 6829168

require 'net/http'
require 'json'
SCHEDULER.every '1h', :first_in => 0 do |job|
repo_id = "YOUR REPO ID HERE"
api_token = "YOUR API_TOKEN HERE"
uri = URI.parse("https://codeclimate.com/api/repos/#{repo_id}")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
request.set_form_data({api_token: api_token})
response = http.request(request)
stats = JSON.parse(response.body)
current_gpa = stats['last_snapshot']['gpa'].to_f
last_gpa = stats['previous_snapshot']['gpa'].to_f
send_event("code-climate", {current: current_gpa, last: last_gpa})
end
class Dashing.Codeclimate extends Dashing.Widget
@accessor 'arrow', ->
if @get('last')
if parseFloat(@get('current')) > parseFloat(@get('last')) then 'icon-arrow-up' else 'icon-arrow-down'
onData: (data) ->
if data.status
$(@get('node')).addClass("status-#{data.status}")
<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
<div data-id="code-climate" data-view="Codeclimate" data-title="Code Climate GPA"></div>
</li>
<h1 class="title" data-bind="title"></h1>
<h2 class="value" data-bind="current | shortenedNumber | prepend prefix"></h2>
<p class="change-rate">
<i data-bind-class="arrow"></i>previously <span data-bind="last"></span>
</p>
<p class="more-info" data-bind="moreinfo | raw"></p>
<p class="updated-at" data-bind="updatedAtMessage"></p>
// ----------------------------------------------------------------------------
// Sass declarations
// ----------------------------------------------------------------------------
$background-color: #667FAD;
$value-color: #fff;
$title-color: rgba(255, 255, 255, 0.7);;
$moreinfo-color: rgba(255, 255, 255, 0.7);;
// ----------------------------------------------------------------------------
// Widget-codeclimate styles
// ----------------------------------------------------------------------------
.widget-codeclimate {
background-color: $background-color;
background-image: url("/assets/codeclimate.png");
background-repeat: no-repeat;
background-position: center center;
.title {
color: $title-color;
}
.value {
margin-top: 50px;
color: $value-color;
}
.change-rate {
margin-top: 50px;
font-weight: 300;
font-size: 20px;
color: $value-color;
}
.more-info {
color: $moreinfo-color;
}
.updated-at {
color: rgba(0, 0, 0, 0.3);
}
}
The MIT License (MIT)
Copyright (c) 2013 HomeFinder.com
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@pzula
Copy link

pzula commented May 30, 2014

Where does one get a CodeClimate API key anymore? Doesn't seem to be around.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment