Giter Site home page Giter Site logo

badging's Introduction

Build Status Badging

The best way to explain what is Badging is by example.

Very often, OSS developers keep track of different metrics via so called "badges" - status images at the top of a repo Readme. There are many services that provide repository status as a badge: Travis CI, Code Climate, and many more.

However, sometimes the metric you want to display on a badge is something that external services do not provide.

For example, let's imagine a situation when you are in the process of a migration from MiniTest to RSpec or vice versa. If your code base is large, it will take considerable amount of time and it's desirable to track progress of this migration.

One way to do it is to leverage the excellent shields.io. You just add something like ![RSpecing](https://img.shields.io/badge/RSpecing_Progress-83%-yellow.svg). It will be displayed as RSpecing.

There is a problem with this approach.

The progress changes over time, so each time you convert a Minitest file to RSpec, you need to remember to update the URL in the Readme. This is not too convenient.

Badging is a small service which solves this problem by keeping badge metadata (subject, status, color) in its own database and using this metadata to obtain and cache badge SVG.

# CREATE BADGE

$  export WRITE_TOKEN=wz94aoKA32QMdg6JeC
$ export BADGING_URL=https://<your badging host>
$ curl -H 'Content-Type: application/json' \
       -X POST \
       $BADGING_URL/badges \
       --data '{"token": "'$WRITE_TOKEN'", "badge": {"subject": "RSpecing Progress", "status": "83%", "identifier": "rspecing", "color": "yellow"}}'

# GET BADGE

$ export READ_TOKEN=wz94aoKA32QMdg6
$ curl $BADGING_URL/badges/rspecing.svg?token=$READ_TOKEN
<svg xmlns="http://www.w3.org/2000/svg" width="148" height="20"><linear...

# UPDATE BADGE

$ curl -H 'Content-Type: application/json' \
       --user user:$WRITE_TOKEN \
       -X PATCH \
       $BADGING_URL/badges/rspecing \
       --data '{"token": "'$WRITE_TOKEN'", "badge": {"subject": "RSpecing Progress", "status": "95%", "identifier": "rspecing", "color": "green"}}'

Going back to our example, here is how you could add the badge showing RSpec migration progress which updates automatically as code evolves:

  1. Deploy Badging to Heroku or any other suitable hosting.
  2. Configure randomly generated READ_TOKEN and WRITE_TOKEN.
  3. Create a badge via curl request or directly via DB insert.
  4. Add ![](<BADGING_URL>/badge/<identifier of created badge>.svg?token=<READ_TOKEN>) to your repo Readme.
  5. Create a script which would send a PATCH request to your Badging server each time a pull request is merged to your integration branch. You can call it from your CI server after each green build, for example. In our case, this script could just count the number of _rspec.rb and _test.rb files and figure out the progress based on that.

Prerequisites

  • Elixir
  • PostgreSQL

Running tests locally

mix deps.get
mix test

Starting your Badging app locally

mix deps.get
mix ecto.create && mix ecto.migrate
mix phx.server

Local read/write passwords are in config/dev.exs.

Deploying to Heroku

# Assuming you already created a new Heroku app and cd'ed to the project directory
heroku create --buildpack "https://github.com/HashNuke/heroku-buildpack-elixir.git"
heroku config:set POOL_SIZE=18 \
                  READ_TOKEN=<randomly generated string> \
                  WRITE_TOKEN=<any other random string> \
                  HOST=<your badging host> \
                  SECRET_KEY_BASE=`mix phoenix.gen.secret`

git push heroku master

CORS

By default, requests from all origins are allowed. If you want to whitelist the allowed domains, set CORS_ALLOWED_ORIGIN instance variable. For example:

heroku config:set CORS_ALLOWED_ORIGIN=https://github.com

badging's People

Contributors

dnnx avatar ertrzyiks avatar stefkin avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

badging's Issues

Enable CORS

Cross-domain support would allow using API from a browser client.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.