checklister 0.9.2 → 0.9.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: 975ebe56553df4d65b12f7dbab5e7a6b01c45d72
4
- data.tar.gz: ffae8c16237f57f5a0003724ef2f0b8885c77466
3
+ metadata.gz: 08d5e35df41587f793a8f21775e8fafeb9d4c04b
4
+ data.tar.gz: c5613a39590bf9203abfd5aec3eb8f5ae720f450
5
5
  SHA512:
6
- metadata.gz: b474c3775f0a55f8650cff805f8201cefe9b8f1d44d7fb4d043b5f031424f31b127190e22bf0ef5f3a100b132992cfd0e5c426c906f0444d95445df85a9451ff
7
- data.tar.gz: f85d2ef19f2e71a4a7956a88b5dbdc677965c1ec8d4ad1ddf7e64d95def72fb100843acf97343504c1df258e8ced690aa731c51de7fb82a3f91c627faaa17836
6
+ metadata.gz: 15f2bb49f709e445ec8dcbb31865ff634aeebc3a4a0f77839823b0f174aaef5c345946c9487cd854d38b000aeed48250bb973cdef33c39e14893955b2c7261b9
7
+ data.tar.gz: a84716cfd646cfdcb79814fb04db912b4186a7a44da842c032527f5300deaaa013e0a3c771ca8103c621de1113dc3a12f97d49d2d6a58e4a1c3271a0950d62e8
@@ -3,7 +3,14 @@ All notable changes to this project will be documented in this file.
3
3
 
4
4
  NOTE: the project follows [Semantic Versioning](http://semver.org/).
5
5
 
6
- ## 0.0.9 - 2015-09-22
6
+ ## 0.9.3 - 2015-09-26
7
+
8
+ ### Added
9
+
10
+ - [feature] Connect to git account
11
+ - [feature] Save your github services settings to local file
12
+
13
+ ## 0.9.0 - 2015-09-22
7
14
 
8
15
  ### Added
9
16
 
data/README.md CHANGED
@@ -7,6 +7,7 @@
7
7
  [![Gem Version](https://badge.fury.io/rb/checklister.svg)](http://badge.fury.io/rb/checklister)
8
8
  [![Code Climate](https://codeclimate.com/github/benichu/checklister/badges/gpa.svg)](https://codeclimate.com/github/benichu/checklister)
9
9
  [![Coverage Status](https://coveralls.io/repos/benichu/checklister/badge.svg?branch=master&service=github)](https://coveralls.io/github/benichu/checklister?branch=master)
10
+ [![MIT license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/benichu/checklister/blob/master/LICENSE)
10
11
 
11
12
  ## Description
12
13
 
@@ -133,7 +134,7 @@ To prepare a release, run `script/release`. This will package a new version of t
133
134
  - [ ] [improvements] CLI improvements based on first test run with real users
134
135
  - [ ] [documentation] Yard documentation updated
135
136
  - [ ] [feature] Create a new Issue based on a specific markdown file (remote path)
136
- - [ ] [feature] Connect to github account
137
+ - [x] [feature] Connect to github account
137
138
 
138
139
  ### Wishlist
139
140
 
@@ -117,28 +117,26 @@ desc "Transform a markdown file or url checklist into an actionable issue"
117
117
  command :new do |c|
118
118
  c.flag [:c,:checklist], desc: "Set the markdown checklist file path", required: true
119
119
  c.action do |global_options,options,args|
120
- client = Checklister::Client.new(Checklister.config.to_hash).get_api_client
121
- gitlab_project = Checklister::Gitlab::Project.new(client)
120
+ api_client = Checklister::Client.new(Checklister.config.to_hash)
121
+ project_client = api_client.project
122
122
  checklist_path = options[:checklist]
123
123
 
124
124
  puts "* Type some letters of your project's name..."
125
125
  project_like = STDIN.gets.chomp
126
- projects = gitlab_project.filtered_by_name(project_like)
126
+ projects = project_client.filtered_by_name(project_like)
127
127
  default_project_id = projects.first[:id]
128
128
  projects.each do |project|
129
- puts "%-5s %-100s" % ["[#{project[:id]}]", project[:name_with_namespace]]
129
+ puts "%-5s %-100s" % ["[#{project[:id]}]", project[:name]]
130
130
  end
131
131
  puts "* Pick your project Id, defaults to [#{default_project_id}]"
132
132
  choice = STDIN.gets.chomp
133
133
  project_id = choice == "" ? default_project_id : choice
134
- project = gitlab_project.get(project_id)
134
+ project = project_client.get(project_id)
135
135
  puts "* Creating a checklist issue from #{checklist_path}"
136
136
  puts " to the project: #{project[:name]}"
137
137
  parsed_checklist = Checklister::Parser.new(checklist_path)
138
- issue = Checklister::Gitlab::Issue.new(client).create(project_id, parsed_checklist.to_params)
139
- puts "------------->"
140
- puts "| Check it out: #{Checklister.config.endpoint.gsub("/api/v3", "")}/#{project[:path_with_namespace]}/issues/#{issue.id}"
141
- puts "------------->"
138
+ issue = api_client.issue.create(project_id, parsed_checklist.to_params)
139
+ puts "* Issue successfully created!"
142
140
  end
143
141
  end
144
142
 
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.add_dependency "gitlab" , "~> 3.4.0"
26
26
  spec.add_dependency "gli" , "~> 2.13"
27
+ spec.add_dependency "octokit" , "~> 4.0"
27
28
 
28
29
  spec.add_development_dependency "bundler" , "~> 1.10"
29
30
  spec.add_development_dependency "coveralls" , "~> 0.8.2"
@@ -9,6 +9,8 @@ require "checklister/version"
9
9
  require "checklister/client"
10
10
  require "checklister/gitlab/project"
11
11
  require "checklister/gitlab/issue"
12
+ require "checklister/github/project"
13
+ require "checklister/github/issue"
12
14
 
13
15
  module Checklister
14
16
  class << self
@@ -1,23 +1,101 @@
1
1
  require "gitlab"
2
+ require "octokit"
2
3
 
3
4
  module Checklister
5
+ # Implement a kind of Factory pattern
6
+ #
7
+ # We create an object without exposing the creation logic and then refer to newly created object using a common interface.
4
8
  class Client
5
- IMPLEMENTED_BACKENDS = %w(gitlab)
9
+ # The issue service backends we are currently supporting
10
+ #
11
+ # - [x] gitlab
12
+ # - [x] github
13
+ # - [ ] bitbucket
14
+ #
15
+ IMPLEMENTED_BACKENDS = %w(gitlab github)
6
16
 
17
+ attr_reader :api_client
18
+
19
+ # Initialize all the issue service options required to be able to interact with it
20
+ #
21
+ # @example Initialize a gitlab client's options
22
+ # gitlab_client = Checklister::Client.new(kind: "gitlab", endpoint: "https://gitlab.com/api/v3", private_token: "supersecret")
23
+ #
24
+ # @param options [Hash] list of key/values to apply to the appropriately created API client
25
+ # @option opts [String] :kind The issue service identifier ('github', 'gitlab', ...)
26
+ # @option opts [String] :endpoint The issue service endpoint url
27
+ # @option opts [String] :private_token The issue service user's private token
28
+ #
29
+ # @raise [ArgumentError] When no or an inexistent issue service kind is set
30
+ #
31
+ # @return [Object] a factory instance
32
+ #
7
33
  def initialize(options = {})
8
34
  @kind = options.fetch(:kind) { raise ArgumentError, "No API client can be initialized" }
9
- raise(ArgumentError, "No #{@kind} API client has been implemented") unless IMPLEMENTED_BACKENDS.include?(@kind)
35
+ raise(NotImplementedError, "No #{@kind} API client has been implemented") unless IMPLEMENTED_BACKENDS.include?(@kind)
10
36
  @options = options.reject { |k| [:kind].include? k }
11
37
  default_options = { user_agent: "Checklister for #{@kind} #{Checklister::VERSION}" }
12
- default_options.merge!(httparty: { verify: false }) # FIXME
13
38
  @options.merge! default_options
39
+ @options_for_kind = prepare_options_for_kind(@options, @kind)
40
+ @project_klass = nil
41
+ @issue_klass = nil
42
+ define_classes_for_kind(@kind)
43
+ @api_client = get_api_client
44
+ end
45
+
46
+ def project
47
+ @project ||= @project_klass.new(@api_client)
14
48
  end
15
49
 
50
+ def issue
51
+ @issue ||= @issue_klass.new(@api_client)
52
+ end
53
+
54
+ private
55
+
56
+ # Initialize the issue service API client
57
+ #
58
+ # @example get an API client
59
+ # gitlab_client = Checklister::Client.new(kind: "gitlab", endpoint: "https://gitlab.com/api/v3", private_token: "supersecret")
60
+ # gtilab_client.get_api_client
61
+ #
62
+ # @return [Object] the API client based on our initialized options
63
+ #
16
64
  def get_api_client
17
65
  case @kind
18
66
  when "gitlab"
19
- ::Gitlab.client(@options)
67
+ @api_client ||= ::Gitlab.client(@options_for_kind)
68
+ when "github"
69
+ @api_client ||= Octokit::Client.new(@options_for_kind)
20
70
  end
21
71
  end
72
+
73
+ def prepare_options_for_kind(options, kind)
74
+ if kind == "github"
75
+ # Octokit uses ENV for overide
76
+ # See: https://github.com/octokit/octokit.rb/blob/a98979107a4bf9741a05a1f751405f8a29f29b38/lib/octokit/default.rb#L136-L138
77
+ options.delete(:user_agent)
78
+ # :endpoint is not required
79
+ options.delete(:endpoint)
80
+ # :private_token is called :access_token
81
+ options[:access_token] = options.delete(:private_token)
82
+ elsif kind == "gitlab"
83
+ options.merge!(httparty: { verify: false }) # FIXME
84
+ end
85
+ options
86
+ end
87
+
88
+ def define_classes_for_kind(kind)
89
+ @project_klass = if kind == "gitlab"
90
+ Checklister::Gitlab::Project
91
+ elsif kind == "github"
92
+ Checklister::Github::Project
93
+ end
94
+ @issue_klass = if kind == "gitlab"
95
+ Checklister::Gitlab::Issue
96
+ elsif kind == "github"
97
+ Checklister::Github::Issue
98
+ end
99
+ end
22
100
  end
23
101
  end
@@ -0,0 +1,14 @@
1
+ module Checklister
2
+ module Github
3
+ class Issue
4
+ def initialize(client)
5
+ @client = client
6
+ end
7
+
8
+ def create(project_id, attributes = {})
9
+ issue = Checklister::Issue.new(attributes.merge(project_id: project_id))
10
+ @client.create_issue(issue.project_id, issue.title, issue.description)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,63 @@
1
+ module Checklister
2
+ module Github
3
+ class ProjectDecorator
4
+ def initialize(object)
5
+ @object = object
6
+ end
7
+
8
+ def id
9
+ @object[:id]
10
+ end
11
+
12
+ def name
13
+ @object[:full_name]
14
+ end
15
+
16
+ def description
17
+ @object[:description]
18
+ end
19
+
20
+ def to_hash
21
+ { id: id, name: name, description: description }
22
+ end
23
+ end
24
+
25
+ class Project
26
+ # Default options that we want to pass when querying the github project index
27
+ DEFAULT_OPTIONS = { sort: "full_name", direction: "asc" }
28
+
29
+ # Initialize a github project instance
30
+ #
31
+ # @example Get a project's data
32
+ # project = Checklister::Project.new(gitlab_client).get(1)
33
+ #
34
+ # @param client [Object] an instance of Checklister::Client
35
+ #
36
+ def initialize(client)
37
+ @client = client
38
+ end
39
+
40
+ # Query a particular project based on it's id
41
+ # @param project_id [Integer] github project id
42
+ # @return [Hash] a project properties
43
+ def get(project_id)
44
+ ProjectDecorator.new(@client.repository(project_id)).to_hash
45
+ end
46
+
47
+ # Get all github's projects
48
+ # @param options [optional, Hash] query options
49
+ # @return [Array] and array of project's properties as Hash
50
+ def all(options = {})
51
+ query_options = DEFAULT_OPTIONS.merge options
52
+ @client.repositories(query_options).map { |p| ProjectDecorator.new(p).to_hash }
53
+ end
54
+
55
+ # Get github's projects based on a search string (LIKE on project#name)
56
+ # @param name [String] partial project's name
57
+ # @return [Array] and array of project's properties as Hash
58
+ def filtered_by_name(name, _options = {})
59
+ all.select { |p| p[:name].downcase.include? name.downcase }
60
+ end
61
+ end
62
+ end
63
+ end
@@ -1,25 +1,64 @@
1
1
  module Checklister
2
2
  module Gitlab
3
+ class ProjectDecorator
4
+ def initialize(object)
5
+ @object = object
6
+ end
7
+
8
+ def id
9
+ @object.id
10
+ end
11
+
12
+ def name
13
+ @object.name_with_namespace
14
+ end
15
+
16
+ def description
17
+ @object.description
18
+ end
19
+
20
+ def to_hash
21
+ { id: id, name: name, description: description }
22
+ end
23
+ end
24
+
3
25
  class Project
4
- DEFAULT_OPTIONS = { order_by: "id", sort: "asc", per_page: "10" }
5
- ATTRIBUTES = %w(id name description) # NOTE: For information
26
+ # Default options that we want to pass when querying the gitlab project index
27
+ DEFAULT_OPTIONS = { order_by: "id", sort: "asc", per_page: "200" }
6
28
 
29
+ # Initialize a gitlab project instance
30
+ #
31
+ # @example Get a project's data
32
+ # project = Checklister::Project.new(gitlab_client).get(1)
33
+ #
34
+ # @param client [Object] an instance of Checklister::Client
35
+ #
7
36
  def initialize(client)
8
37
  @client = client
9
38
  end
10
39
 
40
+ # Query a particular project based on it's id
41
+ # @param project_id [Integer] gitlab project id
42
+ # @return [Hash] a project properties
11
43
  def get(project_id)
12
- Checklister::Sanitizer.symbolize @client.project(project_id).to_hash
44
+ ProjectDecorator.new(@client.project(project_id)).to_hash
13
45
  end
14
46
 
47
+ # Get all gitlab's projects
48
+ # @param options [optional, Hash] query options
49
+ # @return [Array] and array of project's properties as Hash
15
50
  def all(options = {})
16
51
  query_options = DEFAULT_OPTIONS.merge options
17
- Checklister::Sanitizer.symbolize @client.projects(query_options).map(&:to_hash)
52
+ @client.projects(query_options).map { |p| ProjectDecorator.new(p).to_hash }
18
53
  end
19
54
 
55
+ # Get gitlab's projects based on a search string (LIKE on project#name)
56
+ # @param name [String] partial project's name
57
+ # @param options [optional, Hash] query options
58
+ # @return [Array] and array of project's properties as Hash
20
59
  def filtered_by_name(name, options = {})
21
60
  query_options = DEFAULT_OPTIONS.merge options
22
- Checklister::Sanitizer.symbolize @client.project_search(name, query_options).map(&:to_hash)
61
+ @client.project_search(name, query_options).map { |p| ProjectDecorator.new(p).to_hash }
23
62
  end
24
63
  end
25
64
  end
@@ -1,3 +1,3 @@
1
1
  module Checklister
2
- VERSION = "0.9.2"
2
+ VERSION = "0.9.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: checklister
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Thouret
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-09-24 00:00:00.000000000 Z
12
+ date: 2015-09-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gitlab
@@ -39,6 +39,20 @@ dependencies:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
41
  version: '2.13'
42
+ - !ruby/object:Gem::Dependency
43
+ name: octokit
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '4.0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '4.0'
42
56
  - !ruby/object:Gem::Dependency
43
57
  name: bundler
44
58
  requirement: !ruby/object:Gem::Requirement
@@ -182,6 +196,8 @@ files:
182
196
  - lib/checklister/client.rb
183
197
  - lib/checklister/configuration.rb
184
198
  - lib/checklister/configuration_file.rb
199
+ - lib/checklister/github/issue.rb
200
+ - lib/checklister/github/project.rb
185
201
  - lib/checklister/gitlab/issue.rb
186
202
  - lib/checklister/gitlab/project.rb
187
203
  - lib/checklister/issue.rb