mygit 0.0.2 → 0.0.11

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.
Files changed (5) hide show
  1. data/LICENSE +19 -0
  2. data/README.md +1 -0
  3. data/bin/mygit +3 -70
  4. data/lib/mygit.rb +123 -0
  5. metadata +20 -2
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (C) 2012 Ian Vaughan
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
+ so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
18
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
19
+ THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -9,6 +9,7 @@ Setup
9
9
 
10
10
  Put config file where I can find it :-
11
11
 
12
+ mkdir ~/.mygit
12
13
  cp .mygit-example ~/.mygit
13
14
 
14
15
  And then edit it to add your details
data/bin/mygit CHANGED
@@ -1,72 +1,5 @@
1
- #!/usr/bin/env ruby -wKU
2
- # curl -u "github@ianvaughan.co.uk:password" https://api.github.com/orgs/globaldev/repos
1
+ #!/usr/bin/env ruby
3
2
 
4
- require 'httparty'
5
- require 'pp'
3
+ require 'mygit'
6
4
 
7
- class GitHub
8
- include HTTParty
9
- base_uri 'https://api.github.com'
10
-
11
- def initialize(u, p)
12
- @auth = {:username => u, :password => p}
13
- end
14
-
15
- def repos repo
16
- self.class.get("/orgs/#{repo}/repos", {:basic_auth => @auth})
17
- end
18
-
19
- end
20
-
21
- class Access
22
- def initialize
23
- conf = YAML.load_file File.expand_path '~/.mygit'
24
- @repo = GitHub.new(conf['user'], conf['pass']).repos(conf['repo'])
25
- end
26
-
27
- def keys
28
- puts @repo.first.each_key { |k| puts k }
29
- end
30
-
31
- def list
32
- @repo.each do |r|
33
- spaces = ' ' * (30 - r['name'].size)
34
- puts "#{r['name']} #{spaces} #{r['ssh_url']}"
35
- end
36
- end
37
-
38
- def find name
39
- found = nil
40
- @repo.each do |r|
41
- found = r if r['name'] == name
42
- end
43
- found
44
- end
45
- end
46
-
47
- # git clone name -> looks up git@ ssh, then cd
48
-
49
- access = Access.new
50
-
51
- cmd = ARGV.shift
52
- case cmd
53
- when 'list' # dumps a list of all repos found
54
- access.list
55
- when 'find' # find a repo by name
56
- pp access.find ARGV.shift
57
- when 'clone' # clone a repo by name
58
- p = access.find ARGV.shift
59
- cmd = "git clone #{p['ssh_url']}"
60
- system cmd
61
- when 'open' # Opens either the current pwd, or a supplied project, GitHub project page in a browser
62
- opt = ARGV.shift
63
- opt = File.basename(Dir.getwd) if opt.nil?
64
- p = access.find opt
65
- system "open #{p['html_url']}"
66
- else
67
- puts 'Unknown or no command given! Options are :-'
68
- File.open(__FILE__).each_line do |line|
69
- puts " " + line.sub('when','').sub('#', '->').gsub('\'','') if line.include? 'when'
70
- break if line.include? 'else'
71
- end
72
- end
5
+ Commands::execute ARGV
@@ -0,0 +1,123 @@
1
+ require 'httparty'
2
+ require 'highline/import'
3
+
4
+ class GitHub
5
+ include HTTParty
6
+ base_uri 'https://api.github.com'
7
+
8
+ def initialize(u, p)
9
+ @auth = {:username => u, :password => p}
10
+ end
11
+
12
+ def repos repo
13
+ self.class.get("/orgs/#{repo}/repos?per_page=100", {:basic_auth => @auth})
14
+ end
15
+ end
16
+
17
+ class FileStorage
18
+ CONFIG_DIR = "#{Dir.home}/.mygit"
19
+ CONFIG_FILE = "#{CONFIG_DIR}/config.yml"
20
+ REPOS_FILE = "#{CONFIG_DIR}/repos.yml"
21
+
22
+ attr_reader :repo
23
+
24
+ def initialize
25
+ @repo ||= YAML.load_file REPOS_FILE if File.exist?(REPOS_FILE)
26
+ end
27
+
28
+ class << self
29
+ def update filename = CONFIG_FILE
30
+ # Get username from prompt if file missing
31
+ file = File.expand_path filename
32
+ conf = YAML.load_file file
33
+ gh = GitHub.new(conf['user'], get_input("Enter password: ", '*'))
34
+
35
+ repo = gh.repos(conf['repo'])
36
+ keep = remove_keys repo
37
+ save keep
38
+ end
39
+
40
+ KEEP_KEYS = ['name', 'ssh_url', 'html_url']
41
+ def remove_keys array
42
+ keep = []
43
+ array.each do |a|
44
+ keep << a.keep_if {|k| KEEP_KEYS.include? k }
45
+ end
46
+ keep
47
+ end
48
+
49
+ def get_input prompt, echo = true
50
+ ask(prompt) {|q| q.echo = echo}
51
+ end
52
+
53
+ def save data
54
+ File.open(REPOS_FILE, "w+") {|f| f.puts(data.to_yaml) }
55
+ # File.open(fnm, ‘w’) { |out| YAML.dump(h, out) }
56
+ end
57
+ end
58
+ end
59
+
60
+ class Access
61
+ COL_WIDTH = 30
62
+
63
+ class << self
64
+ def list
65
+ repo.each do |r|
66
+ spaces = ' ' * (COL_WIDTH - r['name'].size) unless r['name'].size > COL_WIDTH
67
+ puts "#{r['name']} #{spaces} #{r['ssh_url']}"
68
+ end
69
+ end
70
+
71
+ def find name
72
+ found = nil
73
+ repo.each do |r|
74
+ found = r if r['name'] == name
75
+ end
76
+ found
77
+ end
78
+
79
+ def repo
80
+ @repo ||= FileStorage.new.repo
81
+ end
82
+ end
83
+ end
84
+
85
+ class Commands
86
+ class << self
87
+ def current_branch
88
+ `git rev-parse --abbrev-ref HEAD`
89
+ end
90
+
91
+ def branch_url
92
+ "tree/#{current_branch}"
93
+ end
94
+
95
+ # TODO: Use OptionsParser
96
+ def execute args
97
+ cmd = args.shift
98
+ case cmd
99
+ when 'update'
100
+ FileStorage::update
101
+ when 'list' # dumps a list of all repos found
102
+ Access::list
103
+ when 'find' # find a repo by name
104
+ pp Access::find args.shift
105
+ when 'clone' # clone a repo by name
106
+ p = Access::find args.shift
107
+ cmd = "git clone #{p['ssh_url']}"
108
+ system cmd
109
+ when 'open' # Opens either the current pwd, or a supplied project, GitHub project page in a browser
110
+ opt = args.shift
111
+ opt = File.basename(Dir.getwd) if opt.nil?
112
+ p = Access::find opt
113
+ system "open #{p['html_url']}/#{branch_url}"
114
+ else
115
+ puts 'Unknown or no command given! Options are :-'
116
+ File.open(__FILE__).each_line do |line|
117
+ puts " " + line.sub('when','').sub('#', '->').gsub('\'','') if line.include? 'when'
118
+ break if line.include? 'else'
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mygit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-31 00:00:00.000000000 Z
12
+ date: 2013-01-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: highline
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
30
46
  description: Allows you to do cool things from the CLI with GitHub
31
47
  email:
32
48
  - mygit@ianvaughan.co.uk
@@ -36,6 +52,8 @@ extensions: []
36
52
  extra_rdoc_files: []
37
53
  files:
38
54
  - README.md
55
+ - LICENSE
56
+ - lib/mygit.rb
39
57
  - bin/mygit
40
58
  homepage: http://github.com/ianvaughan/mygit
41
59
  licenses: