Sha256: fe44691b679769f1850aa49ef05ea62b0535f9bda2f74fea80da09df059e9f37

Contents?: true

Size: 1.62 KB

Versions: 1

Compression:

Stored size: 1.62 KB

Contents

require 'sinatra/base'
require 'puma'
require 'json'
require_relative '../../pairing_matrix'
require_relative '../config/config_reader'
require_relative '../cache/commit_cache'
require_relative '../commit_readers/local_commit_reader'
require_relative '../commit_readers/github_commit_reader'
require_relative '../commit_readers/gitlab_commit_reader'

module PairingMatrix
  class Server < Sinatra::Base
    set :bind, '0.0.0.0'
    set :server, :puma

    logging_file = File.new('app.log', 'a+')
    logging_file.sync = true
    before {
      env["rack.errors"] = logging_file
    }
    configure do
      enable :logging
      logging_file.sync = true
      use Rack::CommonLogger, logging_file
    end

    PairingMatrix.enable_caching = true
    config_reader = PairingMatrix::ConfigReader.new('pairing_matrix.yml')
    config = config_reader.config

    local_commit_reader = PairingMatrix::LocalCommitReader.new(config.local)
    github_commit_reader = PairingMatrix::GithubCommitReader.new(config.github)
    gitlab_commit_reader = PairingMatrix::GitlabCommitReader.new(config.gitlab)

    get '/data/:days' do
      PairingMatrix.enable_caching = params[:cache_enabled] != 'false'

      local_data = local_commit_reader.authors_with_commits(params['days'].to_i)
      github_data = github_commit_reader.authors_with_commits(params['days'].to_i)
      gitlab_data = gitlab_commit_reader.authors_with_commits(params['days'].to_i)

      (local_data + github_data + gitlab_data).to_json
    end

    get '/matrix' do
      File.read(File.join(File.dirname(__FILE__), 'public/index.html'))
    end

    get '/' do
      redirect '/matrix'
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pairing_matrix-3.0.0 lib/pairing_matrix/server/server.rb