Sha256: 1813164646dacc26a0b8e12c7a23c18e4c08e7be29f756dd57b1f668cb5aed83

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

require 'octokit'
require_relative 'config-reader'

module WhatsupGithub
  # Gets pull filtered pull requests from GitHub
  class Pulls
    attr_reader :since, :repo

    def initialize(args = {})
      @repo = args[:repo]
      @since = args[:since]
    end

    def filtered
      issues = []
      labels.each do |label|
        issues += search_issues(label).items
      end
      issues
    end

    private

    # def access_token
    #   credentials.dig 'github_token'
    # end

    def configuration
      Config.instance
    end

    def labels
      configuration.labels
    end

    def base_branch
      configuration.base_branch
    end

    def client
      Octokit::Client.new(:netrc => true)
    end

    def search_issues(label)
      auto_paginate
      client.search_issues("repo:#{repo} label:\"#{label}\" merged:>=#{since} base:#{base_branch}")
    end

    def auto_paginate
      Octokit.auto_paginate = true
    end
  end
end

if $PROGRAM_NAME == __FILE__
  require 'date'
  two_weeks_ago = (Date.today - 14).to_s
  pulls = WhatsupGithub::Pulls.new(repo: 'magento/devdocs', since: two_weeks_ago)
  p pulls.filtered
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
whatsup_github-0.2.0 lib/whatsup_github/pulls.rb