gpr 0.1.3 → 0.2.0
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.
- checksums.yaml +4 -4
- data/README.md +4 -26
- data/bin/gpr +1 -27
- data/lib/gpr.rb +4 -6
- data/lib/gpr/action.rb +18 -0
- data/lib/gpr/actions/contrib.rb +14 -0
- data/lib/gpr/actions/search.rb +52 -0
- data/lib/gpr/commands/base.rb +11 -0
- data/lib/gpr/commands/contrib.rb +51 -0
- data/lib/gpr/commands/fetch.rb +35 -0
- data/lib/gpr/commands/get.rb +27 -0
- data/lib/gpr/commands/list.rb +30 -0
- data/lib/gpr/commands/search.rb +60 -0
- data/lib/gpr/commands/select.rb +17 -0
- data/lib/gpr/commands/status.rb +38 -0
- data/lib/gpr/commands/version.rb +17 -0
- data/lib/gpr/git_helper.rb +10 -14
- data/lib/gpr/main.rb +31 -0
- data/lib/gpr/version.rb +1 -1
- metadata +16 -5
- data/lib/gpr/api_helper.rb +0 -34
- data/lib/gpr/cli.rb +0 -235
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ccf15fbb208df9bd4a2ebc336f43d9ee47de666f
|
4
|
+
data.tar.gz: 7c2257355c1f466e54a15710dd73f218867a9cec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fee681930b621356143e8df951fa3355d2761505082bab2a93b3006cd15236f57b7140eb926138db08fa7ae49fa419fa9530476322e51f50de8632730f589f7d
|
7
|
+
data.tar.gz: d222565492c05cf9ede05b325da4cc246119e123c62ebf3b26277466bbacc2ac20e760520edcaedba6ac26b142d8c49021ae51cec40b4f621abfa0abdbfa8480
|
data/README.md
CHANGED
@@ -37,22 +37,6 @@ Just clone a git repository into `$HOME/.gpr/<host>/<user>/<repository>`.
|
|
37
37
|
$ gpr get <repository url>
|
38
38
|
```
|
39
39
|
|
40
|
-
This is alias of GitHub.
|
41
|
-
|
42
|
-
```sh
|
43
|
-
# e.g. gpr get kaihar4/gpr
|
44
|
-
$ gpr get <user>/<repository>
|
45
|
-
```
|
46
|
-
|
47
|
-
### Register all public repositories of the specified user
|
48
|
-
|
49
|
-
You can specify host only `github.com` or `bitbucket.org`.
|
50
|
-
|
51
|
-
```sh
|
52
|
-
# e.g. gpr get github.com/kaihar4
|
53
|
-
$ gpr get <host>/<user>
|
54
|
-
```
|
55
|
-
|
56
40
|
### Show all registered repositories
|
57
41
|
|
58
42
|
```sh
|
@@ -73,7 +57,7 @@ $ gpr select
|
|
73
57
|
|
74
58
|
Possible use as this.
|
75
59
|
|
76
|
-

|
77
61
|
|
78
62
|
Other benefits is [here](#convenient-aliases).
|
79
63
|
|
@@ -85,7 +69,7 @@ Display in graph format.
|
|
85
69
|
$ gpr contrib
|
86
70
|
```
|
87
71
|
|
88
|
-

|
89
73
|
|
90
74
|
### Show the status of all registered repositories
|
91
75
|
|
@@ -95,7 +79,7 @@ You can check the status of the registered repositories at a glance.
|
|
95
79
|
$ gpr status
|
96
80
|
```
|
97
81
|
|
98
|
-

|
99
83
|
|
100
84
|
### Search the specified keyword in registered repositories
|
101
85
|
|
@@ -113,13 +97,7 @@ Options:
|
|
113
97
|
Search the specified keyword in registered repositories
|
114
98
|
```
|
115
99
|
|
116
|
-

|
123
101
|
|
124
102
|
### Update the database to be used for search
|
125
103
|
|
data/bin/gpr
CHANGED
@@ -1,31 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require 'fileutils'
|
4
|
-
|
5
|
-
require 'groonga'
|
6
|
-
|
7
3
|
require 'gpr'
|
8
4
|
|
9
|
-
|
10
|
-
Groonga::Database.open("#{Gpr::DB_PATH}/gpr.db")
|
11
|
-
else
|
12
|
-
FileUtils.mkdir_p(Gpr::DB_PATH)
|
13
|
-
Groonga::Context.default_options = { encoding: :utf8 }
|
14
|
-
Groonga::Database.create(path: "#{Gpr::DB_PATH}/gpr.db")
|
15
|
-
Groonga::Schema.create_table('Files', type: :patricia_trie) do |t|
|
16
|
-
t.text('filename')
|
17
|
-
t.text('body')
|
18
|
-
t.text('host')
|
19
|
-
t.text('repository')
|
20
|
-
end
|
21
|
-
Groonga::Schema.create_table(
|
22
|
-
'Terms',
|
23
|
-
type: :patricia_trie,
|
24
|
-
normalizer: :NormalizerAuto,
|
25
|
-
default_tokenizer: 'TokenBigramSplitSymbolAlpha'
|
26
|
-
) do |t|
|
27
|
-
t.index('Files.body')
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
Gpr::CLI.start(ARGV)
|
5
|
+
Gpr::Main.start(ARGV)
|
data/lib/gpr.rb
CHANGED
data/lib/gpr/action.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
module Gpr
|
2
|
+
module Action
|
3
|
+
def parse_repository(repository_path)
|
4
|
+
repo_info = {}
|
5
|
+
parsed_path = repository_path.match(/#{::Gpr::APP_PATH}\/(?<host>[^\/]+)\/(?<repository>.+)/)
|
6
|
+
repo_info[:host] = parsed_path[:host]
|
7
|
+
repo_info[:repository] = parsed_path[:repository]
|
8
|
+
repo_info
|
9
|
+
end
|
10
|
+
|
11
|
+
def repository_list
|
12
|
+
repositories = Dir.glob("#{::Gpr::APP_PATH}/*/*/*").select do |directory|
|
13
|
+
FileTest.directory?(directory)
|
14
|
+
end
|
15
|
+
repositories.sort
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
require 'groonga'
|
4
|
+
|
5
|
+
require 'gpr/git_helper'
|
6
|
+
|
7
|
+
module Gpr
|
8
|
+
module Actions
|
9
|
+
module Search
|
10
|
+
DB_PATH = "#{::Gpr::APP_PATH}/.database"
|
11
|
+
|
12
|
+
def initialize_groonga
|
13
|
+
if FileTest.exist?("#{DB_PATH}/gpr.db")
|
14
|
+
Groonga::Database.open("#{DB_PATH}/gpr.db")
|
15
|
+
else
|
16
|
+
FileUtils.mkdir_p(DB_PATH)
|
17
|
+
Groonga::Context.default_options = { encoding: :utf8 }
|
18
|
+
Groonga::Database.create(path: "#{DB_PATH}/gpr.db")
|
19
|
+
Groonga::Schema.create_table('Files', type: :patricia_trie) do |t|
|
20
|
+
t.text('filename')
|
21
|
+
t.text('body')
|
22
|
+
t.text('host')
|
23
|
+
t.text('repository')
|
24
|
+
end
|
25
|
+
Groonga::Schema.create_table(
|
26
|
+
'Terms',
|
27
|
+
type: :patricia_trie,
|
28
|
+
normalizer: :NormalizerAuto,
|
29
|
+
default_tokenizer: 'TokenBigramSplitSymbolAlpha'
|
30
|
+
) do |t|
|
31
|
+
t.index('Files.body')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def add_file(path)
|
37
|
+
repo_info = parse_repository(path)
|
38
|
+
|
39
|
+
GitHelper.ls_files(path).each do |file|
|
40
|
+
next unless FileTest.file?(file)
|
41
|
+
Groonga['Files'].add(
|
42
|
+
File.expand_path(file),
|
43
|
+
filename: File.basename(file),
|
44
|
+
body: File.open(file).read,
|
45
|
+
host: repo_info[:host],
|
46
|
+
repository: repo_info[:repository]
|
47
|
+
)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'utils_drawer'
|
2
|
+
|
3
|
+
require 'gpr/git_helper'
|
4
|
+
require 'gpr/actions/contrib'
|
5
|
+
|
6
|
+
module Gpr
|
7
|
+
module Commands
|
8
|
+
class Contrib < Base
|
9
|
+
def initialize(thor)
|
10
|
+
thor.class_eval do
|
11
|
+
include UtilsDrawer
|
12
|
+
include ::Gpr::Actions::Contrib
|
13
|
+
|
14
|
+
desc 'contrib', 'Show your contributions of registered repositories'
|
15
|
+
def contrib(path = nil)
|
16
|
+
user = detect_git_user || ENV['USER']
|
17
|
+
|
18
|
+
if path.nil?
|
19
|
+
repositories = repository_list
|
20
|
+
dates = repositories.each_with_object([]) { |repository, ary|
|
21
|
+
ary << GitHelper.log_by_date(repository, user)
|
22
|
+
}.flatten!
|
23
|
+
else
|
24
|
+
dates = GitHelper.log_by_date(path, user)
|
25
|
+
end
|
26
|
+
|
27
|
+
first_date = Time.parse(dates.sort.first)
|
28
|
+
diff = ((Time.now - first_date).to_i / 86400) + 1
|
29
|
+
|
30
|
+
# Initialize a hash
|
31
|
+
commit_counts = diff.times.each_with_object({}) do |index, hash|
|
32
|
+
date = Time.at(first_date + (86400 * index)).strftime('%Y-%m-%d')
|
33
|
+
hash[date] = 0
|
34
|
+
end
|
35
|
+
|
36
|
+
# Count commits
|
37
|
+
dates.each do |date|
|
38
|
+
commit_counts[date] += 1 if commit_counts[date]
|
39
|
+
end
|
40
|
+
|
41
|
+
graph do
|
42
|
+
commit_counts.sort.each do |date, value|
|
43
|
+
data(date, value)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'safe_colorize'
|
2
|
+
|
3
|
+
require 'gpr/git_helper'
|
4
|
+
|
5
|
+
module Gpr
|
6
|
+
module Commands
|
7
|
+
class Fetch < Base
|
8
|
+
using SafeColorize
|
9
|
+
|
10
|
+
def initialize(thor)
|
11
|
+
thor.class_eval do
|
12
|
+
desc 'fetch', 'Fetch the registered repositories'
|
13
|
+
def fetch(remote = 'origin', branch = nil, path = nil)
|
14
|
+
if path.nil?
|
15
|
+
repositories = repository_list
|
16
|
+
repositories.each do |repository|
|
17
|
+
repo_info = parse_repository(repository)
|
18
|
+
|
19
|
+
puts "#{repo_info[:host].color(:yellow)} - #{repo_info[:repository].color(:blue)}"
|
20
|
+
|
21
|
+
GitHelper.fetch(repository, remote, branch)
|
22
|
+
end
|
23
|
+
else
|
24
|
+
repo_info = parse_repository(path)
|
25
|
+
|
26
|
+
puts "#{repo_info[:host].color(:yellow)} - #{repo_info[:repository].color(:blue)}"
|
27
|
+
|
28
|
+
GitHelper.fetch(path, remote, branch)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'safe_colorize'
|
2
|
+
|
3
|
+
module Gpr
|
4
|
+
module Commands
|
5
|
+
class Get < Base
|
6
|
+
using SafeColorize
|
7
|
+
|
8
|
+
def initialize(thor)
|
9
|
+
thor.class_eval do
|
10
|
+
desc 'get', 'Get a repository'
|
11
|
+
def get(param)
|
12
|
+
host, user, repository =
|
13
|
+
param.match(/.+(\/\/|@)(.+)\.git$/)[2].split(/(:|\/)/).delete_if.with_index { |_c, index| index.odd? }
|
14
|
+
path = "#{::Gpr::APP_PATH}/#{host}/#{user}/#{repository}"
|
15
|
+
|
16
|
+
if Dir.exist?(path)
|
17
|
+
puts "#{'Warning'.color(:red).style(:underscore)}: #{user}/#{repository} already registered"
|
18
|
+
return
|
19
|
+
end
|
20
|
+
|
21
|
+
`git clone #{param} #{path}`
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'safe_colorize'
|
2
|
+
|
3
|
+
module Gpr
|
4
|
+
module Commands
|
5
|
+
class List < Base
|
6
|
+
using SafeColorize
|
7
|
+
|
8
|
+
def initialize(thor)
|
9
|
+
thor.class_eval do
|
10
|
+
desc 'list', 'Show all registered repositories'
|
11
|
+
option :paths, type: :boolean, desc: 'Show the paths of all registered repositories'
|
12
|
+
def list
|
13
|
+
repositories = repository_list
|
14
|
+
if options[:paths]
|
15
|
+
repositories.each do |repository|
|
16
|
+
puts repository
|
17
|
+
end
|
18
|
+
else
|
19
|
+
repositories.each do |repository|
|
20
|
+
repo_info = parse_repository(repository)
|
21
|
+
|
22
|
+
puts "#{repo_info[:host].color(:yellow)} - #{repo_info[:repository].color(:blue)}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'groonga'
|
2
|
+
require 'safe_colorize'
|
3
|
+
|
4
|
+
require 'gpr/actions/search'
|
5
|
+
|
6
|
+
module Gpr
|
7
|
+
module Commands
|
8
|
+
class Search < Base
|
9
|
+
using SafeColorize
|
10
|
+
include ::Gpr::Actions::Search
|
11
|
+
|
12
|
+
def initialize(thor)
|
13
|
+
initialize_groonga
|
14
|
+
|
15
|
+
thor.class_eval do
|
16
|
+
include ::Gpr::Actions::Search
|
17
|
+
|
18
|
+
desc 'search', 'Search the specified keyword in registered repositories'
|
19
|
+
option :file, type: :string, aliases: '-f', desc: 'Filter by filename'
|
20
|
+
option :host, type: :string, aliases: '-h', desc: 'Filter by host'
|
21
|
+
option :repository, type: :string, aliases: '-r', desc: 'Filter by repository'
|
22
|
+
def search(string)
|
23
|
+
result = Groonga['Files'].select do |record|
|
24
|
+
record.body =~ string
|
25
|
+
end
|
26
|
+
|
27
|
+
result.each do |record|
|
28
|
+
next unless FileTest.exist?(record._key)
|
29
|
+
|
30
|
+
next if options[:file] && !(record.filename =~ /#{options[:file]}/)
|
31
|
+
next if options[:host] && !(record.host == options[:host])
|
32
|
+
next if options[:repository] && !(record.repository == options[:repository])
|
33
|
+
|
34
|
+
relative_path = record._key.sub(/#{::Gpr::APP_PATH}\/#{record.host}\/#{record.repository}\//, '')
|
35
|
+
puts "#{record.host.color(:yellow)} - #{record.repository.color(:blue)} : #{relative_path.color(:red)}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
desc 'update', 'Update the database to be used for search'
|
40
|
+
def update
|
41
|
+
puts 'Updating...'
|
42
|
+
|
43
|
+
Groonga['Files'].truncate
|
44
|
+
|
45
|
+
# Remove unregistered directories
|
46
|
+
Dir.glob("#{::Gpr::APP_PATH}/*/*").each do |path|
|
47
|
+
# Unregistered directories returns [".", ".."].
|
48
|
+
Dir.rmdir(path) if Dir.entries(path).size == 2
|
49
|
+
end
|
50
|
+
|
51
|
+
repositories = repository_list
|
52
|
+
repositories.each do |repository|
|
53
|
+
add_file(repository)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'ifilter'
|
2
|
+
|
3
|
+
module Gpr
|
4
|
+
module Commands
|
5
|
+
class Select < Base
|
6
|
+
def initialize(thor)
|
7
|
+
thor.class_eval do
|
8
|
+
desc 'select', 'Select a repository using the interactive interface'
|
9
|
+
def select
|
10
|
+
repositories = repository_list
|
11
|
+
puts Ifilter.filtering(repositories)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'utils_drawer'
|
2
|
+
require 'safe_colorize'
|
3
|
+
|
4
|
+
require 'gpr/git_helper'
|
5
|
+
|
6
|
+
module Gpr
|
7
|
+
module Commands
|
8
|
+
class Status < Base
|
9
|
+
using SafeColorize
|
10
|
+
|
11
|
+
def initialize(thor)
|
12
|
+
thor.class_eval do
|
13
|
+
include UtilsDrawer
|
14
|
+
|
15
|
+
desc 'status', 'Show the status of all registered repositories'
|
16
|
+
def status
|
17
|
+
repositories = repository_list
|
18
|
+
table do
|
19
|
+
row do
|
20
|
+
column('REPOSITORY NAME'.style(:bold), 25)
|
21
|
+
column('BRANCH STATUS'.style(:bold), 45)
|
22
|
+
column('DIRECTORY STATUS'.style(:bold), 25)
|
23
|
+
end
|
24
|
+
repositories.each do |repository|
|
25
|
+
status = GitHelper.status(repository)
|
26
|
+
row do
|
27
|
+
column(repository.match(/.+\/(?<repository>.+\/.+)/)[:repository])
|
28
|
+
column(status[:branch])
|
29
|
+
column(status[:directory])
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'gpr/version'
|
2
|
+
|
3
|
+
module Gpr
|
4
|
+
module Commands
|
5
|
+
class Version < Base
|
6
|
+
def initialize(thor)
|
7
|
+
thor.class_eval do
|
8
|
+
desc 'version', 'Display installed gpr version'
|
9
|
+
map '-v' => :version
|
10
|
+
def version
|
11
|
+
puts "gpr #{::Gpr::VERSION}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/gpr/git_helper.rb
CHANGED
@@ -5,29 +5,16 @@ module Gpr
|
|
5
5
|
using SafeColorize
|
6
6
|
|
7
7
|
class << self
|
8
|
-
def clone(url, path)
|
9
|
-
`git clone #{url} #{path}`
|
10
|
-
end
|
11
|
-
|
12
8
|
def ls_files(path)
|
13
9
|
Dir.chdir(path)
|
14
10
|
`git ls-files`.split("\n")
|
15
11
|
end
|
16
12
|
|
17
|
-
def fetch(path, remote, branch)
|
18
|
-
Dir.chdir(path)
|
19
|
-
if branch.nil?
|
20
|
-
`git fetch #{remote}`
|
21
|
-
else
|
22
|
-
`git fetch #{remote} #{branch}`
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
13
|
def status(path)
|
27
14
|
Dir.chdir(path)
|
28
15
|
result = {}
|
29
16
|
git_status = `git status -sb`.split("\n")
|
30
|
-
branch_name = git_status.shift.match(/## (
|
17
|
+
branch_name = git_status.shift.match(/## (?<branch>.+)/)[:branch]
|
31
18
|
unstaged_changes = []
|
32
19
|
untracked_files = []
|
33
20
|
|
@@ -63,6 +50,15 @@ module Gpr
|
|
63
50
|
`git log --author=#{user} --date=short --pretty=format:"%cd"`.split("\n")
|
64
51
|
end
|
65
52
|
end
|
53
|
+
|
54
|
+
def fetch(path, remote, branch)
|
55
|
+
Dir.chdir(path)
|
56
|
+
if branch.nil?
|
57
|
+
`git fetch #{remote}`
|
58
|
+
else
|
59
|
+
`git fetch #{remote} #{branch}`
|
60
|
+
end
|
61
|
+
end
|
66
62
|
end
|
67
63
|
end
|
68
64
|
end
|
data/lib/gpr/main.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
require 'gpr/action'
|
4
|
+
require 'gpr/commands/base'
|
5
|
+
require 'gpr/commands/get'
|
6
|
+
require 'gpr/commands/list'
|
7
|
+
require 'gpr/commands/select'
|
8
|
+
require 'gpr/commands/search'
|
9
|
+
require 'gpr/commands/status'
|
10
|
+
require 'gpr/commands/contrib'
|
11
|
+
require 'gpr/commands/fetch'
|
12
|
+
require 'gpr/commands/version'
|
13
|
+
|
14
|
+
Bundler.require
|
15
|
+
|
16
|
+
module Gpr
|
17
|
+
class Main < Thor
|
18
|
+
include ::Gpr
|
19
|
+
include Action
|
20
|
+
|
21
|
+
def self.start(args)
|
22
|
+
self.load_commands
|
23
|
+
|
24
|
+
super(args)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.load_commands
|
28
|
+
@@commands.map { |command| command.new(self) }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/gpr/version.rb
CHANGED
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kaihar4
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -124,9 +124,20 @@ files:
|
|
124
124
|
- bin/gpr
|
125
125
|
- gpr.gemspec
|
126
126
|
- lib/gpr.rb
|
127
|
-
- lib/gpr/
|
128
|
-
- lib/gpr/
|
127
|
+
- lib/gpr/action.rb
|
128
|
+
- lib/gpr/actions/contrib.rb
|
129
|
+
- lib/gpr/actions/search.rb
|
130
|
+
- lib/gpr/commands/base.rb
|
131
|
+
- lib/gpr/commands/contrib.rb
|
132
|
+
- lib/gpr/commands/fetch.rb
|
133
|
+
- lib/gpr/commands/get.rb
|
134
|
+
- lib/gpr/commands/list.rb
|
135
|
+
- lib/gpr/commands/search.rb
|
136
|
+
- lib/gpr/commands/select.rb
|
137
|
+
- lib/gpr/commands/status.rb
|
138
|
+
- lib/gpr/commands/version.rb
|
129
139
|
- lib/gpr/git_helper.rb
|
140
|
+
- lib/gpr/main.rb
|
130
141
|
- lib/gpr/version.rb
|
131
142
|
- zsh/gpr.zsh
|
132
143
|
homepage: https://github.com/kaihar4/gpr
|
@@ -149,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
160
|
version: '0'
|
150
161
|
requirements: []
|
151
162
|
rubyforge_project:
|
152
|
-
rubygems_version: 2.
|
163
|
+
rubygems_version: 2.4.5
|
153
164
|
signing_key:
|
154
165
|
specification_version: 4
|
155
166
|
summary: Gitkeeper.
|
data/lib/gpr/api_helper.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
require 'net/https'
|
3
|
-
|
4
|
-
module Gpr
|
5
|
-
module APIHelper
|
6
|
-
class << self
|
7
|
-
def get_repository_urls(host, user)
|
8
|
-
case host
|
9
|
-
when 'github.com'
|
10
|
-
uri = URI.parse("https://api.github.com/users/#{user}/repos?per_page=100")
|
11
|
-
JSON.parse(request_https_get(uri).body).map do |repository|
|
12
|
-
repository['clone_url']
|
13
|
-
end
|
14
|
-
|
15
|
-
when 'bitbucket.org'
|
16
|
-
uri = URI.parse("https://api.bitbucket.org/1.0/users/#{user}")
|
17
|
-
JSON.parse(request_https_get(uri).body)['repositories'].map do |repository|
|
18
|
-
"https://#{repository['owner']}@bitbucket.org/#{repository['owner']}/#{repository['name']}.git"
|
19
|
-
end
|
20
|
-
|
21
|
-
else
|
22
|
-
puts "#{host} is not supported"
|
23
|
-
exit 0
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def request_https_get(uri)
|
28
|
-
https = Net::HTTP.new(uri.host, uri.port)
|
29
|
-
https.use_ssl = true
|
30
|
-
https.get(uri.request_uri)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
data/lib/gpr/cli.rb
DELETED
@@ -1,235 +0,0 @@
|
|
1
|
-
require 'thor'
|
2
|
-
require 'groonga'
|
3
|
-
require 'safe_colorize'
|
4
|
-
require 'ifilter'
|
5
|
-
require 'utils_drawer'
|
6
|
-
|
7
|
-
module Gpr
|
8
|
-
class CLI < Thor
|
9
|
-
using SafeColorize
|
10
|
-
include UtilsDrawer
|
11
|
-
|
12
|
-
desc 'get', 'Get a repository'
|
13
|
-
def get(param)
|
14
|
-
case param
|
15
|
-
when /.+(\/\/|@)(.+)\.git$/
|
16
|
-
host, user, repository =
|
17
|
-
param.match(/.+(\/\/|@)(.+)\.git$/)[2].split(/(:|\/)/).delete_if.with_index { |_c, index| index.odd? }
|
18
|
-
path = "#{APP_PATH}/#{host}/#{user}/#{repository}"
|
19
|
-
|
20
|
-
if Dir.exist?(path)
|
21
|
-
puts "#{user}/#{repository} is already registered."
|
22
|
-
return
|
23
|
-
end
|
24
|
-
|
25
|
-
GitHelper.clone(param, path)
|
26
|
-
add_file(path)
|
27
|
-
|
28
|
-
when /^([^\/]+)\/([^\/]+)$/
|
29
|
-
parsed_param = param.match(/^([^\/]+)\/([^\/]+)$/)
|
30
|
-
|
31
|
-
# <host>/<user>
|
32
|
-
if parsed_param[1].include?('.')
|
33
|
-
host = parsed_param[1]
|
34
|
-
user = parsed_param[2]
|
35
|
-
|
36
|
-
APIHelper.get_repository_urls(host, user).each do |clone_url|
|
37
|
-
get(clone_url)
|
38
|
-
end
|
39
|
-
|
40
|
-
# <user>/<repository>
|
41
|
-
else
|
42
|
-
user = parsed_param[1]
|
43
|
-
repository = parsed_param[2]
|
44
|
-
|
45
|
-
clone_url = "https://github.com/#{user}/#{repository}.git"
|
46
|
-
get(clone_url)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
desc 'list', 'Show all registered repositories'
|
52
|
-
option :paths, type: :boolean, desc: 'Show the paths of all registered repositories'
|
53
|
-
def list
|
54
|
-
repositories = get_repositories
|
55
|
-
if options[:paths]
|
56
|
-
repositories.each do |repository|
|
57
|
-
puts repository
|
58
|
-
end
|
59
|
-
|
60
|
-
else
|
61
|
-
repositories.each do |repository|
|
62
|
-
repo_info = parse_repository(repository)
|
63
|
-
|
64
|
-
puts "#{repo_info[:host].color(:yellow)} - #{repo_info[:repository].color(:blue)}"
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
desc 'select', 'Select a repository using the interactive interface'
|
70
|
-
def select
|
71
|
-
repositories = get_repositories
|
72
|
-
puts Ifilter.filtering(repositories)
|
73
|
-
end
|
74
|
-
|
75
|
-
desc 'contrib', 'Show your contributions of registered repositories'
|
76
|
-
def contrib(path = nil)
|
77
|
-
git_user = File.open("#{ENV['HOME']}/.gitconfig", 'r') do |f|
|
78
|
-
body = f.read
|
79
|
-
body.match(/name\s+=\s+(.+)/)[1]
|
80
|
-
end
|
81
|
-
user = git_user || ENV['USER']
|
82
|
-
|
83
|
-
if path.nil?
|
84
|
-
repositories = get_repositories
|
85
|
-
dates = repositories.each_with_object([]) do |repository, ary|
|
86
|
-
ary.concat(GitHelper.log_by_date(repository, user))
|
87
|
-
end
|
88
|
-
|
89
|
-
else
|
90
|
-
dates = GitHelper.log_by_date(path, user)
|
91
|
-
end
|
92
|
-
|
93
|
-
first_date = Time.parse(dates.sort.first)
|
94
|
-
diff = ((Time.now - first_date).to_i / 86400) + 1
|
95
|
-
|
96
|
-
# Initialize a hash
|
97
|
-
commit_counts = diff.times.each_with_object({}) do |index, hash|
|
98
|
-
date = Time.at(first_date + (86400 * index)).strftime('%Y-%m-%d')
|
99
|
-
hash[date] = 0
|
100
|
-
end
|
101
|
-
|
102
|
-
# Count commits
|
103
|
-
dates.each do |date|
|
104
|
-
commit_counts[date] += 1 if commit_counts[date]
|
105
|
-
end
|
106
|
-
|
107
|
-
graph do
|
108
|
-
commit_counts.sort.each do |date, value|
|
109
|
-
data(date, value)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
desc 'search', 'Search the specified keyword in registered repositories'
|
115
|
-
option :file, type: :string, aliases: '-f', desc: 'Filter by filename'
|
116
|
-
option :host, type: :string, aliases: '-h', desc: 'Filter by host'
|
117
|
-
option :repository, type: :string, aliases: '-r', desc: 'Filter by repository'
|
118
|
-
def search(string)
|
119
|
-
result = Groonga['Files'].select do |record|
|
120
|
-
record.body =~ string
|
121
|
-
end
|
122
|
-
|
123
|
-
result.each do |record|
|
124
|
-
next unless FileTest.exist?(record._key)
|
125
|
-
|
126
|
-
next unless /#{options[:file]}/ =~ record.filename if options[:file]
|
127
|
-
next unless options[:host] == record.host if options[:host]
|
128
|
-
next unless options[:repository] == record.repository if options[:repository]
|
129
|
-
|
130
|
-
relative_path = record._key.sub(/#{APP_PATH}\/#{record.host}\/#{record.repository}\//, '')
|
131
|
-
puts "#{record.host.color(:yellow)} - #{record.repository.color(:blue)} : #{relative_path.color(:red)}"
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
desc 'clean', 'Remove the unregistered directories'
|
136
|
-
def clean
|
137
|
-
puts 'Processing...'
|
138
|
-
|
139
|
-
Dir.glob("#{APP_PATH}/*/*").each do |path|
|
140
|
-
# Unregistered directories returns [".", ".."].
|
141
|
-
Dir.rmdir(path) if Dir.entries(path).size == 2
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
desc 'update', 'Update the database to be used for search'
|
146
|
-
def update
|
147
|
-
puts 'Updating...'
|
148
|
-
|
149
|
-
Groonga['Files'].truncate
|
150
|
-
|
151
|
-
repositories = get_repositories
|
152
|
-
repositories.each do |repository|
|
153
|
-
add_file(repository)
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
desc 'fetch', 'Fetch the registered repositories'
|
158
|
-
def fetch(remote = 'origin', branch = nil, path = nil)
|
159
|
-
if path.nil?
|
160
|
-
repositories = get_repositories
|
161
|
-
repositories.each do |repository|
|
162
|
-
repo_info = parse_repository(repository)
|
163
|
-
|
164
|
-
puts "#{repo_info[:host].color(:yellow)} - #{repo_info[:repository].color(:blue)}"
|
165
|
-
|
166
|
-
GitHelper.fetch(repository, remote, branch)
|
167
|
-
end
|
168
|
-
else
|
169
|
-
repo_info = parse_repository(path)
|
170
|
-
|
171
|
-
puts "#{repo_info[:host].color(:yellow)} - #{repo_info[:repository].color(:blue)}"
|
172
|
-
|
173
|
-
GitHelper.fetch(path, remote, branch)
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
desc 'status', 'Show the status of all registered repositories'
|
178
|
-
def status
|
179
|
-
repositories = get_repositories
|
180
|
-
table do
|
181
|
-
row do
|
182
|
-
column('REPOSITORY NAME'.style(:bold), 25)
|
183
|
-
column('BRANCH STATUS'.style(:bold), 45)
|
184
|
-
column('DIRECTORY STATUS'.style(:bold), 25)
|
185
|
-
end
|
186
|
-
repositories.each do |repository|
|
187
|
-
status = GitHelper.status(repository)
|
188
|
-
row do
|
189
|
-
column(repository.match(/.+\/(.+\/.+)/)[1])
|
190
|
-
column(status[:branch])
|
191
|
-
column(status[:directory])
|
192
|
-
end
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
desc 'version', 'Display installed gpr version'
|
198
|
-
map '-v' => :version
|
199
|
-
def version
|
200
|
-
puts "gpr #{Gpr::VERSION}"
|
201
|
-
end
|
202
|
-
|
203
|
-
private
|
204
|
-
|
205
|
-
def parse_repository(repository_path)
|
206
|
-
repo_info = {}
|
207
|
-
parsed_path = repository_path.match(/#{APP_PATH}\/([^\/]+)\/(.+)/)
|
208
|
-
repo_info[:host] = parsed_path[1]
|
209
|
-
repo_info[:repository] = parsed_path[2]
|
210
|
-
repo_info
|
211
|
-
end
|
212
|
-
|
213
|
-
def get_repositories
|
214
|
-
repositories = Dir.glob("#{APP_PATH}/*/*/*").select do |directory|
|
215
|
-
FileTest.directory?(directory)
|
216
|
-
end
|
217
|
-
repositories.sort
|
218
|
-
end
|
219
|
-
|
220
|
-
def add_file(path)
|
221
|
-
repo_info = parse_repository(path)
|
222
|
-
|
223
|
-
GitHelper.ls_files(path).each do |file|
|
224
|
-
next unless FileTest.file?(file)
|
225
|
-
Groonga['Files'].add(
|
226
|
-
File.expand_path(file),
|
227
|
-
filename: File.basename(file),
|
228
|
-
body: File.open(file).read,
|
229
|
-
host: repo_info[:host],
|
230
|
-
repository: repo_info[:repository]
|
231
|
-
)
|
232
|
-
end
|
233
|
-
end
|
234
|
-
end
|
235
|
-
end
|