gpr 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +28 -27
- data/lib/gpr.rb +1 -0
- data/lib/gpr/cli.rb +37 -0
- data/lib/gpr/git_helper.rb +5 -0
- data/lib/gpr/version.rb +1 -1
- data/lib/graph_drawer.rb +16 -0
- data/lib/graph_drawer/data.rb +30 -0
- data/lib/graph_drawer/graph.rb +98 -0
- data/zsh/gpr.zsh +3 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6aaeb3e46219acf803f62ee8fed9789232e25f1
|
4
|
+
data.tar.gz: c13cb934f58327cd44bb16a54aed8a95734a947d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03bf320b8e4ec2952e6e3893fd5e921826616149d078eef651712b4b8d01983e294c6e4764adddb2e7682b7ff12d3525d661575984734ca9d580368ba6ffb725
|
7
|
+
data.tar.gz: d3269f2cbd486c71b90bb18a596bb9686187e62a01e5ce93208b8df0408ffc273fdff16e31185f50d2576195794bb03d1193111f59aa406100033e844c0bcce1
|
data/README.md
CHANGED
@@ -12,6 +12,14 @@ For example, all repositories are cloned to `$HOME/.gpr/<host>/<user>/<repositor
|
|
12
12
|
|
13
13
|
It is possible to centrally manage of the all repositories.
|
14
14
|
|
15
|
+
## Work with peco
|
16
|
+
|
17
|
+
Gpr provides a list of directories of all registered repositories.
|
18
|
+
|
19
|
+
Therefore, it is powerful when combined with [peco](https://github.com/peco/peco).
|
20
|
+
|
21
|
+
![with\_peco](https://raw.github.com/wiki/kaihar4/gpr/images/with_peco.gif)
|
22
|
+
|
15
23
|
## Installation
|
16
24
|
|
17
25
|
```sh
|
@@ -44,30 +52,36 @@ $ gpr get <host>/<user>
|
|
44
52
|
|
45
53
|
```sh
|
46
54
|
$ gpr list
|
55
|
+
```
|
47
56
|
|
48
|
-
github.com
|
49
|
-
github.com - kaihar4/gpr
|
57
|
+
![list](https://raw.github.com/wiki/kaihar4/gpr/images/list.png)
|
50
58
|
|
59
|
+
```sh
|
51
60
|
$ gpr list --paths
|
61
|
+
```
|
62
|
+
|
63
|
+
![list\_paths](https://raw.github.com/wiki/kaihar4/gpr/images/list_paths.png)
|
64
|
+
|
65
|
+
### Show contributions of registered repositories
|
52
66
|
|
53
|
-
|
54
|
-
|
67
|
+
Display in graph format.
|
68
|
+
|
69
|
+
```sh
|
70
|
+
$ gpr contrib
|
55
71
|
```
|
56
72
|
|
73
|
+
![contrib](https://raw.github.com/wiki/kaihar4/gpr/images/contrib.png)
|
74
|
+
|
57
75
|
### Show the status of all registered repositories
|
58
76
|
|
77
|
+
You can check the status of the registered repositories at a glance.
|
78
|
+
|
59
79
|
```sh
|
60
80
|
$ gpr status
|
61
|
-
|
62
|
-
+-----------------+------------------------------------------+---------------------------+
|
63
|
-
| REPOSITORY NAME | BRANCH STATUS | DIRECTORY STATUS |
|
64
|
-
+-----------------+------------------------------------------+---------------------------+
|
65
|
-
| dotfiles | up-to-date with 'origin/master' | Working directory clean |
|
66
|
-
+-----------------+------------------------------------------+---------------------------+
|
67
|
-
| gpr | ahead of 'origin/master' by 1 commit | Exist unstaged changes |
|
68
|
-
+-----------------+------------------------------------------+---------------------------+
|
69
81
|
```
|
70
82
|
|
83
|
+
![status](https://raw.github.com/wiki/kaihar4/gpr/images/status.png)
|
84
|
+
|
71
85
|
### Search the specified keyword in registered repositories
|
72
86
|
|
73
87
|
Show a list of the files that the specified keyword is included.
|
@@ -84,20 +98,7 @@ Options:
|
|
84
98
|
Search the specified keyword in registered repositories
|
85
99
|
```
|
86
100
|
|
87
|
-
|
88
|
-
$ gpr search 'net/http'
|
89
|
-
|
90
|
-
github.com - kaihar4/gpr : lib/gpr.rb
|
91
|
-
github.com - kaihar4/kaihar4.com : source/articles/2014-06-29-mechanize-scraping.md
|
92
|
-
|
93
|
-
$ gpr search 'net/http' -f '.rb'
|
94
|
-
|
95
|
-
github.com - kaihar4/gpr : lib/gpr.rb
|
96
|
-
|
97
|
-
$ gpr search 'net/http' -r 'kaihar4/kaihar4.com'
|
98
|
-
|
99
|
-
github.com - kaihar4/kaihar4.com : source/articles/2014-06-29-mechanize-scraping.md
|
100
|
-
```
|
101
|
+
![search](https://raw.github.com/wiki/kaihar4/gpr/images/search.png)
|
101
102
|
|
102
103
|
### Update the database to be used for search
|
103
104
|
|
@@ -108,7 +109,7 @@ $ gpr update
|
|
108
109
|
### Fetch all registered repositories
|
109
110
|
|
110
111
|
```sh
|
111
|
-
$ gpr fetch remote_repo
|
112
|
+
$ gpr fetch <remote_repo>
|
112
113
|
```
|
113
114
|
|
114
115
|
If you run for short, it means `gpr fetch origin`.
|
data/lib/gpr.rb
CHANGED
data/lib/gpr/cli.rb
CHANGED
@@ -2,6 +2,7 @@ module Gpr
|
|
2
2
|
class CLI < Thor
|
3
3
|
using Colorize
|
4
4
|
include TableBuilder
|
5
|
+
include GraphDrawer
|
5
6
|
|
6
7
|
desc 'get', 'Get a repository'
|
7
8
|
def get(param)
|
@@ -52,6 +53,42 @@ module Gpr
|
|
52
53
|
end
|
53
54
|
end
|
54
55
|
|
56
|
+
desc 'contrib', 'Show contributions of registered repositories'
|
57
|
+
def contrib(path = nil)
|
58
|
+
if path.nil?
|
59
|
+
dates = []
|
60
|
+
|
61
|
+
repositories = get_repositories
|
62
|
+
repositories.each do |repository|
|
63
|
+
dates.concat(GitHelper.log_by_date(repository))
|
64
|
+
end
|
65
|
+
|
66
|
+
else
|
67
|
+
dates = GitHelper.log_by_date(path)
|
68
|
+
end
|
69
|
+
|
70
|
+
first_date = Time.parse(dates.sort.first)
|
71
|
+
diff = ((Time.now - first_date).to_i / 86400) + 1
|
72
|
+
|
73
|
+
# Initialize a hash
|
74
|
+
commit_counts = {}
|
75
|
+
diff.times.with_index do |index|
|
76
|
+
date = Time.at(first_date + (86400 * index)).strftime('%Y-%m-%d')
|
77
|
+
commit_counts[date] = 0
|
78
|
+
end
|
79
|
+
|
80
|
+
# Count commits
|
81
|
+
dates.each do |date|
|
82
|
+
commit_counts[date] += 1 if commit_counts[date]
|
83
|
+
end
|
84
|
+
|
85
|
+
graph do
|
86
|
+
commit_counts.sort.each do |date, value|
|
87
|
+
data(date, value)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
55
92
|
desc 'search', 'Search the specified keyword in registered repositories'
|
56
93
|
option :file, type: :string, aliases: '-f', desc: 'Filter by filename'
|
57
94
|
option :host, type: :string, aliases: '-h', desc: 'Filter by host'
|
data/lib/gpr/git_helper.rb
CHANGED
data/lib/gpr/version.rb
CHANGED
data/lib/graph_drawer.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'graph_drawer/graph.rb'
|
2
|
+
require 'graph_drawer/data.rb'
|
3
|
+
|
4
|
+
module GraphDrawer
|
5
|
+
def graph(&block)
|
6
|
+
@graph = Graph.new
|
7
|
+
block.call
|
8
|
+
@graph.datas_init
|
9
|
+
@graph.to_s
|
10
|
+
end
|
11
|
+
|
12
|
+
def data(item, value)
|
13
|
+
@data = Data.new(item, value)
|
14
|
+
@graph.add(@data)
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module GraphDrawer
|
2
|
+
class Data
|
3
|
+
using Colorize
|
4
|
+
|
5
|
+
attr_accessor :item
|
6
|
+
attr_accessor :value
|
7
|
+
attr_accessor :level
|
8
|
+
|
9
|
+
def initialize(item, value)
|
10
|
+
@item = item
|
11
|
+
@value = value
|
12
|
+
@level = nil
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
color =
|
17
|
+
case @level
|
18
|
+
when 1
|
19
|
+
:green
|
20
|
+
when 2
|
21
|
+
:cyan
|
22
|
+
when 3
|
23
|
+
:blue
|
24
|
+
end
|
25
|
+
|
26
|
+
bar = ' ' * @value
|
27
|
+
"#{@item}|#{bar.bg_color(color)}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
module GraphDrawer
|
2
|
+
class Graph
|
3
|
+
def initialize
|
4
|
+
@datas = []
|
5
|
+
@max_item_size = 0
|
6
|
+
@max_value_size = 0
|
7
|
+
end
|
8
|
+
|
9
|
+
def add(data)
|
10
|
+
@datas << data
|
11
|
+
@max_item_size = data.item.size if @max_item_size < data.item.size
|
12
|
+
@max_value_size = data.value if @max_value_size < data.value
|
13
|
+
end
|
14
|
+
|
15
|
+
def datas_init
|
16
|
+
@datas.each do |data|
|
17
|
+
# Adjust the data item size
|
18
|
+
data.item = adjust_item_size(data)
|
19
|
+
|
20
|
+
# Set the data level
|
21
|
+
data.level = calc_data_level(data)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_s
|
26
|
+
puts separate
|
27
|
+
|
28
|
+
ommit_flag = false
|
29
|
+
omitted = false
|
30
|
+
|
31
|
+
@datas.each.with_index do |data, index|
|
32
|
+
ommit_flag = false if ommit_flag == true && !data.value.zero?
|
33
|
+
|
34
|
+
# First and Last
|
35
|
+
if index.zero? || index == @datas.size - 1
|
36
|
+
puts data.to_s
|
37
|
+
|
38
|
+
# Omission
|
39
|
+
elsif ommit_flag == true && omitted == false && @datas[index + 1].value.zero?
|
40
|
+
puts draw_omission
|
41
|
+
|
42
|
+
omitted = true
|
43
|
+
|
44
|
+
# Omitted already
|
45
|
+
elsif ommit_flag == true && omitted == true && @datas[index + 1].value.zero?
|
46
|
+
next
|
47
|
+
|
48
|
+
else
|
49
|
+
puts data.to_s
|
50
|
+
|
51
|
+
omitted = false
|
52
|
+
end
|
53
|
+
|
54
|
+
ommit_flag = true if ommit_flag == false && data.value.zero?
|
55
|
+
end
|
56
|
+
|
57
|
+
puts separate
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def adjust_item_size(data)
|
63
|
+
missing_size = @max_item_size - data.item.size
|
64
|
+
|
65
|
+
# Nothing to do
|
66
|
+
return data.item if missing_size.zero?
|
67
|
+
|
68
|
+
if missing_size.even?
|
69
|
+
' ' * (missing_size / 2) + data.item + ' ' * (missing_size / 2)
|
70
|
+
else
|
71
|
+
' ' * (missing_size / 2) + data.item + ' ' * (missing_size / 2 + 1)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def calc_data_level(data)
|
76
|
+
basis = (@max_value_size / 3).round
|
77
|
+
if data.value <= basis * 1
|
78
|
+
1
|
79
|
+
elsif data.value <= basis * 2
|
80
|
+
2
|
81
|
+
else
|
82
|
+
3
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def separate
|
87
|
+
'=' * (@max_item_size + 1 + (@max_value_size * 2))
|
88
|
+
end
|
89
|
+
|
90
|
+
def draw_omission
|
91
|
+
if @max_item_size.even?
|
92
|
+
' ' * (@max_item_size / 2) + '|' + ' ' * (@max_item_size / 2 - 1) + '|'
|
93
|
+
else
|
94
|
+
' ' * (@max_item_size / 2) + '|' + ' ' * (@max_item_size / 2) + '|'
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
data/zsh/gpr.zsh
CHANGED
@@ -23,6 +23,8 @@ function _gpr () {
|
|
23
23
|
'(-)*:: :->null_state' \
|
24
24
|
&& ret=0
|
25
25
|
;;
|
26
|
+
(contrib)
|
27
|
+
;;
|
26
28
|
(search)
|
27
29
|
_arguments -C \
|
28
30
|
'-f[Filter by filename]' \
|
@@ -52,6 +54,7 @@ __gpr_cmds () {
|
|
52
54
|
'get:Get a repository'
|
53
55
|
'help:Describe available commands or one specific command'
|
54
56
|
'list:Show all registered repositories'
|
57
|
+
'contrib:Show contributions of registered repositories'
|
55
58
|
'search:Search the specified keyword in registered repositories'
|
56
59
|
'update:Update the database to be used for search'
|
57
60
|
'fetch:Fetch the registered repositories'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gpr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kaihar4
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -115,6 +115,9 @@ files:
|
|
115
115
|
- lib/gpr/cli.rb
|
116
116
|
- lib/gpr/git_helper.rb
|
117
117
|
- lib/gpr/version.rb
|
118
|
+
- lib/graph_drawer.rb
|
119
|
+
- lib/graph_drawer/data.rb
|
120
|
+
- lib/graph_drawer/graph.rb
|
118
121
|
- lib/table_builder.rb
|
119
122
|
- lib/table_builder/column.rb
|
120
123
|
- lib/table_builder/column_validator.rb
|