github_dash 1.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: 93dec1769b08ecf9352742d50e044fe7d9d6f95f
4
+ data.tar.gz: 5f96a959d2e994a77c3d9cf5f5d6705fba5b355b
5
+ SHA512:
6
+ metadata.gz: 0a1abbd5bbaaf54ad566d40fc566297c4ddb829cea5fd58c3a074ee5b8a06d4236db758575de88c53d4ad0f1c10611c2fd52a1c6e35f09fa9c9fa9adaaeab29c
7
+ data.tar.gz: b00771e302849e69c51f5048b0c079b507346f9626624f58930f9d2d6989c173d639dcac7cf212e132943fcee42b5fb879f8002d57e7c1b2f2aafabf186d06c0
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.15.3
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in github_dash.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # GithubDash
2
+
3
+ A dashboard for viewing github repopsitories in a unix terminal.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'github_dash'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install github_dash
20
+
21
+ ## Usage
22
+
23
+ TBA
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/josefwaller/github_dash.
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "github_dash"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/github-dash ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require "github_dash/cli"
3
+ GithubDash::CLI.start
@@ -0,0 +1,46 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "github_dash/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "github_dash"
8
+ spec.version = GithubDash::VERSION
9
+ spec.authors = ["Josef Waller"]
10
+ spec.email = ["josef@siriusapplications.com"]
11
+
12
+ spec.summary = %q{A terminial dashboard for github.}
13
+ spec.description = %q{A dashboard for viewing the changes in github repositories over time.}
14
+ spec.homepage = "https://github.com/josefwaller/github-dash"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.15"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+ spec.add_dependency "octokit", "~> 4.0"
37
+ spec.add_development_dependency "webmock", "~> 3.0.1"
38
+ spec.add_development_dependency "vcr", "~> 3.0.3"
39
+ spec.add_dependency "thor", "~> 0.19.4"
40
+ spec.add_dependency "tty-prompt", "~> 0.13.2"
41
+ spec.add_dependency "tty-cursor", "~> 0.5.0"
42
+ spec.add_dependency "sqlite3", "~> 1.3.13"
43
+ spec.add_dependency "sequel", "~> 4.49.0"
44
+ spec.add_dependency "tty-table", "~> 0.8.0"
45
+ spec.add_dependency "pastel", "~> 0.7.1"
46
+ end
@@ -0,0 +1,47 @@
1
+ require "github_dash/version"
2
+ require "github_dash/repository"
3
+ require "github_dash/data_depository"
4
+ require "octokit"
5
+
6
+ module GithubDash
7
+ # Fetch repository information given a reposoitory name
8
+ def self.fetch_repository(repository_name)
9
+ Repository.new repository_name
10
+ end
11
+
12
+ # Add a repository to the list of followed repositories
13
+ def self.add_repo_to_following(name, token=nil)
14
+ token ||= DataDepository.get_token
15
+ # Check that the repository exists
16
+ client = Octokit::Client.new(:access_token => token)
17
+ client.repository name
18
+
19
+ DataDepository.add_repo name, token
20
+ end
21
+
22
+ # Remove a repository from the list of followed repositories
23
+ def self.remove_repo_from_following(name)
24
+ # Tell the user whether it removed a repo or not
25
+ DataDepository.remove_repo name
26
+ end
27
+
28
+ # Get an array of the names of followed repositories
29
+ def self.get_following
30
+ DataDepository.get_following
31
+ end
32
+
33
+ # Save a user's token for getting private repositories
34
+ def self.add_user(username, password)
35
+ # Create new token
36
+ client = Octokit::Client.new :login => username, :password => password
37
+ token = client.create_authorization(:scopes => ["repo"], :note => "github-dash token").token
38
+
39
+ # Save it
40
+ DataDepository.save_token(token, username)
41
+ end
42
+
43
+ # Add a token and set it to be used first when fetching repositories
44
+ def self.add_token(token, token_name)
45
+ DataDepository.save_token(token, token_name)
46
+ end
47
+ end
@@ -0,0 +1,286 @@
1
+ require "thor"
2
+ require "github_dash"
3
+ require "pp"
4
+ require "tty-cursor"
5
+ require "tty-table"
6
+ require "tty-prompt"
7
+ require "pastel"
8
+
9
+ module GithubDash
10
+ class CLI < Thor
11
+
12
+ def initialize(*args)
13
+ super
14
+ @prompt = TTY::Prompt.new
15
+ @pastel = Pastel.new
16
+ end
17
+
18
+ desc "add_repo REPO_NAME", "Adds a repository to the 'followed repositories' list"
19
+ def add_repo(name)
20
+ # Keep looping while the user is choosing different tokens
21
+ token = nil
22
+ loop do
23
+ begin
24
+ # Try to successfully add repository
25
+ GithubDash::add_repo_to_following(name, token)
26
+ @prompt.say "Added #{name} to followed repositories."
27
+ break
28
+ rescue ArgumentError
29
+ # If repo is already follewed, just break
30
+ @prompt.say "Repository is already followed!"
31
+ break
32
+ rescue Octokit::NotFound, Octokit::Unauthorized
33
+ # Prompt user to enter another token
34
+ @prompt.say "Could not find #{name} on github using #{@pastel.bright_blue(token)}."
35
+ ans = @prompt.yes? "Do you want to try with a different token?"
36
+
37
+ # break if they said no
38
+ break unless ans
39
+
40
+ # Make menu for them to choose a toekn
41
+ token = @prompt.select "Chose a token" do |menu|
42
+ tokens = GithubDash::DataDepository.get_all_tokens
43
+ # There must be at least 1 token to choose from
44
+ if tokens.size < 1
45
+ @prompt.say @pastel.red("No tokens added. Add a token with add_token.")
46
+ return
47
+ end
48
+ # Add a choice per token
49
+ tokens.map do |t|
50
+ menu.choice(t[:name], t[:token])
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ desc "remove_repos", "Remove one repository from the 'followed repositories' list"
58
+ def remove_repos
59
+ # Prompt user for repos
60
+ repos = @prompt.multi_select "Select which repos to remove" do |menu|
61
+ GithubDash::DataDepository.get_following.each do |r|
62
+ menu.choice r
63
+ end
64
+ end
65
+ # Delete each one
66
+ repos.each do |name|
67
+ GithubDash::remove_repo_from_following(name)
68
+ end
69
+ @prompt.say "Removed #{repos.size} repositories."
70
+ end
71
+
72
+ desc "login", "Log into github to allow access to private repositories and increase API limit."
73
+ def login
74
+
75
+ # Prompt for username/password
76
+ username = @prompt.ask("Enter username: ")
77
+ password = @prompt.ask("Enter password: ", echo: false)
78
+
79
+ GithubDash::add_user(username, password)
80
+ @prompt.say "Added #{@pastel.bright_blue(username)}"
81
+ end
82
+
83
+ desc "add_token TOKEN", "Save a token and set it to be used first for all repositories"
84
+ option :token_name, :aliases => [:n], :type => :string, :required => true
85
+ def add_token(token)
86
+ GithubDash::add_token(token, options[:token_name])
87
+ @prompt.say "Added #{@pastel.bright_blue(options[:token_name])}"
88
+ end
89
+
90
+ desc "remove_tokens", "Delete one or more tokens"
91
+ def remove_tokens
92
+
93
+ # Get the tokens to remove
94
+ remove_tokens = @prompt.multi_select "Select which tokens to remove" do |menu|
95
+ GithubDash::DataDepository.get_all_tokens.each do |t|
96
+ menu.choice t[:name], t[:token]
97
+ end
98
+ end
99
+ @prompt.say "You are removing #{@pastel.bright_blue(remove_tokens.size)} tokens"
100
+
101
+ # Double check
102
+ if @prompt.yes?("Proceed: ")
103
+
104
+ # Remove the tokens
105
+ remove_tokens.each do |t|
106
+ GithubDash::DataDepository.delete_token(t)
107
+ end
108
+
109
+ @prompt.say "Removed #{@pastel.bright_blue(remove_tokens.size)} tokens."
110
+ else
111
+ @prompt.say "Cancelled"
112
+ end
113
+ end
114
+
115
+ desc "compare_review", "Print a comparative review of several user's commits on a certain repository"
116
+ option :repo_name, :aliases => [:r], :type => :string, :required => true
117
+ option :users, :aliases => [:u], :type => :array, :required => true
118
+ option :days, :aliases => [:d], :type => :numeric, :default => 7
119
+ def compare_review
120
+ # First, create headers, which is just
121
+ # the user's option aligned center
122
+ headers = options[:users].map {|u| {value: u, alignment: :center}}
123
+
124
+ # Create a new table
125
+ table = TTY::Table.new :header => headers do |t|
126
+
127
+ # Create empty 2D array
128
+ rows = Array.new(options[:users].count) { [] }
129
+
130
+ # Fetch the repo
131
+ repo = GithubDash::fetch_repository options[:repo_name]
132
+
133
+ # Get the commit messages for each user
134
+ options[:users].each_with_index do |val, i|
135
+ commits = repo.get_commits(10, val)
136
+
137
+ # Add their messages to the rwos array
138
+ commits.each_with_index do |c, c_i|
139
+ rows[i].push c.commit.message.split("\n").first
140
+ end
141
+ end
142
+ # Pads the rows until they are all equal size
143
+ mx_size = rows.map(&:size).max
144
+ rows.each {|r| r.fill(nil, r.count, mx_size - r.count) }
145
+
146
+ # Since we have one user per row, but the table will have one user per column,
147
+ # transpose the rows before adding them
148
+ rows.transpose.each do |r|
149
+ t << r
150
+ end
151
+ end
152
+
153
+ # Tell user what repos we are comparing
154
+ @prompt.say "\n"
155
+ @prompt.say "Comparing commits from #{@pastel.bright_green(options[:repo_name])}" \
156
+ " in the last #{@pastel.bright_green(options[:days])}".center(table.width)
157
+ @prompt.say "\n"
158
+
159
+ # Pastel colors only show up when the table is saved as a string first
160
+ table_str = table.render(:unicode) do |r|
161
+ r.filter = Proc.new do |val, row_index, col_index|
162
+ if row_index == 0
163
+ @pastel.yellow(val)
164
+ else
165
+ @pastel.bright_blue(val)
166
+ end
167
+ end
168
+ r.padding = [0, 1]
169
+ end
170
+
171
+ # Print the table
172
+ @prompt.say table_str
173
+ end
174
+
175
+ desc "following", "Show all the repopsitories the user is following"
176
+ option :liveupdate, :aliases => [:l], :type => :boolean, :default => false
177
+ def following
178
+
179
+ # Gather all repos
180
+ repos = {}
181
+ GithubDash::get_following.each do |r|
182
+ repos[r] = GithubDash::fetch_repository r
183
+ end
184
+
185
+ # Loop while liveupdating
186
+ loop do
187
+ begin
188
+ # Create table
189
+ table = TTY::Table.new(header: ["Repository", "PRs in the last week", "Commits in the last week"]) do |t|
190
+ # Add each repo's data to the table
191
+ repos.each do |r, val|
192
+ repos.fetch(r).update_commits 100
193
+ repos.fetch(r).update_pull_requests 100
194
+ t << [val.data.full_name, val.get_pull_requests.size, val.get_commits.size]
195
+ end
196
+ end
197
+
198
+ # Get the table's string
199
+ table_str = table.render(:unicode) do |r|
200
+ r.filter = Proc.new do |val, row, col|
201
+ # The headers are yellow
202
+ if row == 0
203
+ @pastel.yellow(val)
204
+ else
205
+ # Set different colors for different columns
206
+ case col
207
+ when 0
208
+ @pastel.bright_blue val
209
+ when 1
210
+ @pastel.bright_green val
211
+ when 2
212
+ @pastel.bright_red val
213
+ else
214
+ val
215
+ end
216
+ end
217
+ end
218
+ r.padding = [0, 1]
219
+ end
220
+
221
+ # Clear the screen and move the cursor to the too left
222
+ # Note: This must be done before printing the table
223
+ if options[:liveupdate]
224
+ print TTY::Cursor.clear_screen
225
+ print TTY::Cursor.move_to
226
+ print TTY::Cursor.hide
227
+ end
228
+ # Print the table
229
+ @prompt.say table_str
230
+
231
+ # If not live updating, break
232
+ break unless options[:liveupdate]
233
+ # Update every 10 seconds
234
+ sleep 10
235
+ ensure
236
+ # If the user quits, show the cursor
237
+ # otherwise the cursor won't show in regular terminal
238
+ print TTY::Cursor.show
239
+ end
240
+ end
241
+ end
242
+
243
+ option :days, :aliases => [:d], :type => :numeric, :default => 7
244
+ desc "repo REPO_NAME", "Logs a bunch of information about a repository"
245
+ def repo(name)
246
+ # Fetch repo information
247
+ repo = GithubDash::fetch_repository name
248
+
249
+ # Create a table for this repo's informaion
250
+ table = TTY::Table.new header: ["Commit Date", "Commit Title", "Commit Author"] do |t|
251
+ repo.get_commits(options[:days]).each do |c|
252
+ t << [c.commit.author.date, c.commit.message.split("\n").first, c.commit.author.name]
253
+ end
254
+ end
255
+
256
+ # print title for the table
257
+ @prompt.say "\n"
258
+ @prompt.say @pastel.yellow(repo.data.full_name)
259
+ @prompt.say "Commits from the last #{@pastel.bright_green(options[:days])} day#{"s" if options[:days] > 1}"
260
+ table_str = table.render(:unicode) do |r|
261
+ r.filter = Proc.new do |val, row_index, col_index|
262
+
263
+ # Headers are yellow
264
+ if row_index == 0
265
+ @pastel.yellow(val)
266
+ else
267
+ # columns have different colors
268
+ case col_index
269
+ when 0
270
+ @pastel.bright_blue(val)
271
+ when 1
272
+ @pastel.bright_red(val)
273
+ when 2
274
+ @pastel.green(val)
275
+ else
276
+ val
277
+ end
278
+ end
279
+ end
280
+ r.padding = [0, 1]
281
+ end
282
+ # Print the table
283
+ @prompt.say table_str
284
+ end
285
+ end
286
+ end
@@ -0,0 +1,114 @@
1
+ require "github_dash"
2
+ require "sequel"
3
+
4
+ module GithubDash
5
+
6
+ # Store and manage all repositories the user choses to follow
7
+ # and the tokens needed to access them
8
+ class DataDepository
9
+
10
+ # Save a repo name in the following list
11
+ def self.add_repo(repo_name, token=nil)
12
+ # Check the repo is not already followed
13
+ if get_db[:repos].where(:name => repo_name.downcase).all.count > 0
14
+ raise ArgumentError, "Tried to follow a repository that was already followed!"
15
+ end
16
+
17
+ # Add repository to database
18
+ if token.nil?
19
+ token_id = nil
20
+ else
21
+ token_id = get_db[:tokens].where(:token => token).first[:id]
22
+ end
23
+ get_db[:repos].insert(:name => repo_name.downcase, :token_id => token_id)
24
+ end
25
+
26
+ # Remove a repository from a list of followed repositories
27
+ def self.remove_repo(repo_name)
28
+ # Remove the repository
29
+ if get_db[:repos].where(:name => repo_name.downcase).delete == 0
30
+ # `delete` will return the number of entries deleted
31
+ # So if none were deleted, raise an error
32
+ raise ArgumentError, "Tried removing a repository that was not followed!"
33
+ end
34
+ end
35
+
36
+ # Get an array of the names of followed repositories
37
+ def self.get_following
38
+ # Create an arrau of just the repo's names
39
+ get_db[:repos].all.map do |r|
40
+ r[:name]
41
+ end
42
+ end
43
+
44
+ # Save a token to be used for logging in
45
+ def self.save_token(token, token_name)
46
+ # Add this token
47
+ get_db[:tokens].insert(:token => token, :name => token_name)
48
+ end
49
+
50
+ # Delete a token
51
+ def self.delete_token(token)
52
+ # Delete it
53
+ get_db[:tokens].where(:token => token).delete
54
+ end
55
+
56
+ # Get the github API token
57
+ def self.get_token(place_from_last = 0)
58
+ tokens = get_db[:tokens].order(:id)
59
+ # Will return nil if empty
60
+ return nil if tokens.empty? || place_from_last >= tokens.all.count
61
+
62
+ # Returns the token in the place from last specifiedl
63
+ tokens.all[- (place_from_last + 1)][:token]
64
+ end
65
+
66
+ # Get all the tokens saved
67
+ def self.get_all_tokens
68
+ get_db[:tokens].all.map do |t|
69
+ { token: t[:token], name: t[:name] }
70
+ end
71
+ end
72
+
73
+ # Get the token for a certain repository
74
+ def self.get_token_for_repo(repo_name)
75
+ repo = get_db[:repos].where(:name => repo_name.downcase).first
76
+ return nil if repo.nil? || repo[:token_id].nil?
77
+ token_id = repo[:token_id]
78
+
79
+ get_db[:tokens].where(:id => token_id).first[:token]
80
+ end
81
+
82
+ # Get the database from the .db file and creates
83
+ # all tables unless they already exist
84
+ def self.get_db
85
+
86
+ # Does not load the database twice
87
+ unless class_variable_defined?(:@@db)
88
+
89
+ @@db = Sequel.sqlite("#{ENV['HOME']}/.github_dash/data.db")
90
+
91
+ # Create the tables
92
+ # Note: create_table? works the same as create_table,
93
+ # except that it will not override an existing table
94
+ # with the same name.
95
+ @@db.create_table? :repos do
96
+ primary_key :id
97
+ String :name, :unique => true
98
+ # The ID of the token used to fetch this repo
99
+ foriegn_key :token_id
100
+ end
101
+
102
+ @@db.create_table? :tokens do
103
+ primary_key :id
104
+ String :token, :unique => true
105
+ String :name, :unique => true
106
+ end
107
+ end
108
+
109
+ @@db
110
+ end
111
+
112
+ private_class_method :get_db
113
+ end
114
+ end
@@ -0,0 +1,60 @@
1
+ require "octokit"
2
+ require 'pp'
3
+
4
+ module GithubDash
5
+ class Repository
6
+ # Fetch a new repository
7
+ def initialize(repo_name)
8
+ # Use client if logged in
9
+ @repo_data = client_for(repo_name).repository(repo_name)
10
+ end
11
+
12
+ # Get the raw octokit data
13
+ def data
14
+ @repo_data
15
+ end
16
+
17
+ # Update cached PR data
18
+ def update_pull_requests(up_to=100)
19
+ @pull_requests = client_for.pull_requests(@repo_data.full_name, :per_page => up_to)
20
+ end
21
+
22
+ # Get the pull requests opened in the last so many days
23
+ def get_pull_requests(days=7)
24
+ update_pull_requests if @pull_requests.nil?
25
+ @pull_requests.take_while do |pr|
26
+ pr.created_at.to_date > Date.today - days
27
+ end
28
+ end
29
+
30
+ # Update cached commits
31
+ def update_commits(up_to=100)
32
+ @commits = client_for.commits(@repo_data.full_name, :per_page => up_to)
33
+ end
34
+
35
+ # Get all commits in a certain time period
36
+ def get_commits(days=7, user=nil)
37
+ update_commits if @commits.nil?
38
+ # Note that while get_pull_requests can use take_while, commits will also include
39
+ # merges and therefore the dates are not neccissarily in order
40
+ @commits.select do |c|
41
+ c.commit.author.date.to_date > Date.today - days && (user.nil? || c.committer.login == user)
42
+ end
43
+ end
44
+
45
+ # Get a client which can access certain repository
46
+ # If passed without a pre_name parameter, assume that @repo_data has been
47
+ # initialized, and get the name from that
48
+ def client_for(repo_name = nil)
49
+ repo_name ||= @repo_data.full_name
50
+ # Get the token
51
+ token = GithubDash::DataDepository.get_token_for_repo(repo_name)
52
+ # Use the most recent token if this repo doesn't have an associated token
53
+ token = GithubDash::DataDepository.get_token if token.nil?
54
+ # Use default client if the token is nil
55
+ Octokit if token.nil?
56
+ # Return new client
57
+ client = Octokit::Client.new(:access_token => token)
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,3 @@
1
+ module GithubDash
2
+ VERSION = "1.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,244 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: github_dash
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Josef Waller
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-09-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: octokit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 3.0.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.0.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 3.0.3
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 3.0.3
97
+ - !ruby/object:Gem::Dependency
98
+ name: thor
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.19.4
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.19.4
111
+ - !ruby/object:Gem::Dependency
112
+ name: tty-prompt
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.13.2
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.13.2
125
+ - !ruby/object:Gem::Dependency
126
+ name: tty-cursor
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 0.5.0
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 0.5.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: sqlite3
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 1.3.13
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 1.3.13
153
+ - !ruby/object:Gem::Dependency
154
+ name: sequel
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 4.49.0
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 4.49.0
167
+ - !ruby/object:Gem::Dependency
168
+ name: tty-table
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: 0.8.0
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: 0.8.0
181
+ - !ruby/object:Gem::Dependency
182
+ name: pastel
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: 0.7.1
188
+ type: :runtime
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: 0.7.1
195
+ description: A dashboard for viewing the changes in github repositories over time.
196
+ email:
197
+ - josef@siriusapplications.com
198
+ executables:
199
+ - github-dash
200
+ extensions: []
201
+ extra_rdoc_files: []
202
+ files:
203
+ - ".gitignore"
204
+ - ".rspec"
205
+ - ".travis.yml"
206
+ - Gemfile
207
+ - LICENSE.txt
208
+ - README.md
209
+ - Rakefile
210
+ - bin/console
211
+ - bin/setup
212
+ - exe/github-dash
213
+ - github_dash.gemspec
214
+ - lib/github_dash.rb
215
+ - lib/github_dash/cli.rb
216
+ - lib/github_dash/data_depository.rb
217
+ - lib/github_dash/repository.rb
218
+ - lib/github_dash/version.rb
219
+ homepage: https://github.com/josefwaller/github-dash
220
+ licenses:
221
+ - MIT
222
+ metadata:
223
+ allowed_push_host: https://rubygems.org
224
+ post_install_message:
225
+ rdoc_options: []
226
+ require_paths:
227
+ - lib
228
+ required_ruby_version: !ruby/object:Gem::Requirement
229
+ requirements:
230
+ - - ">="
231
+ - !ruby/object:Gem::Version
232
+ version: '0'
233
+ required_rubygems_version: !ruby/object:Gem::Requirement
234
+ requirements:
235
+ - - ">="
236
+ - !ruby/object:Gem::Version
237
+ version: '0'
238
+ requirements: []
239
+ rubyforge_project:
240
+ rubygems_version: 2.6.13
241
+ signing_key:
242
+ specification_version: 4
243
+ summary: A terminial dashboard for github.
244
+ test_files: []