codebase-cli 0.1.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.
- data/Gemfile +3 -0
- data/Gemfile.lock +18 -0
- data/README.md +7 -0
- data/Rakefile +19 -0
- data/bin/cb +77 -0
- data/lib/codebase_cli/version.rb +10 -0
- data/lib/codebase_cli.rb +6 -0
- metadata +69 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rake/testtask'
|
2
|
+
|
3
|
+
desc "Build the gem"
|
4
|
+
task :build do
|
5
|
+
opers = Dir.glob('*.gem')
|
6
|
+
opers = ["rm #{ opers.join(' ') }"] unless opers.empty?
|
7
|
+
opers << ["gem build codebase-cli.gemspec"]
|
8
|
+
sh opers.join(" && ")
|
9
|
+
end
|
10
|
+
|
11
|
+
desc "Build and install the gem, removing old installation"
|
12
|
+
task :install => :build do
|
13
|
+
gem = Dir.glob('*.gem').first
|
14
|
+
if gem.nil?
|
15
|
+
puts "could not install the gem"
|
16
|
+
else
|
17
|
+
sh "gem uninstall codebase-cli; gem install #{ gem }"
|
18
|
+
end
|
19
|
+
end
|
data/bin/cb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
CODEBASE_REPOSITORY_URL = "https://%s.codebasehq.com/projects/%s/repositories/%s/tree/master"
|
4
|
+
CODEBASE_BRANCH_URL = "https://%s.codebasehq.com/projects/%s/repositories/%s/tree/%s"
|
5
|
+
CODEBASE_BLOB_URL = "https://%s.codebasehq.com/projects/%s/repositories/%s/blob/master/%s"
|
6
|
+
CODEBASE_COMMIT_URL = "https://%s.codebasehq.com/projects/%s/repositories/%s/commit/%s"
|
7
|
+
|
8
|
+
# Helper methods
|
9
|
+
#
|
10
|
+
def open(url)
|
11
|
+
if RUBY_PLATFORM =~ /darwin/
|
12
|
+
command = 'open'
|
13
|
+
elsif RUBY_PLATFORM =~ /linux/
|
14
|
+
command = 'xgd-open'
|
15
|
+
else
|
16
|
+
command = 'start'
|
17
|
+
end
|
18
|
+
|
19
|
+
`#{command} '#{url}'`
|
20
|
+
end
|
21
|
+
|
22
|
+
def repository_info
|
23
|
+
remote_info = `git remote show origin -n`
|
24
|
+
|
25
|
+
if remote_info =~ /Fetch\sURL:\s(.+)\n/
|
26
|
+
remote_url = $1
|
27
|
+
|
28
|
+
if remote_url =~ /codebase/
|
29
|
+
splited_url = remote_url.split('/')
|
30
|
+
|
31
|
+
if splited_url.size == 3
|
32
|
+
company = splited_url[0].split(':')[1]
|
33
|
+
project = splited_url[1]
|
34
|
+
repository = splited_url[2].gsub('.git', '')
|
35
|
+
|
36
|
+
return [company, project, repository]
|
37
|
+
end
|
38
|
+
else
|
39
|
+
puts 'error: this is not a codebase repository'
|
40
|
+
exit 1
|
41
|
+
end
|
42
|
+
else
|
43
|
+
puts 'error: git remote url not found'
|
44
|
+
exit 1
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def help
|
49
|
+
puts "Codebase CLI - Command line utility to open codebase repositories in you browser"
|
50
|
+
puts
|
51
|
+
puts 'cb'
|
52
|
+
puts "\t open the repository homepage"
|
53
|
+
puts 'cb <file>'
|
54
|
+
puts "\t open the specified file"
|
55
|
+
puts 'cb -r | --ref <object>'
|
56
|
+
puts "\t open the specified object"
|
57
|
+
puts 'cb -b | --branch <branch>'
|
58
|
+
puts "\t open the specified branch"
|
59
|
+
end
|
60
|
+
|
61
|
+
# CLI
|
62
|
+
#
|
63
|
+
case ARGV[0]
|
64
|
+
when '--help', '-h'
|
65
|
+
help
|
66
|
+
when '--ref', '-r'
|
67
|
+
ref = ARGV[1]
|
68
|
+
open CODEBASE_COMMIT_URL % (repository_info << ref)
|
69
|
+
when '--branch', '-b'
|
70
|
+
branch = ARGV[1]
|
71
|
+
open CODEBASE_BRANCH_URL % (repository_info << branch)
|
72
|
+
when nil
|
73
|
+
open CODEBASE_REPOSITORY_URL % repository_info
|
74
|
+
else
|
75
|
+
file = ARGV[0]
|
76
|
+
open CODEBASE_BLOB_URL % (repository_info << file)
|
77
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module CodebaseCli
|
2
|
+
version = nil
|
3
|
+
version = $1 if ::File.expand_path('../..', __FILE__) =~ /\/codebase-cli-([\w\.\-]+)/
|
4
|
+
if version.nil? && ::File.exists?(::File.expand_path('../../../.git', __FILE__))
|
5
|
+
require "step-up"
|
6
|
+
version = StepUp::Driver::Git.last_version
|
7
|
+
end
|
8
|
+
version = "0.0.0" if version.nil?
|
9
|
+
VERSION = version.gsub(/^v?([^\+]+)\+?\d*$/, '\1')
|
10
|
+
end
|
data/lib/codebase_cli.rb
ADDED
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: codebase-cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Lucas Fais
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: step-up
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: Command line utility to open codebase repositories in you browser
|
31
|
+
email:
|
32
|
+
- lucasfais@gmail.com
|
33
|
+
executables:
|
34
|
+
- cb
|
35
|
+
extensions: []
|
36
|
+
extra_rdoc_files: []
|
37
|
+
files:
|
38
|
+
- Gemfile
|
39
|
+
- Gemfile.lock
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- bin/cb
|
43
|
+
- lib/codebase_cli.rb
|
44
|
+
- lib/codebase_cli/version.rb
|
45
|
+
homepage: https://github.com/abril/codebase-cli
|
46
|
+
licenses: []
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 1.3.6
|
63
|
+
requirements: []
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.8.24
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: Command line utility to open codebase repositories in you browser
|
69
|
+
test_files: []
|