geet 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +31 -0
- data/README.md +0 -2
- data/bin/geet +50 -39
- data/geet.gemspec +1 -1
- data/lib/geet/commandline/commands.rb +14 -0
- data/lib/geet/{helpers/configuration_helper.rb → commandline/configuration.rb} +4 -12
- data/lib/geet/git/repository.rb +93 -44
- data/lib/geet/{git_hub → github}/abstract_issue.rb +13 -13
- data/lib/geet/github/account.rb +19 -0
- data/lib/geet/{git_hub/api_helper.rb → github/api_interface.rb} +21 -19
- data/lib/geet/github/collaborator.rb +17 -0
- data/lib/geet/{git_hub → github}/gist.rb +4 -4
- data/lib/geet/{git_hub → github}/issue.rb +10 -10
- data/lib/geet/github/label.rb +17 -0
- data/lib/geet/{git_hub → github}/milestone.rb +11 -11
- data/lib/geet/github/pr.rb +61 -0
- data/lib/geet/services/create_gist.rb +4 -4
- data/lib/geet/services/create_issue.rb +30 -25
- data/lib/geet/services/create_pr.rb +28 -27
- data/lib/geet/services/list_issues.rb +2 -2
- data/lib/geet/services/list_labels.rb +2 -2
- data/lib/geet/services/list_milestones.rb +10 -10
- data/lib/geet/services/list_prs.rb +2 -2
- data/lib/geet/services/merge_pr.rb +8 -7
- data/lib/geet/version.rb +1 -1
- data/spec/integration/create_gist_spec.rb +46 -0
- data/spec/integration/create_issue_spec.rb +66 -0
- data/spec/integration/create_pr_spec.rb +68 -0
- data/spec/integration/list_issues_spec.rb +52 -0
- data/spec/integration/list_labels_spec.rb +28 -0
- data/spec/integration/list_milestones_spec.rb +43 -0
- data/spec/integration/list_prs_spec.rb +52 -0
- data/spec/integration/merge_pr_spec.rb +30 -0
- data/spec/spec_helper.rb +121 -0
- data/spec/vcr_cassettes/create_gist_private.yml +80 -0
- data/spec/vcr_cassettes/create_gist_public.yml +80 -0
- data/spec/vcr_cassettes/create_issue.yml +534 -0
- data/spec/vcr_cassettes/create_issue_upstream.yml +235 -0
- data/spec/vcr_cassettes/create_pr.yml +693 -0
- data/spec/vcr_cassettes/create_pr_upstream.yml +313 -0
- data/spec/vcr_cassettes/list_issues.yml +82 -0
- data/spec/vcr_cassettes/list_issues_upstream.yml +84 -0
- data/spec/vcr_cassettes/list_labels.yml +78 -0
- data/spec/vcr_cassettes/list_milestones.yml +468 -0
- data/spec/vcr_cassettes/list_prs.yml +84 -0
- data/spec/vcr_cassettes/list_prs_upstream.yml +80 -0
- data/spec/vcr_cassettes/merge_pr.yml +156 -0
- metadata +36 -11
- data/lib/geet/git_hub/account.rb +0 -19
- data/lib/geet/git_hub/pr.rb +0 -57
- data/lib/geet/git_hub/remote_repository.rb +0 -65
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b893cf44b85d8bfeedc77128b96c5bc921abb701
|
4
|
+
data.tar.gz: e50482a1691bedde73ef4c1c195693a57c60d9ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2733412c618b5d39cdeeb3b900364c69fcc551fa9238c30e743d6deb1b6a9083fc3cbf279df09027692a685f9f47fddb2d8eecb6beda7f79f03617f3dce31814
|
7
|
+
data.tar.gz: 4cb03d50785c4645e0d206337340d84bd53f8569c667c20787a2507a4579264fc4d13be4c2bffa5109c1a46ac2c79d8011917c50d7e580f0de72e7d207a36611
|
data/.rspec
ADDED
data/Gemfile
CHANGED
@@ -5,3 +5,13 @@ source 'https://rubygems.org'
|
|
5
5
|
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
6
6
|
|
7
7
|
gem 'simple_scripting', '~> 0.9.3'
|
8
|
+
|
9
|
+
group :development, :test do
|
10
|
+
gem 'byebug', '~> 9.1.0'
|
11
|
+
end
|
12
|
+
|
13
|
+
group :test do
|
14
|
+
gem 'vcr', '~> 3.0.3'
|
15
|
+
gem 'webmock', '~> 3.1.1'
|
16
|
+
gem 'rspec', '~> 3.7.0'
|
17
|
+
end
|
data/Gemfile.lock
CHANGED
@@ -1,15 +1,46 @@
|
|
1
1
|
GEM
|
2
2
|
remote: https://rubygems.org/
|
3
3
|
specs:
|
4
|
+
addressable (2.5.2)
|
5
|
+
public_suffix (>= 2.0.2, < 4.0)
|
6
|
+
byebug (9.1.0)
|
7
|
+
crack (0.4.3)
|
8
|
+
safe_yaml (~> 1.0.0)
|
9
|
+
diff-lcs (1.3)
|
10
|
+
hashdiff (0.3.7)
|
4
11
|
parseconfig (1.0.8)
|
12
|
+
public_suffix (3.0.1)
|
13
|
+
rspec (3.7.0)
|
14
|
+
rspec-core (~> 3.7.0)
|
15
|
+
rspec-expectations (~> 3.7.0)
|
16
|
+
rspec-mocks (~> 3.7.0)
|
17
|
+
rspec-core (3.7.0)
|
18
|
+
rspec-support (~> 3.7.0)
|
19
|
+
rspec-expectations (3.7.0)
|
20
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
21
|
+
rspec-support (~> 3.7.0)
|
22
|
+
rspec-mocks (3.7.0)
|
23
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
+
rspec-support (~> 3.7.0)
|
25
|
+
rspec-support (3.7.0)
|
26
|
+
safe_yaml (1.0.4)
|
5
27
|
simple_scripting (0.9.3)
|
6
28
|
parseconfig (~> 1.0)
|
29
|
+
vcr (3.0.3)
|
30
|
+
webmock (3.1.1)
|
31
|
+
addressable (>= 2.3.6)
|
32
|
+
crack (>= 0.3.2)
|
33
|
+
hashdiff
|
7
34
|
|
8
35
|
PLATFORMS
|
9
36
|
ruby
|
10
37
|
|
11
38
|
DEPENDENCIES
|
39
|
+
byebug (~> 9.1.0)
|
40
|
+
rspec (~> 3.7.0)
|
12
41
|
simple_scripting (~> 0.9.3)
|
42
|
+
vcr (~> 3.0.3)
|
43
|
+
webmock (~> 3.1.1)
|
13
44
|
|
14
45
|
BUNDLED WITH
|
15
46
|
1.16.0.pre.3
|
data/README.md
CHANGED
@@ -85,5 +85,3 @@ Examples:
|
|
85
85
|
Geet is in alpha status. Although I use it daily, lots of features are being implemented, and internal/external APIs are frequently changed.
|
86
86
|
|
87
87
|
The public release will be 1.0, and is expected to be released in January 2018 or earlier.
|
88
|
-
|
89
|
-
The test suite is planned for v0.3.0. In case the project should have any user/developer besides me before that version, I will put any feature on hold, and build the full test suite.
|
data/bin/geet
CHANGED
@@ -1,45 +1,56 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require_relative '../lib/geet/
|
4
|
+
require_relative '../lib/geet/commandline/configuration.rb'
|
5
|
+
require_relative '../lib/geet/commandline/commands.rb'
|
5
6
|
require_relative '../lib/geet/git/repository.rb'
|
7
|
+
Dir[File.join(__dir__, '../lib/geet/services/*.rb')].each { |filename| require filename }
|
8
|
+
|
9
|
+
class GeetLauncher
|
10
|
+
include Geet
|
11
|
+
include Geet::Commandline::Commands
|
12
|
+
|
13
|
+
def launch
|
14
|
+
commandline_configuration = Commandline::Configuration.new
|
15
|
+
|
16
|
+
command, options = commandline_configuration.decode_argv || exit
|
17
|
+
api_token = commandline_configuration.api_token
|
18
|
+
|
19
|
+
# `:upstream` is always false in the gist command case.
|
20
|
+
repository = Git::Repository.new(api_token, upstream: !!options[:upstream])
|
21
|
+
|
22
|
+
case command
|
23
|
+
when GIST_CREATE_COMMAND
|
24
|
+
filename = options.delete(:filename)
|
25
|
+
options[:publik] = options.delete(:public) if options.key?(:public)
|
26
|
+
|
27
|
+
Services::CreateGist.new.execute(repository, filename, options)
|
28
|
+
when ISSUE_CREATE_COMMAND
|
29
|
+
title, description = options.values_at(:title, :description)
|
30
|
+
options[:milestone_pattern] = options.delete(:milestone) if options.key?(:milestone)
|
31
|
+
|
32
|
+
Services::CreateIssue.new.execute(repository, title, description, options)
|
33
|
+
when ISSUE_LIST_COMMAND
|
34
|
+
Services::ListIssues.new.execute(repository)
|
35
|
+
when LABEL_LIST_COMMAND
|
36
|
+
Services::ListLabels.new.execute(repository)
|
37
|
+
when MILESTONE_LIST_COMMAND
|
38
|
+
Services::ListMilestones.new.execute(repository)
|
39
|
+
when PR_CREATE_COMMAND
|
40
|
+
title, description = options.values_at(:title, :description)
|
41
|
+
options[:milestone_pattern] = options.delete(:milestone) if options.key?(:milestone)
|
42
|
+
|
43
|
+
Services::CreatePr.new.execute(repository, title, description, options)
|
44
|
+
when PR_LIST_COMMAND
|
45
|
+
Services::ListPrs.new.execute(repository)
|
46
|
+
when PR_MERGE_COMMAND
|
47
|
+
Services::MergePr.new.execute(repository)
|
48
|
+
else
|
49
|
+
raise "Internal error - Unrecognized command #{command.inspect}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
6
53
|
|
7
|
-
|
8
|
-
|
9
|
-
configuration_helper = Helpers::ConfigurationHelper.new
|
10
|
-
|
11
|
-
command, options = configuration_helper.decode_argv || exit
|
12
|
-
api_token = configuration_helper.api_token
|
13
|
-
|
14
|
-
# `:upstream` is always false in the gist command case.
|
15
|
-
repository = Git::Repository.new(api_token, upstream: !!options[:upstream])
|
16
|
-
|
17
|
-
case command
|
18
|
-
when Helpers::ConfigurationHelper::GIST_CREATE_COMMAND
|
19
|
-
filename = options.delete(:filename)
|
20
|
-
options[:publik] = options.delete(:public) if options.key?(:public)
|
21
|
-
|
22
|
-
Services::CreateGist.new.execute(repository, filename, options)
|
23
|
-
when Helpers::ConfigurationHelper::ISSUE_CREATE_COMMAND
|
24
|
-
title, description = options.values_at(:title, :description)
|
25
|
-
options[:milestone_pattern] = options.delete(:milestone) if options.key?(:milestone)
|
26
|
-
|
27
|
-
Services::CreateIssue.new.execute(repository, title, description, options)
|
28
|
-
when Helpers::ConfigurationHelper::ISSUE_LIST_COMMAND
|
29
|
-
Services::ListIssues.new.execute(repository)
|
30
|
-
when Helpers::ConfigurationHelper::LABEL_LIST_COMMAND
|
31
|
-
Services::ListLabels.new.execute(repository)
|
32
|
-
when Helpers::ConfigurationHelper::MILESTONE_LIST_COMMAND
|
33
|
-
Services::ListMilestones.new.execute(repository)
|
34
|
-
when Helpers::ConfigurationHelper::PR_CREATE_COMMAND
|
35
|
-
title, description = options.values_at(:title, :description)
|
36
|
-
options[:milestone_pattern] = options.delete(:milestone) if options.key?(:milestone)
|
37
|
-
|
38
|
-
Services::CreatePr.new.execute(repository, title, description, options)
|
39
|
-
when Helpers::ConfigurationHelper::PR_LIST_COMMAND
|
40
|
-
Services::ListPrs.new.execute(repository)
|
41
|
-
when Helpers::ConfigurationHelper::PR_MERGE_COMMAND
|
42
|
-
Services::MergePr.new.execute(repository)
|
43
|
-
else
|
44
|
-
raise "Internal error - Unrecognized command #{command.inspect}"
|
54
|
+
if __FILE__ == $0
|
55
|
+
GeetLauncher.new.launch
|
45
56
|
end
|
data/geet.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.platform = Gem::Platform::RUBY
|
11
11
|
s.required_ruby_version = '>= 2.2.0'
|
12
12
|
s.authors = ['Saverio Miroddi']
|
13
|
-
s.date = '2017-11-
|
13
|
+
s.date = '2017-11-21'
|
14
14
|
s.email = ['saverio.pub2@gmail.com']
|
15
15
|
s.homepage = 'https://github.com/saveriomiroddi/geet'
|
16
16
|
s.summary = 'Commandline interface for performing SCM (eg. GitHub) operations (eg. PR creation).'
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Geet
|
2
|
+
module Commandline
|
3
|
+
module Commands
|
4
|
+
GIST_CREATE_COMMAND = 'gist.create'
|
5
|
+
ISSUE_CREATE_COMMAND = 'issue.create'
|
6
|
+
ISSUE_LIST_COMMAND = 'issue.list'
|
7
|
+
LABEL_LIST_COMMAND = 'label.list'
|
8
|
+
MILESTONE_LIST_COMMAND = 'milestone.list'
|
9
|
+
PR_CREATE_COMMAND = 'pr.create'
|
10
|
+
PR_LIST_COMMAND = 'pr.list'
|
11
|
+
PR_MERGE_COMMAND = 'pr.merge'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,20 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'simple_scripting/argv'
|
4
|
+
require_relative 'commands'
|
4
5
|
|
5
6
|
module Geet
|
6
|
-
module
|
7
|
-
class
|
8
|
-
|
9
|
-
|
10
|
-
GIST_CREATE_COMMAND = 'gist.create'
|
11
|
-
ISSUE_CREATE_COMMAND = 'issue.create'
|
12
|
-
ISSUE_LIST_COMMAND = 'issue.list'
|
13
|
-
LABEL_LIST_COMMAND = 'label.list'
|
14
|
-
MILESTONE_LIST_COMMAND = 'milestone.list'
|
15
|
-
PR_CREATE_COMMAND = 'pr.create'
|
16
|
-
PR_LIST_COMMAND = 'pr.list'
|
17
|
-
PR_MERGE_COMMAND = 'pr.merge'
|
7
|
+
module Commandline
|
8
|
+
class Configuration
|
9
|
+
include Commands
|
18
10
|
|
19
11
|
# Command options
|
20
12
|
|
data/lib/geet/git/repository.rb
CHANGED
@@ -1,32 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
4
|
-
|
5
|
-
Dir[File.join(__dir__, '../**/remote_repository.rb')].each { |repository_file| require repository_file }
|
6
|
-
Dir[File.join(__dir__, '../**/account.rb')].each { |account_file| require account_file }
|
7
|
-
Dir[File.join(__dir__, '../**/api_helper.rb')].each { |helper_file| require helper_file }
|
8
|
-
Dir[File.join(__dir__, '../services/*.rb')].each { |helper_file| require helper_file }
|
3
|
+
require 'shellwords'
|
9
4
|
|
10
5
|
module Geet
|
11
6
|
module Git
|
12
7
|
# This class represents, for convenience, both the local and the remote repository, but the
|
13
8
|
# remote code is separated in each provider module.
|
14
9
|
class Repository
|
15
|
-
extend Forwardable
|
16
|
-
|
17
|
-
def_delegators :@remote_repository, :abstract_issues
|
18
|
-
def_delegators :@remote_repository, :collaborators, :labels
|
19
|
-
def_delegators :@remote_repository, :create_gist
|
20
|
-
def_delegators :@remote_repository, :create_issue, :issues
|
21
|
-
def_delegators :@remote_repository, :labels
|
22
|
-
def_delegators :@remote_repository, :milestones
|
23
|
-
def_delegators :@remote_repository, :create_pr, :prs
|
24
|
-
def_delegators :@account, :authenticated_user
|
25
|
-
|
26
|
-
DOMAIN_PROVIDERS_MAPPING = {
|
27
|
-
'github.com' => Geet::GitHub
|
28
|
-
}.freeze
|
29
|
-
|
30
10
|
# For simplicity, we match any character except the ones the separators.
|
31
11
|
REMOTE_ORIGIN_REGEX = %r{
|
32
12
|
\A
|
@@ -39,54 +19,80 @@ module Geet
|
|
39
19
|
ORIGIN_NAME = 'origin'
|
40
20
|
UPSTREAM_NAME = 'upstream'
|
41
21
|
|
42
|
-
def initialize(api_token, upstream: false)
|
43
|
-
|
44
|
-
|
22
|
+
def initialize(api_token, upstream: false, location: nil)
|
23
|
+
@api_token = api_token
|
24
|
+
@upstream = upstream
|
25
|
+
@location = location
|
26
|
+
end
|
45
27
|
|
46
|
-
|
28
|
+
# REMOTE FUNCTIONALITIES (REPOSITORY)
|
47
29
|
|
48
|
-
|
49
|
-
|
30
|
+
def collaborators
|
31
|
+
provider_module::Collaborator.list(api_interface)
|
50
32
|
end
|
51
33
|
|
52
|
-
|
34
|
+
def labels
|
35
|
+
provider_module::Label.list(api_interface)
|
36
|
+
end
|
53
37
|
|
54
|
-
def
|
55
|
-
|
38
|
+
def create_gist(filename, content, description: nil, publik: false)
|
39
|
+
provider_module::Gist.create(filename, content, api_interface, description: description, publik: publik)
|
56
40
|
end
|
57
41
|
|
58
|
-
def
|
59
|
-
|
60
|
-
|
61
|
-
remote_url = remote(ORIGIN_NAME)
|
42
|
+
def create_issue(title, description)
|
43
|
+
provider_module::Issue.create(title, description, api_interface)
|
44
|
+
end
|
62
45
|
|
63
|
-
|
46
|
+
def abstract_issues(milestone: nil)
|
47
|
+
provider_module::AbstractIssue.list(api_interface, milestone: milestone)
|
64
48
|
end
|
65
49
|
|
66
|
-
def
|
67
|
-
|
50
|
+
def issues
|
51
|
+
provider_module::Issue.list(api_interface)
|
52
|
+
end
|
68
53
|
|
69
|
-
|
54
|
+
def milestone(number)
|
55
|
+
provider_module::Milestone.find(number, api_interface)
|
56
|
+
end
|
57
|
+
|
58
|
+
def milestones
|
59
|
+
provider_module::Milestone.list(api_interface)
|
60
|
+
end
|
61
|
+
|
62
|
+
def create_pr(title, description, head)
|
63
|
+
provider_module::PR.create(title, description, head, api_interface)
|
64
|
+
end
|
65
|
+
|
66
|
+
def prs(head: nil)
|
67
|
+
provider_module::PR.list(api_interface, head: head)
|
70
68
|
end
|
71
69
|
|
72
|
-
#
|
70
|
+
# REMOTE FUNCTIONALITIES (ACCOUNT)
|
71
|
+
|
72
|
+
def authenticated_user
|
73
|
+
provider_module::Account.new(api_interface).authenticated_user
|
74
|
+
end
|
75
|
+
|
76
|
+
# OTHER/CONVENIENCE FUNCTIONALITIES
|
73
77
|
|
74
78
|
def current_branch
|
75
|
-
|
79
|
+
gitdir_option = "--git-dir #{@location.shellescape}/.git" if @location
|
80
|
+
branch = `git #{gitdir_option} rev-parse --abbrev-ref HEAD`.strip
|
76
81
|
|
77
82
|
raise "Couldn't find current branch" if branch == 'HEAD'
|
78
83
|
|
79
84
|
branch
|
80
85
|
end
|
81
86
|
|
82
|
-
# OTHER
|
83
|
-
|
84
87
|
private
|
85
88
|
|
86
|
-
#
|
89
|
+
# REPOSITORY METADATA
|
90
|
+
|
91
|
+
# The result is in the format `git@github.com:donaldduck/geet.git`
|
87
92
|
#
|
88
93
|
def remote(name)
|
89
|
-
|
94
|
+
gitdir_option = "--git-dir #{@location.shellescape}/.git" if @location
|
95
|
+
remote_url = `git #{gitdir_option} ls-remote --get-url #{name}`.strip
|
90
96
|
|
91
97
|
if remote_url == name
|
92
98
|
raise "Remote #{name.inspect} not found!"
|
@@ -96,6 +102,49 @@ module Geet
|
|
96
102
|
|
97
103
|
remote_url
|
98
104
|
end
|
105
|
+
|
106
|
+
# PROVIDER
|
107
|
+
|
108
|
+
def provider_domain
|
109
|
+
# We assume that it's not possible to have origin and upstream on different providers.
|
110
|
+
#
|
111
|
+
remote_url = remote(ORIGIN_NAME)
|
112
|
+
|
113
|
+
domain = remote_url[REMOTE_ORIGIN_REGEX, 1] || remote_url[REMOTE_ORIGIN_REGEX, 2]
|
114
|
+
|
115
|
+
raise "Can't identify domain in the provider domain string: #{provider_domain}" if domain !~ /(.*)\.\w+/
|
116
|
+
|
117
|
+
domain
|
118
|
+
end
|
119
|
+
|
120
|
+
def provider_module
|
121
|
+
module_name = provider_domain[/(.*)\.\w+/, 1].capitalize
|
122
|
+
|
123
|
+
require_provider_modules
|
124
|
+
|
125
|
+
Kernel.const_get("Geet::#{module_name}")
|
126
|
+
end
|
127
|
+
|
128
|
+
def require_provider_modules
|
129
|
+
provider_dirname = provider_domain[/(.*)\.\w+/, 1]
|
130
|
+
files_pattern = "#{__dir__}/../#{provider_dirname}/*.rb"
|
131
|
+
|
132
|
+
Dir[files_pattern].each { |filename| require filename }
|
133
|
+
end
|
134
|
+
|
135
|
+
# OTHER HELPERS
|
136
|
+
|
137
|
+
def api_interface
|
138
|
+
provider_module::ApiInterface.new(@api_token, path(upstream: @upstream), @upstream)
|
139
|
+
end
|
140
|
+
|
141
|
+
# Example: `donaldduck/geet`
|
142
|
+
#
|
143
|
+
def path(upstream: false)
|
144
|
+
remote_name = upstream ? UPSTREAM_NAME : ORIGIN_NAME
|
145
|
+
|
146
|
+
remote(remote_name)[REMOTE_ORIGIN_REGEX, 3]
|
147
|
+
end
|
99
148
|
end
|
100
149
|
end
|
101
150
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Geet
|
4
|
-
module
|
4
|
+
module Github
|
5
5
|
# It seems that autoloading will be deprecated, but it's currently the cleanest solution
|
6
6
|
# to the legitimate problem of AbstractIssue needing Issue/PR to be loaded (due to :list),
|
7
7
|
# and viceversa (due to class definition).
|
@@ -13,20 +13,20 @@ module Geet
|
|
13
13
|
class AbstractIssue
|
14
14
|
attr_reader :number, :title, :link
|
15
15
|
|
16
|
-
def initialize(number,
|
16
|
+
def initialize(number, api_interface, title, link)
|
17
17
|
@number = number
|
18
|
-
@
|
18
|
+
@api_interface = api_interface
|
19
19
|
@title = title
|
20
20
|
@link = link
|
21
21
|
end
|
22
22
|
|
23
23
|
# See https://developer.github.com/v3/issues/#list-issues-for-a-repository
|
24
24
|
#
|
25
|
-
def self.list(
|
26
|
-
|
25
|
+
def self.list(api_interface, milestone: nil)
|
26
|
+
api_path = 'issues'
|
27
27
|
request_params = { milestone: milestone } if milestone
|
28
28
|
|
29
|
-
response =
|
29
|
+
response = api_interface.send_request(api_path, params: request_params, multipage: true)
|
30
30
|
|
31
31
|
response.map do |issue_data|
|
32
32
|
number = issue_data.fetch('number')
|
@@ -35,7 +35,7 @@ module Geet
|
|
35
35
|
|
36
36
|
klazz = issue_data.key?('pull_request') ? PR : Issue
|
37
37
|
|
38
|
-
klazz.new(number,
|
38
|
+
klazz.new(number, api_interface, title, link)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -43,26 +43,26 @@ module Geet
|
|
43
43
|
# users: String, or Array of strings.
|
44
44
|
#
|
45
45
|
def assign_users(users)
|
46
|
+
api_path = "issues/#{@number}/assignees"
|
46
47
|
request_data = { assignees: Array(users) }
|
47
|
-
request_address = "#{@api_helper.api_repo_link}/issues/#{@number}/assignees"
|
48
48
|
|
49
|
-
@
|
49
|
+
@api_interface.send_request(api_path, data: request_data)
|
50
50
|
end
|
51
51
|
|
52
52
|
def add_labels(labels)
|
53
|
+
api_path = "issues/#{@number}/labels"
|
53
54
|
request_data = labels
|
54
|
-
request_address = "#{@api_helper.api_repo_link}/issues/#{@number}/labels"
|
55
55
|
|
56
|
-
@
|
56
|
+
@api_interface.send_request(api_path, data: request_data)
|
57
57
|
end
|
58
58
|
|
59
59
|
# See https://developer.github.com/v3/issues/#edit-an-issue
|
60
60
|
#
|
61
61
|
def edit(milestone:)
|
62
|
-
request_address = "#{@api_helper.api_repo_link}/issues/#{@number}"
|
63
62
|
request_data = { milestone: milestone }
|
63
|
+
api_path = "issues/#{@number}"
|
64
64
|
|
65
|
-
@
|
65
|
+
@api_interface.send_request(api_path, data: request_data, http_method: :patch)
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|