geet 0.1.1 → 0.1.2

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: 033e3851278fd2e0b27bbf58ed7b4fe63f1dc293
4
- data.tar.gz: 5a89dbdd4d43594638e67453d9cdaab7c64bfcf4
3
+ metadata.gz: c29c38895b2fd22b51cba179ee16e94f13c20104
4
+ data.tar.gz: cc3838fd34621971c813f48c282981758f558acf
5
5
  SHA512:
6
- metadata.gz: f038e218da489bc3599091209b8241dba8339441144775e8af0193c793a403187ffb14e88aedfcbcdd2fb427da1f7a9556804c9d2c4e54d7585bc3a2bd7232c5
7
- data.tar.gz: 0faf78b1473415d7725fe04f561177eb64740158d3f1993b4056f5ec21784998d8dce409df944a43c2555d13dff8b5701e7c353a41353b7d44d76bdfc8b61e35
6
+ metadata.gz: 617d8c5acc3b8bc88b49680a39dbf9e0079ef9128ed026bdcb02cb7f241793d70700debd790c52ad8f54612475261c586ca50ddf8559832bdbd77b963fcd68d8
7
+ data.tar.gz: de39813e76e1323296a7bc69f77e82ce4b285c8a31364f596e06120941efce5be7464d559705bc08fbe08f82908bf2be93a61398e31653363165c0a8b4276ae2
data/bin/geet CHANGED
@@ -11,16 +11,23 @@ configuration_helper = Helpers::ConfigurationHelper.new
11
11
  command, options = configuration_helper.decode_argv || exit
12
12
  api_token = configuration_helper.api_token
13
13
 
14
- title, description = options.values_at(:title, :description)
15
-
16
14
  repository = Git::Repository.new(api_token)
17
15
 
18
16
  case command
17
+ when Helpers::ConfigurationHelper::GIST_CREATE_COMMAND
18
+ filename = options.delete(:filename)
19
+ options[:publik] = options.delete(:public) if options.key?(:public)
20
+
21
+ Services::CreateGist.new.execute(repository, filename, options)
19
22
  when Helpers::ConfigurationHelper::ISSUE_CREATE_COMMAND
23
+ title, description = options.values_at(:title, :description)
24
+
20
25
  Services::CreateIssue.new.execute(repository, title, description, options)
21
26
  when Helpers::ConfigurationHelper::ISSUE_LIST_COMMAND
22
27
  Services::ListIssues.new.execute(repository)
23
28
  when Helpers::ConfigurationHelper::PR_CREATE_COMMAND
29
+ title, description = options.values_at(:title, :description)
30
+
24
31
  Services::CreatePr.new.execute(repository, title, description, options)
25
32
  else
26
33
  raise "Internal error - Unrecognized command #{command.inspect}"
data/geet.gemspec CHANGED
@@ -8,6 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.name = "geet"
9
9
  s.version = Geet::VERSION
10
10
  s.platform = Gem::Platform::RUBY
11
+ s.required_ruby_version = '>= 2.2.0'
11
12
  s.authors = ["Saverio Miroddi"]
12
13
  s.date = "2017-10-18"
13
14
  s.email = ["saverio.pub2@gmail.com"]
@@ -15,6 +15,7 @@ module Geet
15
15
  extend Forwardable
16
16
 
17
17
  def_delegators :@remote_repository, :collaborators, :labels
18
+ def_delegators :@remote_repository, :create_gist
18
19
  def_delegators :@remote_repository, :create_issue, :list_issues
19
20
  def_delegators :@remote_repository, :create_pr
20
21
  def_delegators :@account, :authenticated_user
@@ -15,8 +15,12 @@ module Geet
15
15
  @repo = repo
16
16
  end
17
17
 
18
+ def base_link
19
+ "https://api.github.com"
20
+ end
21
+
18
22
  def repo_link
19
- "https://api.github.com/repos/#{@owner}/#{@repo}"
23
+ "#{base_link}/repos/#{@owner}/#{@repo}"
20
24
  end
21
25
 
22
26
  # Send a request.
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'abstract_issue'
4
+
5
+ module Geet
6
+ module GitHub
7
+ class Gist
8
+ def self.create(repository, filename, content, api_helper, description: nil, publik: false)
9
+ request_address = "#{api_helper.base_link}/gists"
10
+ request_data = prepare_request_data(filename, content, description, publik)
11
+
12
+ response = api_helper.send_request(request_address, data: request_data)
13
+
14
+ id = response.fetch('id')
15
+
16
+ new(id)
17
+ end
18
+
19
+ def initialize(id)
20
+ @id = id
21
+ end
22
+
23
+ def link
24
+ "https://gist.github.com/#{@id}"
25
+ end
26
+
27
+ private
28
+
29
+ def self.prepare_request_data(filename, content, description, publik)
30
+ request_data = {
31
+ "public" => publik,
32
+ "files" => {
33
+ filename => {
34
+ "content" => content
35
+ }
36
+ }
37
+ }
38
+
39
+ request_data['description'] = description if description
40
+
41
+ request_data
42
+ end
43
+ end
44
+ end
45
+ end
@@ -27,12 +27,14 @@ module Geet
27
27
  response = api_helper.send_request(request_address, multipage: true)
28
28
  issue_class = Struct.new(:number, :title, :link)
29
29
 
30
- response.map do |issue_data|
31
- number = issue_data.fetch('number')
32
- title = issue_data.fetch('title')
33
- link = issue_data.fetch('html_url')
34
-
35
- issue_class.new(number, title, link)
30
+ response.each_with_object([]) do |issue_data, result|
31
+ if ! issue_data.key?('pull_request')
32
+ number = issue_data.fetch('number')
33
+ title = issue_data.fetch('title')
34
+ link = issue_data.fetch('html_url')
35
+
36
+ result << issue_class.new(number, title, link)
37
+ end
36
38
  end
37
39
  end
38
40
 
@@ -1,8 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'api_helper.rb'
3
+ require_relative 'api_helper'
4
+ require_relative 'gist'
4
5
  require_relative 'issue'
5
- require_relative 'pr.rb'
6
+ require_relative 'pr'
6
7
 
7
8
  module Geet
8
9
  module GitHub
@@ -26,6 +27,10 @@ module Geet
26
27
  response.map { |label_entry| label_entry['name'] }
27
28
  end
28
29
 
30
+ def create_gist(filename, content, description: nil, publik: false)
31
+ Geet::GitHub::Gist.create(@local_repository, filename, content, @api_helper, description: description, publik: publik)
32
+ end
33
+
29
34
  def create_issue(title, description)
30
35
  Geet::GitHub::Issue.create(@local_repository, title, description, @api_helper)
31
36
  end
@@ -7,12 +7,20 @@ module Geet
7
7
  class ConfigurationHelper
8
8
  # Commands
9
9
 
10
+ GIST_CREATE_COMMAND = 'gist.create'
10
11
  ISSUE_CREATE_COMMAND = 'issue.create'
11
12
  ISSUE_LIST_COMMAND = 'issue.list'
12
13
  PR_CREATE_COMMAND = 'pr.create'
13
14
 
14
15
  # Command options
15
16
 
17
+ GIST_CREATE_OPTIONS = [
18
+ ['-p', '--public'],
19
+ ['-B', '--no-browse', "Don't open the gist link in the browser after creation"],
20
+ 'filename',
21
+ '[description]'
22
+ ]
23
+
16
24
  ISSUE_CREATE_OPTIONS = [
17
25
  ['-n', '--no-open-issue', "Don't open the issue link in the browser after creation"],
18
26
  ['-l', '--label-patterns "bug,help wanted"', 'Label patterns'],
@@ -36,6 +44,9 @@ module Geet
36
44
 
37
45
  def decode_argv
38
46
  SimpleScripting::Argv.decode(
47
+ 'gist' => {
48
+ 'create' => GIST_CREATE_OPTIONS,
49
+ },
39
50
  'issue' => {
40
51
  'create' => ISSUE_CREATE_OPTIONS,
41
52
  'list' => ISSUE_LIST_OPTIONS,
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../helpers/os_helper.rb'
4
+ require_relative '../git/repository.rb'
5
+
6
+ module Geet
7
+ module Services
8
+ class CreateGist
9
+ include Geet::Helpers::OsHelper
10
+
11
+ # options:
12
+ # :description
13
+ # :publik: defaults to false
14
+ # :no_browse defaults to false
15
+ #
16
+ def execute(repository, filename, description: nil, publik: false, no_browse: false)
17
+ content = IO.read(filename)
18
+
19
+ puts 'Creating the gist...'
20
+
21
+ gist = repository.create_gist(filename, content, description: description, publik: publik)
22
+
23
+ if no_browse
24
+ puts "Gist address: #{gist.link}"
25
+ else
26
+ os_open(gist.link)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
data/lib/geet/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Geet
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Saverio Miroddi
@@ -46,11 +46,13 @@ files:
46
46
  - lib/geet/git_hub/abstract_issue.rb
47
47
  - lib/geet/git_hub/account.rb
48
48
  - lib/geet/git_hub/api_helper.rb
49
+ - lib/geet/git_hub/gist.rb
49
50
  - lib/geet/git_hub/issue.rb
50
51
  - lib/geet/git_hub/pr.rb
51
52
  - lib/geet/git_hub/remote_repository.rb
52
53
  - lib/geet/helpers/configuration_helper.rb
53
54
  - lib/geet/helpers/os_helper.rb
55
+ - lib/geet/services/create_gist.rb
54
56
  - lib/geet/services/create_issue.rb
55
57
  - lib/geet/services/create_pr.rb
56
58
  - lib/geet/services/list_issues.rb
@@ -67,7 +69,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
67
69
  requirements:
68
70
  - - ">="
69
71
  - !ruby/object:Gem::Version
70
- version: '0'
72
+ version: 2.2.0
71
73
  required_rubygems_version: !ruby/object:Gem::Requirement
72
74
  requirements:
73
75
  - - ">="