Sha256: e8dfe93c3b8f480cb40793a2fe74e56cb24234eae0c7d6c4c3a801f2c5613bb1

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

require 'octokit'
require 'eldritch'
require_relative './commit_cache'
require_relative './commit_reader'

Octokit.auto_paginate = true

module PairingMatrix
  class GithubCommitReader < CommitReader
    def initialize(config)
      super(config)
      @github_client = github_client
      @cache = CommitCache.new
    end

    def read(since)
      cache = @cache.get(since)
      return cache unless cache.nil?

      commits = []
      together do
        @config.github_repos.map do |repo|
          async do
            commits << fetch_commits(repo, since)
          end
        end
      end
      result = commits.flatten
      @cache.put(since, result)
      result
    end

    private
    def fetch_commits(repo, since)
      @github_client.commits_since(repo, since).map { |commit| commit.commit.message }
    end

    def github_client
      Octokit.configure {|c| c.api_endpoint = @config.github_url} if @config.github_enterprise?
      if @config.has_github_access_token?
        Octokit::Client.new(:access_token => @config.github_access_token)
      else
        Octokit::Client.new
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pairing_matrix-2.3.1 lib/pairing_matrix/github_commit_reader.rb
pairing_matrix-2.3 lib/pairing_matrix/github_commit_reader.rb