fgi 0.2.6.2 → 0.2.6.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a6b83bfa515632d441dfe973d5cef26db17cc47a
4
- data.tar.gz: 620554f320cb674a2d478139de5df1643c6d7307
3
+ metadata.gz: 4cccd7a5b745ba11b6a6b1587d74a6766e0d017c
4
+ data.tar.gz: 580b1cc6fcbbefb0d551904de1027e849f8328dd
5
5
  SHA512:
6
- metadata.gz: a69539d110e1dafdf47748e4cd63d36923d71e6239b4613d63531da24c629795b5e40f69ce4e3a1b723388410aafa489ae7a4ecf1d6356ab4b99feec3dfc4a9a
7
- data.tar.gz: ff2efbf77202b2cd67bb2c0fe3542c8d50dabce4fd95ddf5c013489d63e6773cb23a0fe61927ef7418cb55221a5fc324ab01a6d86128631677d6522e48e03d42
6
+ metadata.gz: 077e1f8ace7e2f006e6429603836af1934219c9dc5811f63676794340700ed819d4ac03e65cdbfdbd4bdf8480219b21e8c30a40d17082e7c77d2ef2f1b126236
7
+ data.tar.gz: edc81dfbb587b2990e22e341f34adeaa97589d931779fef12371107c7c1ef7c7a15e167c5dcfe6eb1bf38a184fbc15430f5f1e9926266956b7efd8403e3ff2fe
data/README.md CHANGED
@@ -2,18 +2,19 @@
2
2
 
3
3
  ## Welcome to Fast Gitlab Issues!
4
4
 
5
- Fast Gitlab Issues, aka Fgi, is a command line issue creation tool for Gitlab.
5
+ Fast Gitlab Issues, aka Fgi, is a command line issue creation tool for Gitlab v8.8+.
6
6
 
7
7
  To install, add the following to your project's Gemfile:
8
8
 
9
9
  ```ruby
10
- gem 'fgi', git: 'git@source.modulotech.fr:modulotech/fgi.git'
10
+ gem 'fgi', git: 'https://github.com/moduloTech/fast-gitlab-issues.git'
11
11
  ```
12
12
 
13
13
  And run `bundle install`.
14
14
 
15
15
  After it finishes, run `$ fgi --config` if the gem is new to the project, or run `$ fgi --token <token>` if you are new to the project and fgi was previously installed.
16
16
 
17
+ You can create your token from Gitlab -> Settings -> Access Tokens
17
18
  From then on, create your issues from the console:
18
19
 
19
20
  ```sh
@@ -31,4 +32,4 @@ $ fgi --token \<token\> \# saves the private gitlab token to a file and adds it
31
32
 
32
33
  The config will ask you for your gitlab access token (you can get it from AF2) and the project URL from gitlab.
33
34
 
34
- Any bugs/requests please open an issue, feel free to use fgi to do so!
35
+ Any bugs/requests please open an issue, feel free to use fgi to do so!
data/exe/fgi CHANGED
@@ -1,7 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'open3'
4
- require "fgi"
4
+ require 'uri'
5
+ require 'net/http'
6
+ require_relative '../lib/fgi'
5
7
 
6
8
  # extract core logic from here into the gem bin
7
9
  module Fgi
@@ -17,23 +19,25 @@ module Fgi
17
19
  when content.match(/--config/)
18
20
  Fgi::Configurator.run
19
21
  when content.match(/--token/)
20
- Fgi::Configurator.save_gitlab_token(content.strip.split(' ').last)
22
+ Fgi::Configurator.validate_and_save_gitlab_token(content.strip.split(' ').last)
21
23
  else
22
- title = content
23
- description = []
24
- success = system("vim temp.txt")
25
- if success
26
- File.open("temp.txt", "r") do |f|
27
- f.each_line do |line|
28
- description << line
29
- end
30
- end
31
- # convert the description of the issue into a string we can use in a curl request
32
- description = description.join
33
- end
34
- Fgi::Executor.new.process_data(title, description)
24
+ create_issue(content)
35
25
  end
36
26
  end
27
+
28
+ # Get the issue's description and initiate its creation
29
+ # @param title [String] the issue's title
30
+ def create_issue(title)
31
+ puts "\nWrite your issue description right bellow (save and quit with CTRL+D) :"
32
+ puts "---------------------------------------------------------------------\n\n"
33
+ begin
34
+ description = STDIN.read
35
+ rescue Interrupt => int
36
+ puts %q[Why did you killed me ? :'(]
37
+ exit!
38
+ end
39
+ Fgi::Executor.new.process_data(title, description)
40
+ end
37
41
  end
38
42
  end
39
43
 
data/fgi.gemspec CHANGED
@@ -4,23 +4,23 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'fgi/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "fgi"
7
+ spec.name = 'fgi'
8
8
  spec.version = Fgi::VERSION
9
- spec.authors = ["Julien PHILIBIN", "Pedro Coutinho"]
10
- spec.email = ["philib_j@modulotech.fr"]
9
+ spec.authors = ['Julien Philibin', 'Pedro Coutinho', 'Matthieu Gourvénec']
10
+ spec.email = ['philib_j@modulotech.fr']
11
11
 
12
- spec.summary = %q{CLI for gitlab.}
13
- spec.description = %q{Fast Gitlab Issues.}
14
- spec.homepage = "https://www.modulotech.fr"
12
+ spec.summary = 'CLI for gitlab.'
13
+ spec.description = 'Fast Gitlab Issues.'
14
+ spec.homepage = 'https://www.modulotech.fr'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
17
  f.match(%r{^(test|spec|features)/})
18
18
  end
19
- spec.bindir = "exe"
19
+ spec.bindir = 'exe'
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
- spec.require_paths = ["lib"]
21
+ spec.require_paths = ['lib']
22
22
 
23
- spec.add_development_dependency "bundler", "~> 1.13"
24
- spec.add_development_dependency "rake", "~> 10.0"
25
- spec.add_development_dependency "rspec", "~> 3.0"
23
+ spec.add_development_dependency 'bundler', '~> 1.13'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec', '~> 3.0'
26
26
  end
data/lib/fgi.rb CHANGED
@@ -6,13 +6,13 @@ require 'json'
6
6
  module Fgi
7
7
  class << self
8
8
  end
9
- autoload :Config, 'fgi/config'
10
- autoload :Version, 'fgi/version'
11
- autoload :Executor, 'fgi/executor'
12
- autoload :HTMLRequest, 'fgi/html_request'
13
- autoload :Helper, 'fgi/helper'
14
- autoload :Configurator, 'fgi/configurator'
15
- autoload :GenerateFile, 'fgi/generate_file'
9
+ require_relative 'fgi/config'
10
+ require_relative 'fgi/version'
11
+ require_relative 'fgi/executor'
12
+ require_relative 'fgi/html_request'
13
+ require_relative 'fgi/helper'
14
+ require_relative 'fgi/configurator'
15
+ require_relative 'fgi/generate_file'
16
16
 
17
17
  CONFIG_FILE = '.fast_gitlab_issues.yml'
18
18
  end
@@ -1,83 +1,161 @@
1
1
  module Fgi
2
2
  class Configurator
3
3
  class << self
4
+
4
5
  def run
5
6
  @config = Fgi::Config.current
6
- not_git_directory = !File.exist?(File.expand_path('.gitignore'))
7
- puts "This doesn't seem to be the root of a git repository, browse to the root of your project and try again." if not_git_directory
8
- return if not_git_directory
9
- puts ''
7
+ is_git_dir?
10
8
  puts '####################################################################'
11
9
  puts ' Welcome to Fast Gitlab Issues configuration '
12
- puts '####################################################################'
13
- puts ''
14
- puts "Please enter your Gitlab access token:"
10
+ puts "####################################################################\n\n"
11
+ puts "#### Enter 'quit' or 'exit' at any time to go back to buisness! ####\n\n"
12
+
13
+ puts 'Please enter your Gitlab Url:'
14
+ validate_and_save_gitlab_uri
15
+
16
+ puts "\nPlease enter your Gitlab access token :"
17
+ puts "(You can generate new token from Gitlab -> Settings -> Access Tokens)"
18
+ puts '---------------------------------------'
15
19
  validate_and_save_gitlab_token
16
- puts "Please paste the project url:"
17
- get_id_from_gitlab
18
- File.open('.fast_gitlab_issues.yml', 'w') {|f| f.write @config.to_yaml }
19
- puts "You are now set to work on #{@config[:project_namespaced]}."
20
- puts "Your configuration has been saved to .fast_gitlab_issues.yml, enjoy!"
21
- puts ''
22
- puts '####################################################################'
20
+
21
+ puts "\nPlease enter the name of the current project :"
22
+ puts '----------------------------------------------'
23
+ search_and_save_project
24
+
25
+ File.open('.fast_gitlab_issues.yml', 'w') { |f| f.write @config.to_yaml }
26
+ puts "\nYou are now set to work on #{@config[:project_namespaced]}."
27
+ puts 'Your configuration has been saved to .fast_gitlab_issues.yml, enjoy !'
28
+ puts "\n####################################################################"
23
29
  end
24
30
 
25
- def get_id_from_gitlab
26
- puts 'example: http://YOUR_GITLAB_URL/modulotech/fast-gitlab-issues'
27
- @uri = URI.parse(STDIN.gets.chomp)
28
- @config[:url] = "#{@uri.scheme}://#{@uri.host}"
29
- uri = URI.parse("#{@config[:url]}/api/v4/projects?search=#{@uri.path.split('/').last}")
30
- Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
31
- req = Net::HTTP::Get.new uri
32
- req['Authorization'] = "Bearer #{@token}"
33
- @response = JSON.parse(http.request(req).body)
34
- end
35
- if !@response[0].nil?
36
- puts "Found #{@response.count} match(es):"
37
- @response.each_with_index do |response, i|
38
- puts "#{i+1} - #{response['name_with_namespace']}"
31
+ def validate_and_save_gitlab_token(inline_token = nil)
32
+ begin
33
+ @token = if inline_token.nil?
34
+ STDIN.gets.chomp
35
+ else
36
+ set_config
37
+ inline_token
38
+ end
39
+ if %w(quit exit).include?(@token)
40
+ puts 'See you back soon !'
41
+ exit!
39
42
  end
40
- puts "Please insert the number of the current project:"
41
- @option = STDIN.gets.chomp.to_i
42
- validate_option
43
- else
44
- puts "We couldn't find a project called #{@uri.path.split('/').last}, can you please double check that url?"
45
- get_id_from_gitlab
43
+ rescue Interrupt => int
44
+ puts %q[Why did you killed me ? :'(]
45
+ exit!
46
46
  end
47
- end
47
+ @projects_uri = "#{@config[:url]}/api/v4/projects"
48
+
49
+ req = Net::HTTP::Get.new(@projects_uri)
50
+ req['PRIVATE-TOKEN'] = @token
51
+ res = Net::HTTP.start(@uri.hostname, @uri.port) { |http| http.request(req) }
48
52
 
49
- def validate_option
50
- if (1..@response.length+1).include?(@option)
51
- @config[:project_gitlab_id] = @response[@option - 1]["id"]
52
- @config[:project_namespaced] = @response[@option - 1]["path_with_namespace"]
53
+ if res.code == '200'
54
+ save_gitlab_token
53
55
  else
54
- puts "Sorry, the option is out of range, try again:"
55
- @option = STDIN.gets.chomp.to_i
56
- validate_option
56
+ puts "\nOops, seems to be an invalid token. Try again or quit (quit/exit) :"
57
+ puts '--------------------------------------------------------------'
58
+ validate_and_save_gitlab_token
57
59
  end
58
60
  end
59
61
 
60
- def validate_and_save_gitlab_token
61
- @token = STDIN.gets.chomp
62
- if @token.length > 30
63
- save_gitlab_token(@token)
64
- else
65
- puts "That doesn't seem to be a valid token, can you please check again?"
66
- validate_and_save_gitlab_token
62
+ private
63
+
64
+ def validate_and_save_gitlab_uri
65
+ puts 'example: http://gitlab.example.com/'
66
+ puts '-----------------------------------'
67
+ begin
68
+ input = STDIN.gets.chomp
69
+ if %w(quit exit).include?(input)
70
+ puts 'See you back soon !'
71
+ exit!
72
+ end
73
+ input = "http://#{input}" if !input.start_with?('http://', 'https://')
74
+ @uri = URI.parse("#{input}/")
75
+ @config[:url] = "#{@uri.scheme}://#{@uri.host}"
76
+ req = Net::HTTP.new(@uri.host, @uri.port)
77
+ res = req.request_head(@uri.path)
78
+ rescue Interrupt => int
79
+ puts %q[Why did you killed me ? :'(]
80
+ exit!
81
+ rescue Exception => e
82
+ puts "\nOops, seems to be a bad url. Try again or quit (quit/exit) :"
83
+ validate_and_save_gitlab_uri
67
84
  end
68
85
  end
69
86
 
70
- def save_gitlab_token(token)
71
- @token = token
72
- File.open('.gitlab_access_token', 'w') {|f| f.write @token }
87
+ def save_gitlab_token
88
+ File.open('.gitlab_access_token', 'w') { |f| f.write @token }
73
89
  if File.open('.gitignore').grep(/.gitlab_access_token/).empty?
74
90
  open('.gitignore', 'a') do |f|
75
91
  f.puts ''
76
- f.puts "# Gfi secret token for gitlab"
77
- f.puts ".gitlab_access_token"
92
+ f.puts '# Gfi secret token for gitlab'
93
+ f.puts '.gitlab_access_token'
78
94
  end
79
95
  end
80
- puts "Gitlab secret token successfully saved to file and added to .gitignore."
96
+ puts "\nGitlab secret token successfully saved to file and added to .gitignore."
97
+ end
98
+
99
+ def search_and_save_project
100
+ begin
101
+ project_name = STDIN.gets.chomp
102
+ if %w(quit exit).include?(project_name)
103
+ puts 'See you back soon !'
104
+ exit!
105
+ end
106
+ rescue Interrupt => int
107
+ puts %q[Why did you killed me ? :'(]
108
+ exit!
109
+ end
110
+
111
+ req = Net::HTTP::Get.new("#{@projects_uri}?search=#{project_name}")
112
+ req['PRIVATE-TOKEN'] = @token
113
+ res = Net::HTTP.start(@uri.hostname, @uri.port) { |http| http.request(req) }
114
+
115
+ results = JSON.parse(res.body)
116
+ if res.code == '200' && !results.empty?
117
+ puts "\nFound #{results.count} match(es):"
118
+ results.each_with_index do |result, i|
119
+ puts "#{i+1} - #{result['name_with_namespace']}"
120
+ end
121
+ validate_option(results)
122
+ else
123
+ puts "\nOops, we couldn't find a project called #{project_name}. Try again or quit (quit/exit) :"
124
+ puts '-------------------------------------------------------------------'+('-'*project_name.length) # Yes, i'm a perfectionist <3
125
+ search_and_save_project
126
+ end
127
+ end
128
+
129
+ def validate_option(results)
130
+ puts "\nPlease insert the number of the current project :"
131
+ puts '-------------------------------------------------'
132
+ begin
133
+ option = STDIN.gets.chomp.to_i
134
+ rescue Interrupt => int
135
+ puts %q[Why did you killed me ? :'(]
136
+ exit!
137
+ end
138
+ if (1..results.length+1).include?(option)
139
+ @config[:project_gitlab_id] = results[option - 1]['id']
140
+ @config[:project_namespaced] = results[option - 1]['path_with_namespace']
141
+ else
142
+ puts "\nSorry, the option is out of range. Try again :"
143
+ validate_option(results)
144
+ end
145
+ end
146
+
147
+ def set_config
148
+ config_file = File.expand_path(CONFIG_FILE)
149
+ @config = YAML.load_file(config_file)
150
+ @uri = URI.parse(@config[:url])
151
+ end
152
+
153
+ def is_git_dir?
154
+ is_git_directory = Dir.exists?('.git')
155
+ if !is_git_directory
156
+ puts %q(This doesn't seem to be the root of a git repository, browse to the root of your project and try again.)
157
+ return
158
+ end
81
159
  end
82
160
  end
83
161
  end
@@ -1,30 +1,36 @@
1
1
  module Fgi
2
2
  class HTMLRequest
3
+
3
4
  def initialize(title, description)
4
5
  @title = title
5
6
  @description = description
6
7
  end
8
+
7
9
  def push
8
10
  uri = URI.parse(generate_link)
11
+ req = Net::HTTP::Post.new uri
12
+ req['PRIVATE-TOKEN'] = Fgi::Config[:token]
13
+
9
14
  Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
10
- req = Net::HTTP::Post.new uri
11
- req['Authorization'] = "Bearer #{Fgi::Config[:token]}"
12
15
  @response = JSON.parse(http.request(req).body)
13
16
  end
14
- if !@response["iid"].nil?
15
- puts "Your issue has been sucessfully created."
16
- puts "To view it, please follow the link bellow:"
17
- puts ""
18
- puts " #{Fgi::Config[:url]}/#{Fgi::Config[:project_namespaced]}/issues/#{@response["iid"].to_s}"
19
- puts ""
20
- puts "Thank you for using Fast Gitlab Issues!"
17
+
18
+ if !@response['iid'].nil?
19
+ puts 'Your issue has been sucessfully created.'
20
+ puts 'To view it, please follow the link bellow:'
21
+ puts ''
22
+ puts "#{Fgi::Config[:url]}/#{Fgi::Config[:project_namespaced]}/issues/#{@response['iid'].to_s}"
23
+ puts ''
24
+ puts 'Thank you for using Fast Gitlab Issues!'
21
25
  else
22
- puts "I'm not really sure what happened, but I believe something went wrong."
23
- puts "CALL HELP!!!"
26
+ puts %q(I'm not really sure what happened, but I believe something went wrong.)
27
+ puts 'CALL HELP!!!'
24
28
  end
25
29
  end
30
+
26
31
  def generate_link
27
- Fgi::Config[:url] + "/api/v4/projects/" + Fgi::Config[:project_gitlab_id].to_s + "/issues?title=" + URI.encode(@title) + '&description=' + URI.encode(@description)
32
+ Fgi::Config[:url] + '/api/v4/projects/' + Fgi::Config[:project_gitlab_id].to_s + '/issues?title=' + URI.encode(@title) + '&description=' + URI.encode(@description)
28
33
  end
34
+
29
35
  end
30
36
  end
data/lib/fgi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Fgi
2
- VERSION = "0.2.6.2"
2
+ VERSION = "0.2.6.3"
3
3
  end
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fgi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6.2
4
+ version: 0.2.6.3
5
5
  platform: ruby
6
6
  authors:
7
- - Julien PHILIBIN
7
+ - Julien Philibin
8
8
  - Pedro Coutinho
9
+ - Matthieu Gourvénec
9
10
  autorequire:
10
11
  bindir: exe
11
12
  cert_chain: []
12
- date: 2017-04-21 00:00:00.000000000 Z
13
+ date: 2017-05-24 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: bundler