geet 0.1.4 → 0.1.5

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: 1f6a2eb12fdc08bd0f4a51d842b5531f9a18e6df
4
- data.tar.gz: 0d552dbf78425a735cb5e360492e875f07a24c4a
3
+ metadata.gz: cd0635ff3846a704465468c125761bd184c4f028
4
+ data.tar.gz: 7090288ba79f44a4029ae3ba7217d89e62246105
5
5
  SHA512:
6
- metadata.gz: e9f68e13f8e60fd218ee73188e1593f8cb1da88cf9f03069dcf67ac29e8310be1706b87bbd3a7071fce931d19b45a4a4bd9295f21e2fc82d94670ec76358e015
7
- data.tar.gz: 84e94c28cf83f49cb0b649eec8e13508c4cebc03d417d562c4460f2aaba1a606475860f899d6af3c54ebcdda262b904eb719c47f60f20dfbc99564df7fcb146a
6
+ metadata.gz: 9ae2941d700748eddf8ae382ca8ee7c53ff1a9fe896b752628ceaf0c244ada04312eadea1da3fc9b4ff571bebe512393a48083dbb47e9477c528043c99a4d155
7
+ data.tar.gz: 41ecfe2ea7c10fff999d36403cbccdb9a5b5705b210aadd87f8009d1cc3f7555fe4b9320d9f3fc89a435cb2d101c838e517fb0621fa2ad1e8fe1c7156ce8a898
data/bin/geet CHANGED
@@ -11,7 +11,8 @@ 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
- repository = Git::Repository.new(api_token)
14
+ # `:upstream` is always false in the gist command case.
15
+ repository = Git::Repository.new(api_token, upstream: !!options[:upstream])
15
16
 
16
17
  case command
17
18
  when Helpers::ConfigurationHelper::GIST_CREATE_COMMAND
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-10-26"
13
+ s.date = "2017-10-30"
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)."
@@ -28,18 +28,19 @@ module Geet
28
28
  REMOTE_ORIGIN_REGEX = %r{
29
29
  \A
30
30
  (?:https://(.+?)/|git@(.+?):)
31
- ([^/]+)
32
- /
33
- (.*?)
31
+ ([^/]+/.*?)
34
32
  (?:\.git)?
35
33
  \Z
36
34
  }x
37
35
 
38
- def initialize(api_token)
36
+ ORIGIN_NAME = 'origin'
37
+ UPSTREAM_NAME = 'upstream'
38
+
39
+ def initialize(api_token, upstream: false)
39
40
  the_provider_domain = provider_domain
40
41
  provider_module = DOMAIN_PROVIDERS_MAPPING[the_provider_domain] || raise("Provider not supported for domain: #{provider_domain}")
41
42
 
42
- api_helper = provider_module::ApiHelper.new(api_token, user, owner, repo)
43
+ api_helper = provider_module::ApiHelper.new(api_token, user, path(upstream: upstream), upstream)
43
44
 
44
45
  @remote_repository = provider_module::RemoteRepository.new(self, api_helper)
45
46
  @account = provider_module::Account.new(api_helper)
@@ -52,15 +53,17 @@ module Geet
52
53
  end
53
54
 
54
55
  def provider_domain
55
- remote_origin[REMOTE_ORIGIN_REGEX, 1] || remote_origin[REMOTE_ORIGIN_REGEX, 2]
56
- end
56
+ # We assume that it's not possible to have origin and upstream on different providers.
57
+ #
58
+ remote_url = remote(ORIGIN_NAME)
57
59
 
58
- def owner
59
- remote_origin[REMOTE_ORIGIN_REGEX, 3]
60
+ remote_url[REMOTE_ORIGIN_REGEX, 1] || remote_url[REMOTE_ORIGIN_REGEX, 2]
60
61
  end
61
62
 
62
- def repo
63
- remote_origin[REMOTE_ORIGIN_REGEX, 4]
63
+ def path(upstream: false)
64
+ remote_name = upstream ? UPSTREAM_NAME : ORIGIN_NAME
65
+
66
+ remote(remote_name)[REMOTE_ORIGIN_REGEX, 3]
64
67
  end
65
68
 
66
69
  # DATA
@@ -75,14 +78,16 @@ module Geet
75
78
 
76
79
  # The result is in the format `git@github.com:saveriomiroddi/geet.git`
77
80
  #
78
- def remote_origin
79
- origin = `git ls-remote --get-url origin`.strip
81
+ def remote(name)
82
+ remote_url = `git ls-remote --get-url #{name}`.strip
80
83
 
81
- if origin !~ REMOTE_ORIGIN_REGEX
82
- raise("Unexpected remote reference format: #{origin.inspect}")
84
+ if remote_url == name
85
+ raise "Remote #{name.inspect} not found!"
86
+ elsif remote_url !~ REMOTE_ORIGIN_REGEX
87
+ raise "Unexpected remote reference format: #{remote_url.inspect}"
83
88
  end
84
89
 
85
- origin
90
+ remote_url
86
91
  end
87
92
  end
88
93
  end
@@ -15,8 +15,8 @@ module Geet
15
15
  # options:
16
16
  # filter: :pr, :issue, or nil
17
17
  #
18
- def self.list(repository, api_helper, filter: nil)
19
- request_address = "#{api_helper.repo_link}/issues"
18
+ def self.list(api_helper, filter: nil)
19
+ request_address = "#{api_helper.api_repo_link}/issues"
20
20
 
21
21
  response = api_helper.send_request(request_address, multipage: true)
22
22
  issue_class = Struct.new(:number, :title, :link)
@@ -37,8 +37,7 @@ module Geet
37
37
  end
38
38
  end
39
39
 
40
- def initialize(repository, issue_number, api_helper)
41
- @repository = repository
40
+ def initialize(issue_number, api_helper)
42
41
  @issue_number = issue_number
43
42
  @api_helper = api_helper
44
43
  end
@@ -48,14 +47,14 @@ module Geet
48
47
  #
49
48
  def assign_user(users)
50
49
  request_data = { assignees: Array(users) }
51
- request_address = "#{@api_helper.repo_link}/issues/#{@issue_number}/assignees"
50
+ request_address = "#{@api_helper.api_repo_link}/issues/#{@issue_number}/assignees"
52
51
 
53
52
  @api_helper.send_request(request_address, data: request_data)
54
53
  end
55
54
 
56
55
  def add_labels(labels)
57
56
  request_data = labels
58
- request_address = "#{@api_helper.repo_link}/issues/#{@issue_number}/labels"
57
+ request_address = "#{@api_helper.api_repo_link}/issues/#{@issue_number}/labels"
59
58
 
60
59
  @api_helper.send_request(request_address, data: request_data)
61
60
  end
@@ -8,19 +8,27 @@ require 'shellwords'
8
8
  module Geet
9
9
  module GitHub
10
10
  class ApiHelper
11
- def initialize(api_token, user, owner, repo)
11
+ def initialize(api_token, user, repository_path, upstream)
12
12
  @api_token = api_token
13
13
  @user = user
14
- @owner = owner
15
- @repo = repo
14
+ @repository_path = repository_path
15
+ @upstream = upstream
16
16
  end
17
17
 
18
- def base_link
18
+ def api_base_link
19
19
  "https://api.github.com"
20
20
  end
21
21
 
22
+ def api_repo_link
23
+ "#{api_base_link}/repos/#{@repository_path}"
24
+ end
25
+
22
26
  def repo_link
23
- "#{base_link}/repos/#{@owner}/#{@repo}"
27
+ "https://github.com/#{@repository_path}"
28
+ end
29
+
30
+ def upstream?
31
+ @upstream
24
32
  end
25
33
 
26
34
  # Send a request.
@@ -6,7 +6,7 @@ module Geet
6
6
  module GitHub
7
7
  class Gist
8
8
  def self.create(repository, filename, content, api_helper, description: nil, publik: false)
9
- request_address = "#{api_helper.base_link}/gists"
9
+ request_address = "#{api_helper.api_base_link}/gists"
10
10
  request_data = prepare_request_data(filename, content, description, publik)
11
11
 
12
12
  response = api_helper.send_request(request_address, data: request_data)
@@ -6,18 +6,18 @@ module Geet
6
6
  module GitHub
7
7
  class Issue < AbstractIssue
8
8
  def self.create(repository, title, description, api_helper)
9
- request_address = "#{api_helper.repo_link}/issues"
9
+ request_address = "#{api_helper.api_repo_link}/issues"
10
10
  request_data = { title: title, body: description, base: 'master' }
11
11
 
12
12
  response = api_helper.send_request(request_address, data: request_data)
13
13
 
14
14
  issue_number = response.fetch('number')
15
15
 
16
- new(repository, issue_number, api_helper)
16
+ new(issue_number, api_helper)
17
17
  end
18
18
 
19
19
  def link
20
- "https://github.com/#{@repository.owner}/#{@repository.repo}/issues/#{@issue_number}"
20
+ "#{@api_helper.repo_link}/issues/#{@issue_number}"
21
21
  end
22
22
  end
23
23
  end
@@ -6,23 +6,25 @@ module Geet
6
6
  module GitHub
7
7
  class PR < AbstractIssue
8
8
  def self.create(repository, title, description, head, api_helper)
9
- request_address = "#{api_helper.repo_link}/pulls"
9
+ request_address = "#{api_helper.api_repo_link}/pulls"
10
+
11
+ head = "#{repository.authenticated_user}:#{head}" if api_helper.upstream?
10
12
  request_data = { title: title, body: description, head: head, base: 'master' }
11
13
 
12
14
  response = api_helper.send_request(request_address, data: request_data)
13
15
 
14
16
  issue_number = response.fetch('number')
15
17
 
16
- new(repository, issue_number, api_helper)
18
+ new(issue_number, api_helper)
17
19
  end
18
20
 
19
21
  def link
20
- "https://github.com/#{@repository.owner}/#{@repository.repo}/pull/#{@issue_number}"
22
+ "#{@api_helper.repo_link}/pull/#{@issue_number}"
21
23
  end
22
24
 
23
25
  def request_review(reviewers)
24
26
  request_data = { reviewers: reviewers }
25
- request_address = "#{@api_helper.repo_link}/pulls/#{@issue_number}/requested_reviewers"
27
+ request_address = "#{@api_helper.api_repo_link}/pulls/#{@issue_number}/requested_reviewers"
26
28
 
27
29
  @api_helper.send_request(request_address, data: request_data)
28
30
  end
@@ -14,14 +14,14 @@ module Geet
14
14
  end
15
15
 
16
16
  def collaborators
17
- url = "https://api.github.com/repos/#{@local_repository.owner}/#{@local_repository.repo}/collaborators"
17
+ url = "#{@api_helper.api_repo_link}/collaborators"
18
18
  response = @api_helper.send_request(url, multipage: true)
19
19
 
20
20
  response.map { |user_entry| user_entry.fetch('login') }
21
21
  end
22
22
 
23
23
  def labels
24
- url = "https://api.github.com/repos/#{@local_repository.owner}/#{@local_repository.repo}/labels"
24
+ url = "#{@api_helper.api_repo_link}/labels"
25
25
  response = @api_helper.send_request(url, multipage: true)
26
26
 
27
27
  response.map { |label_entry| label_entry['name'] }
@@ -36,15 +36,15 @@ module Geet
36
36
  end
37
37
 
38
38
  def list_issues
39
- Geet::GitHub::AbstractIssue.list(@local_repository, @api_helper, filter: :issue)
39
+ Geet::GitHub::AbstractIssue.list(@api_helper, filter: :issue)
40
40
  end
41
41
 
42
- def create_pr(title, description, head: @local_repository.current_head)
42
+ def create_pr(title, description, head)
43
43
  Geet::GitHub::PR.create(@local_repository, title, description, head, @api_helper)
44
44
  end
45
45
 
46
46
  def list_prs
47
- Geet::GitHub::AbstractIssue.list(@local_repository, @api_helper, filter: :pr)
47
+ Geet::GitHub::AbstractIssue.list(@api_helper, filter: :pr)
48
48
  end
49
49
  end
50
50
  end
@@ -26,22 +26,26 @@ module Geet
26
26
  ['-n', '--no-open-issue', "Don't open the issue link in the browser after creation"],
27
27
  ['-l', '--label-patterns "bug,help wanted"', 'Label patterns'],
28
28
  ['-a', '--assignee-patterns john,tom,adrian,kevin', 'Assignee login patterns. Defaults to authenticated user'],
29
+ ['-u', '--upstream', 'Create on the upstream repository'],
29
30
  'title',
30
31
  'description'
31
32
  ].freeze
32
33
 
33
34
  ISSUE_LIST_OPTIONS = [
35
+ ['-u', '--upstream', 'List on the upstream repository'],
34
36
  ].freeze
35
37
 
36
38
  PR_CREATE_OPTIONS = [
37
39
  ['-n', '--no-open-pr', "Don't open the PR link in the browser after creation"],
38
40
  ['-l', '--label-patterns "legacy,code review"', 'Label patterns'],
39
41
  ['-r', '--reviewer-patterns john,tom,adrian,kevin', 'Reviewer login patterns'],
42
+ ['-u', '--upstream', 'Create on the upstream repository'],
40
43
  'title',
41
44
  'description'
42
45
  ].freeze
43
46
 
44
47
  PR_LIST_OPTIONS = [
48
+ ['-u', '--upstream', 'List on the upstream repository'],
45
49
  ].freeze
46
50
 
47
51
  # Public interface
@@ -30,7 +30,7 @@ module Geet
30
30
 
31
31
  puts 'Creating PR...'
32
32
 
33
- pr = repository.create_pr(title, description)
33
+ pr = repository.create_pr(title, description, repository.current_head)
34
34
 
35
35
  puts 'Assigning authenticated user...'
36
36
 
data/lib/geet/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Geet
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Saverio Miroddi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-26 00:00:00.000000000 Z
11
+ date: 2017-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simple_scripting