gitGraph 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2ef0185233741d9fe0914102d81fe41ab83d9923
4
+ data.tar.gz: 475770178ffc17cf3a66be1adbe7a497c8d14762
5
+ SHA512:
6
+ metadata.gz: cca0d2447edc9d7373dffc34365d34fc8f186934e92413bfadd9791fb870330dd9c6ec67ae3360dc682ffcdbe0f2b93eb129ea3fbb6516859ec85aedbdcb89de
7
+ data.tar.gz: c8c13184784ffa829126cbb5f5e5bc93bc1de7dc0935c54e1cffc8c6f0dc92529761ef92cd56ca72d1b31976578b4ae5431e5c4b8f58d66ccf92ae788ab7f932
@@ -0,0 +1,41 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ *.gem
16
+ *.rbc
17
+ /.config
18
+ /coverage/
19
+ /InstalledFiles
20
+ /pkg/
21
+ /spec/reports/
22
+ /test/tmp/
23
+ /test/version_tmp/
24
+ /tmp/
25
+ .env
26
+ ## Documentation cache and generated files:
27
+ /.yardoc/
28
+ /_yardoc/
29
+ /doc/
30
+ /rdoc/
31
+ examplefile.rb
32
+
33
+ ## Environment normalisation:
34
+ /.bundle/
35
+ /lib/bundler/man/
36
+
37
+ # for a library or gem, you might want to ignore these files since the code is
38
+ # intended to run in multiple environments; otherwise, check them in:
39
+ # Gemfile.lock
40
+ # .ruby-version
41
+ # .ruby-gemset
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --require spec_helper
3
+ --format doc
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rack'
4
+ gem 'octokit'
5
+ gem 'rspec'
6
+ gem 'dotenv-rails'
7
+ gem 'color-generator'
8
+ gem 'erb'
9
+
10
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Joe Canero
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 all
13
+ 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 THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 caneroj1
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,67 @@
1
+ # GitGraph
2
+
3
+ Displays nice graphs of GitHub usage through a Rack App. Can help you analyze things like what languages you most frequently push in, etc.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'gitGraph'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install gitGraph
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require 'gitGraph'
25
+
26
+ # configuring the client
27
+ GitGraph::Configuration.config do |config|
28
+ config.username = # your github username
29
+ config.password = # your github password
30
+ end
31
+
32
+ # your GitGraph client is now all configured to access GitHub's apis
33
+ client = GitGraph::GitHub::Client.new
34
+
35
+ # start adding GitHub users
36
+ client << # some github username
37
+
38
+ client + # another github username
39
+
40
+ # you can also github users using integers.
41
+ ## CAUTION: these are not guaranteed to exist. ##
42
+
43
+ client + 1
44
+
45
+ # let's run a language comparison. this checks all of
46
+ # the public repositories for each added user and tallies
47
+ # up their language usage.
48
+ client.compare_languages(:radar) # using a radar chart
49
+
50
+ # we can change to a bar chart
51
+ # the compare languages feature is indexed under
52
+ # the :languages key.
53
+ client.change_chart_type(:languages, :bar)
54
+
55
+ # let's render our chart
56
+ path = # path to where you want the chart
57
+ client.render(path)
58
+
59
+ ```
60
+
61
+ ## Contributing
62
+
63
+ 1. Fork it ( https://github.com/[my-github-username]/gitGraph/fork )
64
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
65
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
66
+ 4. Push to the branch (`git push origin my-new-feature`)
67
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gitGraph/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gitGraph"
8
+ spec.version = GitGraph::VERSION
9
+ spec.authors = ["caneroj1"]
10
+ spec.email = ["caneroj1@tcnj.edu"]
11
+ spec.summary = %q{Displays nice graphs of GitHub usage through a Rack App.}
12
+ spec.description = %q{Displays nice graphs of GitHub usage through a Rack App. Can help you analyze things like what languages you most frequently push in, etc.}
13
+ spec.homepage = "https://github.com/caneroj1/GitGraph"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
@@ -0,0 +1,6 @@
1
+ require_relative "gitGraph/version"
2
+ require_relative "utils"
3
+
4
+ module GitGraph
5
+ require_files(File.dirname(__FILE__) << "/gitGraph/*")
6
+ end
@@ -0,0 +1,16 @@
1
+ module GitGraph
2
+ class Configuration
3
+ class << self
4
+ attr_accessor :username, :password
5
+
6
+ def config
7
+ raise ArgumentError, block_error if !block_given?
8
+ yield self
9
+ end
10
+
11
+ def block_error
12
+ "A block must be passed in order to set attributes."
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,71 @@
1
+ require 'octokit'
2
+ require_relative '../configuration'
3
+ require_relative 'graphable_object'
4
+ require_relative 'feature'
5
+ require_relative '../renderer.rb'
6
+
7
+ module GitGraph
8
+ module GitHub
9
+ class Client
10
+ attr_reader :client
11
+ include Enumerable
12
+
13
+ def initialize
14
+ @client = Octokit::Client.new(
15
+ login: GitGraph::Configuration.username,
16
+ password: GitGraph::Configuration.password
17
+ )
18
+
19
+ @stored_users = {
20
+ GitGraph::Configuration.username =>
21
+ @client.user
22
+ }
23
+
24
+ @data_to_graph = {}
25
+ end
26
+
27
+ def get_user(key)
28
+ @stored_users.fetch(key)
29
+ end
30
+ alias_method :[], :get_user
31
+
32
+ def add_user(user)
33
+ user_to_add = @client.user(user)
34
+ @stored_users[user_to_add.login] = user_to_add
35
+ end
36
+ alias_method :<<, :add_user
37
+ alias_method :+, :add_user
38
+
39
+ def remove_user(user)
40
+ @stored_users.delete(user)
41
+ end
42
+ alias_method :-, :remove_user
43
+
44
+ def user_count
45
+ @stored_users.count
46
+ end
47
+ alias_method :user_size, :user_count
48
+
49
+ def change_chart_type(graphable_object_name, chart_type)
50
+ @data_to_graph[graphable_object_name].chart_type = chart_type
51
+ end
52
+
53
+ def each
54
+ @stored_users.each { |name, user| yield(name, user) }
55
+ end
56
+
57
+ def compare_languages(chart, **options)
58
+ options ||= {}
59
+ title = options.delete(:title) || "Kilobytes Written per Language"
60
+ data = GitGraph::GitHub::Feature.send(:compare_languages, self)
61
+ graphable = GitGraph::GitHub::GraphableObject.new(data, chart, options, title)
62
+ @data_to_graph[:languages] = graphable
63
+ end
64
+
65
+ def render(path)
66
+ @data_to_graph.each { |key, data| GitGraph::Renderer.render(data, key, path) }
67
+ GitGraph::Renderer.copy_files(path)
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,11 @@
1
+ require_relative '../../utils'
2
+
3
+ module GitGraph
4
+ module GitHub
5
+ class Feature
6
+ class << self
7
+ require_files(File.dirname(__FILE__) << "/feature/*")
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,51 @@
1
+ require 'octokit'
2
+ require_relative '../graphable_data'
3
+
4
+ def compare_languages(client)
5
+ # languages will be the array that will be used
6
+ # to form labels in the chart
7
+ languages = []
8
+
9
+ # datasets will hold the data that we obtain for each user
10
+ # based on github querying for their languages
11
+ datasets = []
12
+
13
+ client.each do |name, user|
14
+ new_dataset = {
15
+ label: name,
16
+ data: {}
17
+ }
18
+
19
+ client.client.repositories(name).each do |repo|
20
+ client.client.languages(repo.full_name).attrs.each_pair do |lang, value|
21
+ languages.push(lang) unless languages.include?(lang)
22
+ new_dataset[:data][lang] ||= 0
23
+ new_dataset[:data][lang] += value
24
+ end
25
+ end
26
+
27
+ datasets.push(new_dataset)
28
+ end
29
+
30
+ # sort the languages
31
+ languages.sort!
32
+
33
+ # go through the languages, and if a dataset does not have that language
34
+ # as part of its data array, default it to 0
35
+ languages.each do |lang|
36
+ datasets.each { |dataset| dataset[:data][lang] ||= 0}
37
+ end
38
+
39
+ # convert the data hash to an array
40
+ datasets.each { |dataset| dataset[:data] = dataset[:data].to_a }
41
+
42
+ # sort on the array by key
43
+ datasets.each { |dataset| dataset[:data].sort! { |a, b| a[0] <=> b[0] } }
44
+
45
+ # each value in the array represents bytes of code written in a language.
46
+ # convert each value in the array to kilobytes written in each language
47
+ datasets.each { |dataset| dataset[:data].each { |data| data[1] /= 1024} }
48
+
49
+ # return a new graphable data item
50
+ GitGraph::GitHub::GraphableData.new(labels: languages, datasets: datasets)
51
+ end
@@ -0,0 +1,107 @@
1
+ require 'color-generator'
2
+
3
+ module GitGraph
4
+ module GitHub
5
+ class GraphableData
6
+ attr_accessor :labels, :datasets
7
+
8
+ # datasets should be an array of hashes. each has needs to contain
9
+ # a label => name key-value pair, which is basically the name of that dataset, and
10
+ # and a data => data_arr key-value pair, which is just an array of data points.
11
+ def initialize(labels: labels, datasets: datasets)
12
+ @labels, @datasets = labels, datasets
13
+ end
14
+
15
+
16
+ def stringify(chart_type, options = {})
17
+ new_options = format_options(options)
18
+ map_colors_to_datasets(new_options)
19
+ if chart_type == :polar_area
20
+ format_for_polar_area(new_options)
21
+ else
22
+ format_chart(new_options)
23
+ end
24
+ end
25
+
26
+ def map_colors_to_datasets(options)
27
+ @datasets.map! { |dataset| dataset.merge(prettify(options)) }
28
+ end
29
+
30
+ def prettify(options)
31
+ prettified_hash = {}
32
+ base_color = ColorGenerator.new(saturation: 1.0, value: 1.0).create_rgb
33
+
34
+ fill_color = new_color(base_color, options[:fill_alpha])
35
+ stroke_color = new_color(base_color, options[:stroke_alpha])
36
+ { :fillColor => fill_color, :strokeColor => stroke_color, :pointColor => stroke_color,
37
+ :pointStrokeColor => options[:point_stroke_color], :pointHighlightFill => options[:point_highlight_fill],
38
+ :pointHighlightStroke => stroke_color }
39
+ end
40
+
41
+ def new_color(color, alpha)
42
+ "rgba(#{color[0]}, #{color[1]}, #{color[2]}, #{alpha})"
43
+ end
44
+
45
+ def format_options(options)
46
+ options[:fill_alpha] ||= 0.2
47
+ options[:stroke_alpha] ||= 1.0
48
+ options[:point_stroke_color] ||= '#fff'
49
+ options[:point_highlight_fill] ||= '#fff'
50
+ options
51
+ end
52
+
53
+ private
54
+ def format_chart(new_options)
55
+ main_string = make_options(new_options)
56
+ main_string << "\nvar data = {\n"
57
+ main_string << make_labels
58
+ main_string << make_datasets
59
+ main_string << "\n};"
60
+ end
61
+
62
+ def make_options(new_options)
63
+ options_string = "var options = {\n"
64
+ opts_arr = []
65
+
66
+ new_options.each do |key, value|
67
+ if value.class.eql?(String)
68
+ opts_arr.push("\t#{key}: '#{value}'")
69
+ else
70
+ opts_arr.push("\t#{key}: #{value}")
71
+ end
72
+ end
73
+
74
+ options_string << opts_arr.join(",\n")
75
+ options_string << "\n};"
76
+ options_string
77
+ end
78
+
79
+ def make_labels
80
+ "\tlabels: #{@labels.map { |label| label.to_s }.inspect},\n"
81
+ end
82
+
83
+ def make_datasets
84
+ main_string = "\tdatasets: ["
85
+ dataset_string_array = []
86
+
87
+ @datasets.each do |dataset|
88
+ new_string = "\n\t\t{\n"
89
+ dataset_string_components = []
90
+
91
+ dataset.each_pair do |key, value|
92
+ value = value.class.eql?(String) ? "\"#{value}\"" : value.map { |item| [item[1]]}
93
+ dataset_string_components.push("\t\t\t#{key}: #{value}")
94
+ end
95
+
96
+ new_string << dataset_string_components.join(",\n")
97
+ new_string << "\n\t\t}"
98
+
99
+ dataset_string_array.push(new_string)
100
+ end
101
+
102
+ main_string << dataset_string_array.join(',')
103
+ main_string << "\n\t]"
104
+ end
105
+ end
106
+ end
107
+ end