glub 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +2 -2
  3. data/VERSION +1 -1
  4. data/glub.gemspec +3 -4
  5. data/lib/glub.rb +149 -16
  6. metadata +23 -43
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f747e2b5382347598dc9e3ed785d2cd846d2c3ad
4
+ data.tar.gz: f28666496fe885272f9174ef683b341c2f4ae7b1
5
+ SHA512:
6
+ metadata.gz: 12ef1a5cfeb90a5559a102c583c0b5deb9bfff962e101d051acdcc49d916c6f1f70d5f1ce782bdf8898bf92356d57978ad0d4f18f09f2c8f4062772dd0f52e2a
7
+ data.tar.gz: 9debca2365eddfc699f21cd963175b9f74727fce75c198b98ec99b25643367229c6d36eeca9d0eec98dfb65b6fa471b622025d662029a1da708b8c5691ed74eb
data/README.md CHANGED
@@ -13,13 +13,13 @@ gem install glub
13
13
 
14
14
  ## Config
15
15
 
16
- You will need a file called .gitlab in your home directory. It's a YAML file.
16
+ You will need a file called .glub in your home directory. It's a YAML file.
17
17
 
18
18
  You can get your API key - also known as private token - from your account page on Gitlab
19
19
 
20
20
  ### Config example
21
21
 
22
- api_endpoint: http://gitlab.mycompany.com/api/v3
22
+ gitlab_host : gitlab.mycompany.com
23
23
  api_key : Kd834fh3ofoaal
24
24
 
25
25
  ## FAQ
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.1.0
data/glub.gemspec CHANGED
@@ -5,13 +5,13 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "glub"
8
- s.version = "0.0.3"
8
+ s.version = File.read( File.join( File.dirname(__FILE__), 'VERSION' ) )
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["George McIntosh"]
11
+ s.authors = ["George McIntosh", "Ryan MacGillivray"]
12
12
  s.date = "2013-04-18"
13
13
  s.description = "Glub - a Gitlab client for your command-line."
14
- s.email = "george@georgemcintosh.com"
14
+ s.email = "rmacg89@gmail.com"
15
15
  s.executables = ["glub"]
16
16
  s.extra_rdoc_files = [
17
17
  "README.md"
@@ -74,4 +74,3 @@ Gem::Specification.new do |s|
74
74
  s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
75
75
  end
76
76
  end
77
-
data/lib/glub.rb CHANGED
@@ -13,12 +13,12 @@ class Glub < Sif::Loader
13
13
  class_option :config, :default => "#{ENV['HOME']}/.glub", :aliases => ['-c']
14
14
  class_option :host, :aliases => ['-h']
15
15
  class_option :api_key, :aliases => ['-k']
16
-
17
- desc "create NAME", "Creates a new Gitlab project"
18
- def create(project_name)
19
-
16
+
17
+ desc "create NAME (GROUP_ID/NAMESPACE_ID optional)", "Creates a new Gitlab project"
18
+ def create(project_name, namespace_id=nil)
19
+
20
20
  puts "Creating Gitlab project #{project_name}"
21
- command = {
21
+ command = {
22
22
  :name => project_name,
23
23
  :description => 'this is a new project',
24
24
  :default_branch => 'master',
@@ -26,13 +26,18 @@ class Glub < Sif::Loader
26
26
  :wiki_ebabled => 'true',
27
27
  :wall_enabled => 'true',
28
28
  :merge_requests_enabled => 'true'
29
- }
29
+ }
30
+
31
+ unless namespace_id.nil?
32
+ command[:namespace_id] = namespace_id
33
+ end
30
34
 
31
- response = RestClient.post(
35
+
36
+ response = RestClient.post(
32
37
  "#{@api_endpoint}/projects?private_token=#{@api_key}",
33
38
  command.to_json,
34
39
  :content_type => 'application/json'
35
- )
40
+ )
36
41
 
37
42
  response = JSON.parse response.body
38
43
 
@@ -42,23 +47,153 @@ class Glub < Sif::Loader
42
47
  setup_repo
43
48
  end
44
49
 
45
- desc "list projects", "Lists all projects"
50
+ desc "list", "Lists all projects"
46
51
  def list
47
-
48
- response = RestClient.get(
52
+
53
+ response = RestClient.get(
49
54
  "#{@api_endpoint}/projects?private_token=#{@api_key}"
50
- )
55
+ )
51
56
 
52
57
  response = JSON.parse response.body
53
58
 
54
59
  projects = []
55
- response.each { |project| projects << project['name'] }
60
+ response.each { |project| projects << "Name:#{project['name']} / ID:#{project['id']}" }
56
61
  puts "Projects: "
57
62
  projects.each { |project| puts " #{project}" }
58
63
  "#{projects}"
59
64
 
60
65
  end
61
66
 
67
+ desc "list_groups", "Lists all groups"
68
+ def list_groups
69
+
70
+ response = RestClient.get(
71
+ "#{@api_endpoint}/groups?private_token=#{@api_key}"
72
+ )
73
+
74
+ response = JSON.parse response.body
75
+
76
+ groups = []
77
+ response.each { |group| groups << "Name:#{group['name']} / ID:#{group['id']}" }
78
+ puts "Groups: "
79
+ groups.each { |group| puts " #{group}" }
80
+ "#{groups}"
81
+ end
82
+
83
+ desc "create_group NAME", "Creates a new group"
84
+ def create_group(group_name)
85
+
86
+ puts "Creating Gitlab group #{group_name}"
87
+ command = {
88
+ name: group_name,
89
+ path: group_name.downcase.gsub(' ', '-')
90
+ }
91
+
92
+ response = RestClient.post(
93
+ "#{@api_endpoint}/groups?private_token=#{@api_key}",
94
+ command.to_json,
95
+ content_type: 'application/json'
96
+ )
97
+
98
+ response = JSON.parse response.body
99
+
100
+ puts "Group #{group_name} created."
101
+ # add root user by default
102
+ add_user_to_group(response['id'], 1, 'owner')
103
+ end
104
+
105
+ desc "add_user_to_group GROUP_ID USER_ID PERMISSION", "Add a user to a group"
106
+ def add_user_to_group(group_id, user_id, permission=nil)
107
+ if permission.nil?
108
+ access_level = 30
109
+ else
110
+ access_level = determine_access_level(permission)
111
+ end
112
+
113
+ group_response = RestClient.get(
114
+ "#{@api_endpoint}/groups/#{group_id}?private_token=#{@api_key}"
115
+ )
116
+
117
+ group_response = JSON.parse group_response.body
118
+
119
+ group_name = group_response['name']
120
+
121
+
122
+ puts "Adding user to group #{group_name}"
123
+ command = {
124
+ id: group_id,
125
+ user_id: user_id,
126
+ access_level: access_level
127
+ }
128
+
129
+ response = RestClient.post(
130
+ "#{@api_endpoint}/groups/#{group_id}/members?private_token=#{@api_key}",
131
+ command.to_json,
132
+ content_type: 'application/json'
133
+ )
134
+
135
+ response = JSON.parse response.body
136
+
137
+ puts "User added to group #{group_name}"
138
+ end
139
+
140
+ desc 'move_project_to_group GROUP_ID PROJECT_ID', 'Move a project to a group'
141
+ def move_project_to_group(group_id, project_id)
142
+
143
+ group_response = RestClient.get(
144
+ "#{@api_endpoint}/groups/#{group_id}?private_token=#{@api_key}"
145
+ )
146
+ group_response = JSON.parse group_response.body
147
+ group_name = group_response['name']
148
+
149
+ project_response = RestClient.get(
150
+ "#{@api_endpoint}/projects/#{project_id}?private_token=#{@api_key}"
151
+ )
152
+ project_response = JSON.parse project_response.body
153
+ project_name = project_response['name']
154
+
155
+ puts "Moving project #{project_name} to group #{group_name}"
156
+ command = {
157
+ id: group_id,
158
+ project_id: project_id
159
+ }
160
+
161
+ response = RestClient.post(
162
+ "#{@api_endpoint}/groups/#{group_id}/projects/#{project_id}?private_token=#{@api_key}",
163
+ command.to_json,
164
+ content_type: 'application/json'
165
+ )
166
+
167
+ response = JSON.parse response.body
168
+
169
+ puts "Project #{project_name} moved to group #{group_name}"
170
+ end
171
+
172
+ desc "clone", "Clone from a list of projects"
173
+ def clone
174
+
175
+ response = RestClient.get(
176
+ "#{@api_endpoint}/projects?private_token=#{@api_key}"
177
+ )
178
+
179
+ response = JSON.parse response.body
180
+
181
+ projects = []
182
+ response.each_with_index do |project, idx|
183
+ idx+=1
184
+ projects << { id: idx, name: project['name'], ssh_repo: project['ssh_url_to_repo'] }
185
+ end
186
+ puts "Projects: "
187
+ projects.each { |project| puts " #{project[:id]} Name:#{project[:name]}"}
188
+ # "#{projects}"
189
+ puts 'Which project do you want to clone? (enter the number)'
190
+ clone_response = $stdin.gets.chomp.to_i
191
+ if !clone_response.nil?
192
+ project = projects.find{ |p| p[:id] == clone_response }
193
+ system "git clone #{project[:ssh_repo]}"
194
+ end
195
+ end
196
+
62
197
  no_tasks do
63
198
  def load_configuration
64
199
  super
@@ -66,7 +201,5 @@ class Glub < Sif::Loader
66
201
  @api_endpoint = "#{protocol}://#{@gitlab_host}/api/v3"
67
202
  end
68
203
  end
69
-
70
- end
71
-
72
204
 
205
+ end
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
5
- prerelease:
4
+ version: 0.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - George McIntosh
8
+ - Ryan MacGillivray
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
@@ -14,133 +14,117 @@ dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: webmock
16
16
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
17
  requirements:
19
- - - ! '>='
18
+ - - ">="
20
19
  - !ruby/object:Gem::Version
21
20
  version: '0'
22
21
  type: :runtime
23
22
  prerelease: false
24
23
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
24
  requirements:
27
- - - ! '>='
25
+ - - ">="
28
26
  - !ruby/object:Gem::Version
29
27
  version: '0'
30
28
  - !ruby/object:Gem::Dependency
31
29
  name: vcr
32
30
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
31
  requirements:
35
- - - ! '>='
32
+ - - ">="
36
33
  - !ruby/object:Gem::Version
37
34
  version: '0'
38
35
  type: :runtime
39
36
  prerelease: false
40
37
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
38
  requirements:
43
- - - ! '>='
39
+ - - ">="
44
40
  - !ruby/object:Gem::Version
45
41
  version: '0'
46
42
  - !ruby/object:Gem::Dependency
47
43
  name: thor
48
44
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
45
  requirements:
51
- - - ! '>='
46
+ - - ">="
52
47
  - !ruby/object:Gem::Version
53
48
  version: '0'
54
49
  type: :runtime
55
50
  prerelease: false
56
51
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
52
  requirements:
59
- - - ! '>='
53
+ - - ">="
60
54
  - !ruby/object:Gem::Version
61
55
  version: '0'
62
56
  - !ruby/object:Gem::Dependency
63
57
  name: rake
64
58
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
59
  requirements:
67
- - - ! '>='
60
+ - - ">="
68
61
  - !ruby/object:Gem::Version
69
62
  version: '0'
70
63
  type: :runtime
71
64
  prerelease: false
72
65
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
66
  requirements:
75
- - - ! '>='
67
+ - - ">="
76
68
  - !ruby/object:Gem::Version
77
69
  version: '0'
78
70
  - !ruby/object:Gem::Dependency
79
71
  name: rest-client
80
72
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
73
  requirements:
83
- - - ! '>='
74
+ - - ">="
84
75
  - !ruby/object:Gem::Version
85
76
  version: '0'
86
77
  type: :runtime
87
78
  prerelease: false
88
79
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
80
  requirements:
91
- - - ! '>='
81
+ - - ">="
92
82
  - !ruby/object:Gem::Version
93
83
  version: '0'
94
84
  - !ruby/object:Gem::Dependency
95
85
  name: sif
96
86
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
87
  requirements:
99
- - - ! '>='
88
+ - - ">="
100
89
  - !ruby/object:Gem::Version
101
90
  version: '0'
102
91
  type: :runtime
103
92
  prerelease: false
104
93
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
94
  requirements:
107
- - - ! '>='
95
+ - - ">="
108
96
  - !ruby/object:Gem::Version
109
97
  version: '0'
110
98
  - !ruby/object:Gem::Dependency
111
99
  name: bundler
112
100
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
101
  requirements:
115
- - - ! '>='
102
+ - - ">="
116
103
  - !ruby/object:Gem::Version
117
104
  version: '0'
118
105
  type: :development
119
106
  prerelease: false
120
107
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
108
  requirements:
123
- - - ! '>='
109
+ - - ">="
124
110
  - !ruby/object:Gem::Version
125
111
  version: '0'
126
112
  - !ruby/object:Gem::Dependency
127
113
  name: jeweler
128
114
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
115
  requirements:
131
- - - ~>
116
+ - - "~>"
132
117
  - !ruby/object:Gem::Version
133
118
  version: 1.8.4
134
119
  type: :development
135
120
  prerelease: false
136
121
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
122
  requirements:
139
- - - ~>
123
+ - - "~>"
140
124
  - !ruby/object:Gem::Version
141
125
  version: 1.8.4
142
126
  description: Glub - a Gitlab client for your command-line.
143
- email: george@georgemcintosh.com
127
+ email: rmacg89@gmail.com
144
128
  executables:
145
129
  - glub
146
130
  extensions: []
@@ -167,28 +151,24 @@ files:
167
151
  homepage: http://georgemcintosh.com/glub
168
152
  licenses:
169
153
  - Apache 2.0
154
+ metadata: {}
170
155
  post_install_message:
171
156
  rdoc_options: []
172
157
  require_paths:
173
158
  - lib
174
159
  required_ruby_version: !ruby/object:Gem::Requirement
175
- none: false
176
160
  requirements:
177
- - - ! '>='
161
+ - - ">="
178
162
  - !ruby/object:Gem::Version
179
163
  version: '0'
180
- segments:
181
- - 0
182
- hash: -4234807907285407120
183
164
  required_rubygems_version: !ruby/object:Gem::Requirement
184
- none: false
185
165
  requirements:
186
- - - ! '>='
166
+ - - ">="
187
167
  - !ruby/object:Gem::Version
188
168
  version: '0'
189
169
  requirements: []
190
170
  rubyforge_project:
191
- rubygems_version: 1.8.24
171
+ rubygems_version: 2.2.2
192
172
  signing_key:
193
173
  specification_version: 3
194
174
  summary: Command-line Gitlab client