Sha256: 494ec17b6ffc413d0f08fa99add9076e5eee7dec95334315861e642e00d216d9

Contents?: true

Size: 989 Bytes

Versions: 1

Compression:

Stored size: 989 Bytes

Contents

require 'gitlab'
require 'eldritch'
require_relative '../cache/commit_cache'
require_relative './commit_reader'

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

    protected
    def read(since)
        cache = @cache.get(since)
        return cache unless cache.nil?
  
        commits = []
        together do
            client = gitlab_client
            @config.repositories.map do |repo|
                async do
                    commits << fetch_commits(client, repo, since)
                end
            end
        end

        result = commits.flatten
        @cache.put(since, result)
        result
    end

    private
    def fetch_commits(client, repo, since)
        client.commits(repo, since: since).map { |commit| commit.title }
    end

    def gitlab_client
        Gitlab.client(endpoint: @config.url, private_token: @config.access_token)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pairing_matrix-3.0.0 lib/pairing_matrix/commit_readers/gitlab_commit_reader.rb