Sha256: 05caefc6e1659de0072a5e3b2fa82b1c2003c4b8b3855ee76d22ef44661c8422

Contents?: true

Size: 1.48 KB

Versions: 6

Compression:

Stored size: 1.48 KB

Contents

module Git
  module Semaphore
    class API
      class Enrich

        def self.projects auth_token
          API.projects(auth_token).tap do |results|
            results.each do |project|
              # full repository name on github.com: 'pvdb/git-semaphore'
              project['full_name']  = [project['owner'], project['name']].join('/')
              # https://semaphoreci.com/pvdb/git-semaphore -> https://github.com/pvdb/git-semaphore
              project['github_url'] = project['html_url'].sub(/semaphoreci\.com/, 'github.com')
            end
          end
        end

        def self.history project_hash_id, branch_id, auth_token
          API.history(project_hash_id, branch_id, auth_token).tap do |results|
            results['builds'].each do |build|
              # build['result'] = "passed", "failed", "stopped" or "pending"
              next unless started_at  = build['started_at']
              next unless finished_at = build['finished_at']
              started_at  = DateTime.parse(started_at).to_time
              finished_at = DateTime.parse(finished_at).to_time
              build['date'] = {
                :started_at  =>  started_at.to_date,
                :finished_at => finished_at.to_date,
              }
              build['duration'] = {
                :seconds => (finished_at - started_at).to_i,
                :minutes => "%0.2f" % ((finished_at - started_at) / 60),
              }
            end
          end
        end

      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
git-semaphore-2.1.0 lib/git/semaphore/api_enrich.rb
git-semaphore-2.0.1 lib/git/semaphore/api_enrich.rb
git-semaphore-2.0.0 lib/git/semaphore/api_enrich.rb
git-semaphore-1.2.0 lib/git/semaphore/api_enrich.rb
git-semaphore-1.1.0 lib/git/semaphore/api_enrich.rb
git-semaphore-1.0.0 lib/git/semaphore/api_enrich.rb