openpull 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 93ef34492341aa8d9560668e6cf02eff1eb110ad
4
+ data.tar.gz: 7993a4091e4edf11698736791a37b676eaaafee1
5
+ SHA512:
6
+ metadata.gz: fbd989668b099cc0d7adc89743bb552c57cd49b11546fe76634a4499f6d09910767c2011188b63f00d07d03bf3d0209e843885f9ebc9c8530a4332ec7530b0ef
7
+ data.tar.gz: 5a881fc40f80e416b5d56267f0fcd2d64fb50a6f18e1d9d248ed15e385559d2e10e3fb00351d5fad9027db3f240435441fe5480da6c447ae7a2f90845e8b02a5
data/bin/openpull ADDED
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+ require 'openpull'
4
+
5
+ options = {}
6
+ op = OptionParser.new do |opts|
7
+ opts.banner = 'Usage: openpull [options]'
8
+
9
+ opts.separator ''
10
+ opts.separator 'Organisation and username can also be set in the ' \
11
+ 'environment as GITHUB_ORGANISATION and GITHUB_USERNAME.'
12
+ opts.separator ''
13
+
14
+ opts.separator "Options:"
15
+
16
+ opts.on_tail('-h', '--help', 'Show this message') do
17
+ puts opts
18
+ exit
19
+ end
20
+
21
+ opts.on_tail("--version", "Show version") do
22
+ puts OpenPull::VERSION
23
+ exit
24
+ end
25
+
26
+ options[:organisation] = ENV['GITHUB_ORGANISATION']
27
+ opts.on('-o', '--organisation [ORG]', String, 'The Github organisation') do |o|
28
+ options[:organisation] = o
29
+ end
30
+
31
+ options[:username] = ENV['GITHUB_USERNAME']
32
+ opts.on('-u', '--username [USER]', String, 'Your Github username') do |u|
33
+ options[:username] = u
34
+ end
35
+ end
36
+
37
+ op.parse!
38
+
39
+ options[:access_token] = ENV['GITHUB_ACCESS_TOKEN']
40
+
41
+ if options[:access_token].nil?
42
+ puts 'You need to set the GitHub access token in your environment. ' \
43
+ '(GITHUB_ACCESS_TOKEN)'
44
+ exit
45
+ elsif options[:organisation].nil?
46
+ puts 'You need to either pass GitHub organisation or set it in your ' \
47
+ 'environment. (GITHUB_ORGANISATION)'
48
+ puts "\n#{op}"
49
+ exit
50
+ end
51
+
52
+ puts OpenPull::Client.new(options[:access_token],
53
+ options[:organisation],
54
+ options[:username]).show_table
@@ -0,0 +1,36 @@
1
+ module OpenPull
2
+ class Client
3
+ attr_reader :octokit_client, :organisation, :username
4
+
5
+ def initialize(access_token, organisation, username)
6
+ @organisation = organisation
7
+ @username = username
8
+
9
+ setup_octokit(access_token)
10
+ end
11
+
12
+ def show_table
13
+ OpenPull::Table.show(sub_tables)
14
+ end
15
+
16
+ private
17
+
18
+ def setup_octokit(access_token)
19
+ stack = Faraday::RackBuilder.new do |b|
20
+ b.use Faraday::HttpCache
21
+ b.use Octokit::Response::RaiseError
22
+ b.adapter Faraday.default_adapter
23
+ end
24
+ Octokit.middleware = stack
25
+
26
+ @octokit_client = Octokit::Client.new(access_token: access_token)
27
+ @octokit_client.auto_paginate = true
28
+ end
29
+
30
+ def sub_tables
31
+ OpenPull::PullRequestFetcher
32
+ .new(octokit_client, organisation, username)
33
+ .fetch
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,45 @@
1
+ module OpenPull
2
+ class PullRequestDecorator < ::SimpleDelegator
3
+ def title
4
+ title = super
5
+ return title if title.size <= 80
6
+
7
+ title[0, 80] + '...'
8
+ end
9
+
10
+ def user
11
+ user = super.login
12
+ user == __getobj__.username ? user.blue : user
13
+ end
14
+
15
+ def labels
16
+ issue = rels[:issue].get.data
17
+ labels = issue.rels[:labels].get.data
18
+
19
+ labels.map { |l| l.name.yellow }.join(', ')
20
+ end
21
+
22
+ def status
23
+ state = rels[:statuses].get.data.map(&:state).first
24
+
25
+ case state
26
+ when 'success'
27
+ state.green
28
+ when 'pending'
29
+ state.yellow
30
+ else
31
+ '--'.red
32
+ end
33
+ end
34
+
35
+ def mergeable
36
+ super ? 'Yes'.green : 'No'.red
37
+ end
38
+
39
+ private
40
+
41
+ def rels
42
+ __getobj__.rels
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,41 @@
1
+ module OpenPull
2
+ class PullRequestFetcher
3
+ attr_reader :client, :organisation, :username
4
+
5
+ def initialize(client, organisation, username = '')
6
+ @client = client
7
+ @organisation = organisation
8
+ @username = username
9
+ end
10
+
11
+ def fetch
12
+ client.org_repos(organisation).map do |repository|
13
+ Thread.new { fetch_pull_requests(repository) }
14
+ end.map(&:value)
15
+ end
16
+
17
+ private
18
+
19
+ def fetch_pull_requests(repository)
20
+ print '.'.green
21
+
22
+ pull_requests = client.pull_requests(repository.id, state: 'open')
23
+ return [] if pull_requests.empty?
24
+
25
+ header = ["#{repository.name} (#{pull_requests.size})".blue.bold]
26
+ header += [''] * (OpenPull::Table::HEADINGS.size - 1)
27
+
28
+ [header] + pull_requests.map { |pr| row(pr) }
29
+ end
30
+
31
+ def row(pr)
32
+ print '.'.yellow
33
+
34
+ deco_pr = OpenPull::PullRequestDecorator.new(pr.rels[:self].get.data)
35
+
36
+ [deco_pr.title, deco_pr.user, deco_pr.labels,
37
+ deco_pr.status, deco_pr.mergeable, deco_pr.html_url,
38
+ deco_pr.updated_at]
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,24 @@
1
+ module OpenPull
2
+ class Table
3
+ HEADINGS = %w(title user labels status mergeable url updated)
4
+
5
+ class << self
6
+ def rewind!
7
+ print "\r"
8
+ end
9
+
10
+ def show(sub_tables)
11
+ rewind!
12
+
13
+ Terminal::Table.new(headings: HEADINGS.map(&:bold)) do |tab|
14
+ sub_tables.each_with_index do |sub_table, j|
15
+ sub_table.each_with_index do |row, i|
16
+ tab.add_separator if i == 0 && j != 0
17
+ tab.add_row row
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module OpenPull
2
+ VERSION = '0.0.1'
3
+ end
data/lib/openpull.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'octokit'
2
+ require 'faraday-http-cache'
3
+ require 'colorize'
4
+ require 'terminal-table'
5
+ require 'delegate'
6
+
7
+ require 'openpull/client'
8
+ require 'openpull/pull_request_decorator'
9
+ require 'openpull/pull_request_fetcher'
10
+ require 'openpull/table'
11
+
12
+ module OpenPull
13
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: openpull
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mads Ohm Larsen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: octokit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: colorize
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.7'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: terminal-table
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.4'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday-http-cache
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.4'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.4'
69
+ description: Fetches open pull-requests, with status and mergability, in your organisation.
70
+ email: mads.ohm@gmail.com
71
+ executables:
72
+ - openpull
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - bin/openpull
77
+ - lib/openpull.rb
78
+ - lib/openpull/client.rb
79
+ - lib/openpull/pull_request_decorator.rb
80
+ - lib/openpull/pull_request_fetcher.rb
81
+ - lib/openpull/table.rb
82
+ - lib/openpull/version.rb
83
+ homepage: http://ohm.sh/
84
+ licenses:
85
+ - MIT
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.2.2
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Fetches Open Pull-Requests from Github
107
+ test_files: []