Sha256: 4c2d684aa8aa7924f97d212c365eceb17458c20e51c8d8bdd7942e2b302a547d
Contents?: true
Size: 1.42 KB
Versions: 5
Compression:
Stored size: 1.42 KB
Contents
# -*- encoding : utf-8 -*- require 'rest_client' require 'pp' require 'json' module Lolcommits class Lolsrv < Plugin def initialize(runner) super options << 'server' end def run_postcapture return unless valid_configuration? fork { sync } end def configured? !configuration['enabled'].nil? && configuration['server'] end def sync existing = existing_lols return unless existing.nil? Dir[runner.config.loldir + '/*.{jpg,gif}'].each do |item| sha = File.basename(item, '.*') upload(item, sha) unless existing.include?(sha) || sha == 'tmp_snapshot' end end def existing_lols lols = JSON.parse(RestClient.get(configuration['server'] + '/lols')) lols.map { |lol| lol['sha'] } rescue => e log_error(e, "ERROR: existing lols could not be retrieved #{e.class} - #{e.message}") return nil end def upload(file, sha) RestClient.post(configuration['server'] + '/uplol', lol: File.new(file), url: runner.vcs_info.url + sha, repo: runner.vcs_info.repo, date: File.ctime(file), sha: sha) rescue => e log_error(e, "ERROR: Upload of lol #{sha} FAILED #{e.class} - #{e.message}") end def self.name 'lolsrv' end def self.runner_order :postcapture end end end
Version data entries
5 entries across 5 versions & 1 rubygems