gpr 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 416f71fde2acd96aa5793a4727bc98684fe57074
4
+ data.tar.gz: 0c4c0d3ea7b6e2c7ae98513d59228d90fe46c87d
5
+ SHA512:
6
+ metadata.gz: 30fadcd8ca2162d53eddd98b4ba60934e88b4f8ce4f4e835e469d40c4420eeca6d241bfcebad1c66d1a67019d4325975ffab229c70044382d6b9b7a258adb62f
7
+ data.tar.gz: b430d3e905d80dcefd4c0711a64a03c22af9bed46af57809b87f2b7d15705f404077cf639f5789e69e5696d4f894796c64da68d71fb700513549cc33bd08aa3a
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gpr.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 kaihar4
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,76 @@
1
+ # Gpr
2
+
3
+ Gitkeeper.
4
+
5
+ ## Description
6
+
7
+ Gpr provides a simple management of the git repository.
8
+
9
+ Behave like a `go get` of Golang.
10
+
11
+ For example, all repositories are cloned to `$HOME/.gpr/<host>/<user>/<repository>`.
12
+
13
+ It is possible to centrally manage of the all repositories.
14
+
15
+ ## Installation
16
+
17
+ ```sh
18
+ $ gem install gpr
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ ```sh
24
+ $ gpr help
25
+ ```
26
+
27
+ ### Clone a git repository into Gpr directory
28
+
29
+ Just clone a git repository into `$HOME/.gpr/<host>/<user>/<repository>`.
30
+
31
+ ```sh
32
+ $ gpr get <repository url>
33
+ ```
34
+
35
+ ### Clone all public repositories of the specified user
36
+
37
+ You can specify host only `github.com` or `bitbucket.org`.
38
+
39
+ ```sh
40
+ $ gpr get <host>/<user>
41
+ ```
42
+
43
+ ### Show all registered repositories
44
+
45
+ ```sh
46
+ $ gpr list
47
+ ```
48
+
49
+ ### Search the specified keyword in registered repositories
50
+
51
+ Show a list of the files that the specified keyword is included.
52
+
53
+ ```
54
+ Usage:
55
+ gpr search
56
+
57
+ Options:
58
+ -f, [--file=FILE] # Filter by filename
59
+ -h, [--host=HOST] # Filter by host
60
+ -r, [--repository=REPOSITORY] # Filter by repository
61
+
62
+ Search the specified keyword in registered repositories
63
+ ```
64
+
65
+ ```sh
66
+ $ gpr search <keyword>
67
+ ```
68
+
69
+ ## Install the zsh completion
70
+
71
+ ```sh
72
+ $ gpr get https://github.com/kaihar4/gpr.git
73
+ $ cd $HOME/.gpr/github.com/kaihar4/gpr
74
+ $ rake zsh:install
75
+ $ source ~/.zshrc
76
+ ```
@@ -0,0 +1,17 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ namespace :zsh do
4
+ desc 'Install the zsh completion'
5
+ task :install do
6
+ if ENV['SHELL'].include?('zsh')
7
+ File.open("#{ENV['HOME']}/.zshrc", 'a+') do |file|
8
+ path = "source #{Dir.pwd}/zsh/gpr.zsh"
9
+
10
+ file.puts path unless file.read.include?(path)
11
+ end
12
+ puts 'Done.'
13
+ else
14
+ puts 'Please change default shell to zsh.'
15
+ end
16
+ end
17
+ end
data/bin/gpr ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'gpr'
4
+
5
+ begin
6
+ Groonga::Database.open("#{Gpr::DB_PATH}/gpr.db")
7
+ rescue Groonga::NoSuchFileOrDirectory
8
+ FileUtils.mkdir_p(Gpr::DB_PATH)
9
+ Groonga::Context.default_options = { encoding: :utf8 }
10
+ Groonga::Database.create(path: "#{Gpr::DB_PATH}/gpr.db")
11
+ Groonga::Schema.create_table('Files', type: :patricia_trie) do |t|
12
+ t.text('filename')
13
+ t.text('body')
14
+ t.text('host')
15
+ t.text('repository')
16
+ end
17
+ Groonga::Schema.create_table(
18
+ 'Terms',
19
+ type: :patricia_trie,
20
+ normalizer: :NormalizerAuto,
21
+ default_tokenizer: 'TokenBigramSplitSymbolAlpha'
22
+ ) do |t|
23
+ t.index('Files.body')
24
+ end
25
+ end
26
+
27
+ Gpr::CLI.start(ARGV)
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gpr/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'gpr'
8
+ spec.version = Gpr::VERSION
9
+ spec.authors = ['kaihar4']
10
+ spec.email = ['kaihar4@gmail.com']
11
+ spec.summary = 'Simple management of the git repository.'
12
+ spec.description = 'Simple management of the git repository.'
13
+ spec.homepage = 'https://github.com/kaihar4/gpr'
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_dependency 'thor'
22
+ spec.add_dependency 'rroonga'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.6'
25
+ spec.add_development_dependency 'rake'
26
+ spec.add_development_dependency 'pry'
27
+ spec.add_development_dependency 'awesome_print'
28
+ end
@@ -0,0 +1,39 @@
1
+ class String
2
+ COLORS = {
3
+ black: 0,
4
+ red: 1,
5
+ green: 2,
6
+ yellow: 3,
7
+ blue: 4,
8
+ magenta: 5,
9
+ cyan: 6,
10
+ white: 7
11
+ }
12
+
13
+ STYLES = {
14
+ reset: 0,
15
+ bold: 1,
16
+ underscore: 4,
17
+ blink: 5,
18
+ reverse: 6,
19
+ concealed: 7
20
+ }
21
+
22
+ def color(color)
23
+ to_ansi("3#{COLORS[color]}")
24
+ end
25
+
26
+ def bg_color(color)
27
+ to_ansi("4#{COLORS[color]}")
28
+ end
29
+
30
+ def style(style)
31
+ to_ansi(STYLES[style])
32
+ end
33
+
34
+ protected
35
+
36
+ def to_ansi(code)
37
+ "\e[#{code.to_i}m#{self}\e[0m"
38
+ end
39
+ end
@@ -0,0 +1,17 @@
1
+ require 'fileutils'
2
+ require 'net/https'
3
+ require 'json'
4
+ require 'find'
5
+
6
+ require 'thor'
7
+ require 'groonga'
8
+
9
+ require 'extends/colorize'
10
+ require 'gpr/version'
11
+ require 'gpr/api_helper'
12
+ require 'gpr/cli'
13
+
14
+ module Gpr
15
+ APP_PATH = "#{ENV['HOME']}/.gpr"
16
+ DB_PATH = "#{APP_PATH}/.database"
17
+ end
@@ -0,0 +1,31 @@
1
+ module Gpr
2
+ module APIHelper
3
+ class << self
4
+ def get_repository_urls(host, user)
5
+ case host
6
+ when 'github.com'
7
+ uri = URI.parse("https://api.github.com/users/#{user}/repos?per_page=100")
8
+ JSON.parse(request_https_get(uri).body).map do |repository|
9
+ repository['clone_url']
10
+ end
11
+
12
+ when 'bitbucket.org'
13
+ uri = URI.parse("https://api.bitbucket.org/1.0/users/#{user}")
14
+ JSON.parse(request_https_get(uri).body)['repositories'].map do |repository|
15
+ "https://#{repository['owner']}@bitbucket.org/#{repository['owner']}/#{repository['name']}.git"
16
+ end
17
+
18
+ else
19
+ puts "#{host} is not supported"
20
+ exit 0
21
+ end
22
+ end
23
+
24
+ def request_https_get(uri)
25
+ https = Net::HTTP.new(uri.host, uri.port)
26
+ https.use_ssl = true
27
+ https.get(uri.request_uri)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,118 @@
1
+ module Gpr
2
+ class CLI < Thor
3
+ desc 'get', 'Get a repository'
4
+ def get(param)
5
+ case param
6
+ when /.+(\/\/|@)(.+)\.git$/
7
+ host, user, repository =
8
+ param.match(/.+(\/\/|@)(.+)\.git$/)[2].split(/(:|\/)/).delete_if.with_index { |_c, index| index.odd? }
9
+
10
+ if Dir.exist?("#{APP_PATH}/#{host}/#{user}/#{repository}")
11
+ puts "#{user}/#{repository} is already registered."
12
+ return
13
+ end
14
+
15
+ puts "#{user}/#{repository} is registering..."
16
+ unless system("git clone #{param} #{APP_PATH}/#{host}/#{user}/#{repository} >/dev/null 2>&1")
17
+ puts "Failed to clone #{user}/#{repository}."
18
+ return
19
+ end
20
+ add_file("#{APP_PATH}/#{host}/#{user}/#{repository}")
21
+
22
+ when /^([^\/]+)\/([^\/]+)$/
23
+ parsed_param = param.match(/^([^\/]+)\/([^\/]+)$/)
24
+ host = parsed_param[1]
25
+ user = parsed_param[2]
26
+
27
+ clone_urls = APIHelper.get_repository_urls(host, user)
28
+ clone_urls.each do |clone_url|
29
+ get(clone_url)
30
+ end
31
+ end
32
+ end
33
+
34
+ desc 'list', 'Show all registered repositories'
35
+ option :paths, type: :boolean, desc: 'Show the paths of all registered repositories'
36
+ def list
37
+ repositories = get_repositories
38
+ if options[:paths]
39
+ repositories.each do |repository|
40
+ puts repository
41
+ end
42
+
43
+ else
44
+ repositories.each do |repository|
45
+ parsed_path = repository.match(/#{APP_PATH}\/([^\/]+)\/(.+)/)
46
+ host = parsed_path[1]
47
+ repository = parsed_path[2]
48
+
49
+ puts "#{host.color(:yellow)} - #{repository.color(:blue)}"
50
+ end
51
+ end
52
+ end
53
+
54
+ desc 'search', 'Search the specified keyword in registered repositories'
55
+ option :file, type: :string, aliases: '-f', desc: 'Filter by filename'
56
+ option :host, type: :string, aliases: '-h', desc: 'Filter by host'
57
+ option :repository, type: :string, aliases: '-r', desc: 'Filter by repository'
58
+ def search(string)
59
+ result = Groonga['Files'].select do |record|
60
+ record.body =~ string
61
+ end
62
+
63
+ result.each do |record|
64
+ next unless FileTest.exist?(record._key)
65
+
66
+ next unless /#{options[:file]}/ =~ record.filename if options[:file]
67
+ next unless options[:host] == record.host if options[:host]
68
+ next unless options[:repository] == record.repository if options[:repository]
69
+
70
+ relative_path = record._key.sub(/#{APP_PATH}\/#{record.host}\/#{record.repository}\//, '')
71
+ puts "#{record.host.color(:yellow)} - #{record.repository.color(:blue)} : #{relative_path.color(:red)}"
72
+ end
73
+ end
74
+
75
+ desc 'update', 'Update the database to be used for search'
76
+ def update
77
+ puts 'Updating...'
78
+
79
+ Groonga['Files'].truncate
80
+
81
+ repositories = get_repositories
82
+ repositories.each do |repository|
83
+ add_file(repository)
84
+ end
85
+ end
86
+
87
+ desc 'version', 'Display installed gpr version'
88
+ map '-v' => :version
89
+ def version
90
+ puts "gpr #{Gpr::VERSION}"
91
+ end
92
+
93
+ private
94
+
95
+ def get_repositories
96
+ repositories = Dir.glob("#{APP_PATH}/*/*/*").select do |directory|
97
+ FileTest.directory?(directory)
98
+ end
99
+ repositories.sort
100
+ end
101
+
102
+ def add_file(path)
103
+ parsed_path = path.match(/#{APP_PATH}\/([^\/]+)\/(.+)/)
104
+
105
+ Dir.chdir(path)
106
+ `git ls-files`.split("\n").each do |file|
107
+ next unless FileTest.file?(file)
108
+ Groonga['Files'].add(
109
+ File.expand_path(file),
110
+ filename: File.basename(file),
111
+ body: File.open(file).read,
112
+ host: parsed_path[1],
113
+ repository: parsed_path[2]
114
+ )
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,3 @@
1
+ module Gpr
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,55 @@
1
+ function _gpr () {
2
+ local context curcontext=$curcontext state line
3
+ declare -A opt_args
4
+ local ret=1
5
+
6
+ _arguments -C \
7
+ '1: :__gpr_cmds' \
8
+ '*:: :->args' \
9
+ && ret=0
10
+
11
+ case $state in
12
+ (args)
13
+ case $words[1] in
14
+ (get)
15
+ ;;
16
+ (help)
17
+ __gpr_cmds \
18
+ && ret=0
19
+ ;;
20
+ (list)
21
+ _arguments -C \
22
+ '--paths[Show the paths of all registered repositories]' \
23
+ '(-)*:: :->null_state' \
24
+ && ret=0
25
+ ;;
26
+ (search)
27
+ _arguments -C \
28
+ '-f[Filter by filename]' \
29
+ '-h[Filter by host]' \
30
+ '-r[Filter by repository]' \
31
+ '(-)*:: :->null_state' \
32
+ && ret=0
33
+ ;;
34
+ (update)
35
+ ;;
36
+ esac
37
+ ;;
38
+ esac
39
+
40
+ return ret
41
+ }
42
+
43
+ __gpr_cmds () {
44
+ local -a _c
45
+ _c=(
46
+ 'get:Get a repository'
47
+ 'help:Describe available commands or one specific command'
48
+ 'list:Show all registered repositories'
49
+ 'search:Search the specified keyword in registered repositories'
50
+ 'update:Update the database to be used for search'
51
+ )
52
+
53
+ _describe -t commands Commands _c
54
+ }
55
+ compdef _gpr gpr
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gpr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - kaihar4
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rroonga
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: awesome_print
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Simple management of the git repository.
98
+ email:
99
+ - kaihar4@gmail.com
100
+ executables:
101
+ - gpr
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - bin/gpr
111
+ - gpr.gemspec
112
+ - lib/extends/colorize.rb
113
+ - lib/gpr.rb
114
+ - lib/gpr/api_helper.rb
115
+ - lib/gpr/cli.rb
116
+ - lib/gpr/version.rb
117
+ - zsh/gpr.zsh
118
+ homepage: https://github.com/kaihar4/gpr
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.0.14
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Simple management of the git repository.
142
+ test_files: []
143
+ has_rdoc: