gl 0.3.1 → 0.4.0

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
  SHA256:
3
- metadata.gz: 85f487df6edced1c8dd32945ff67087d368cb20939a4106fab5fb08922482b4c
4
- data.tar.gz: 25188a4405e2a305c1ef6c35254a56e5e44b65106f9d38e011ff650a8f027a87
3
+ metadata.gz: dd4f959f120be84fffe69fcab73589c752645bcf380e5d489bbdeee74f979fa1
4
+ data.tar.gz: 8d627f1d6bd8bda3645f57ccefea0c2de35d275deaeb9317ee300bcb6df798ed
5
5
  SHA512:
6
- metadata.gz: ede46461e79ffeae427e1e25b3a74af2edd9ca9dd887dd3d047709c853ea832bf65d9435e49e74ec8e3885f2e970049fe33f39f3ddc7f4966fe78fec5441b51e
7
- data.tar.gz: 11e7ee7b46f33f7142880702ce33340a98a09f11939d342ea7e81c3a23915659210c747539dc3d489ed49ad286f308aa1346e7a166bbad94e79c83aca3142751
6
+ metadata.gz: e7d77af2ee3236e7db33a49ac1808d7c32e93dbcb1715e24329ec6300faab1670c4a5e1dbbfc720ac26166a4018ada46b80b59f74053952dae7634a43c359fe0
7
+ data.tar.gz: 56e18bab0459050cf6fa4258fb1850ee9f1f0665fae1c87cd448d38ed6891ee5d3881592a482c4223607202439fbfa7f79a0e67d5ebc70c39760052ca3916862
@@ -1,21 +1,26 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2019-08-19 16:08:47 +0200 using RuboCop version 0.74.0.
3
+ # on 2019-08-21 14:37:45 +0200 using RuboCop version 0.74.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 1
9
+ # Offense count: 2
10
10
  Lint/ShadowingOuterLocalVariable:
11
11
  Exclude:
12
12
  - 'lib/gl/cli/registry.rb'
13
13
 
14
- # Offense count: 4
14
+ # Offense count: 5
15
15
  Metrics/AbcSize:
16
16
  Max: 48
17
17
 
18
- # Offense count: 5
18
+ # Offense count: 1
19
+ # Configuration parameters: CountComments.
20
+ Metrics/ClassLength:
21
+ Max: 113
22
+
23
+ # Offense count: 7
19
24
  # Configuration parameters: CountComments, ExcludedMethods.
20
25
  Metrics/MethodLength:
21
26
  Max: 35
@@ -1,11 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gl (0.2.1)
4
+ gl (0.3.1)
5
5
  gitlab (~> 4.12)
6
6
  thor (~> 0.20.3)
7
+ tty-box
7
8
  tty-progressbar (~> 0.17.0)
8
9
  tty-prompt (~> 0.19.0)
10
+ tty-screen
9
11
  tty-spinner (~> 0.9.1)
10
12
  tty-table (~> 0.11.0)
11
13
 
@@ -50,6 +52,10 @@ GEM
50
52
  terminal-table (1.8.0)
51
53
  unicode-display_width (~> 1.1, >= 1.1.1)
52
54
  thor (0.20.3)
55
+ tty-box (0.4.0)
56
+ pastel (~> 0.7.2)
57
+ strings (~> 0.1.5)
58
+ tty-cursor (~> 0.7)
53
59
  tty-color (0.5.0)
54
60
  tty-cursor (0.7.0)
55
61
  tty-progressbar (0.17.0)
data/README.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Gl
2
2
 
3
+ - [Gl](#gl)
4
+ * [Installation](#installation)
5
+ * [Usage](#usage)
6
+ + [Issues](#issues)
7
+ - [List](#list)
8
+ - [Open](#open)
9
+ + [Merge Requests](#merge-requests)
10
+ - [Interactive](#interactive)
11
+ - [List](#list-1)
12
+ - [Open](#open-1)
13
+ - [Approve](#approve)
14
+ - [Merge](#merge)
15
+ + [Registry](#registry)
16
+ * [Development](#development)
17
+ * [Contributing](#contributing)
18
+ * [License](#license)
19
+
3
20
  Gl is a small CLI that hooks into your Git config and GitLab API to easily access information based
4
21
  on the project your are currently in.
5
22
 
@@ -22,6 +39,8 @@ Commands:
22
39
  gl registry # handle registry of the project
23
40
  ```
24
41
 
42
+ ### Issues
43
+ #### List
25
44
  ```bash
26
45
  $ gl issues list
27
46
 
@@ -34,23 +53,7 @@ $ gl issues list
34
53
  | 33 | XXXXXXXXXXXXXX | XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
35
54
  +-----+----------------+-------------------------------------------------------------------------------+
36
55
  ```
37
-
38
- ```bash
39
- $ gl mr list
40
-
41
- +-----+--------------+-------------------------------------------------------------------------------+
42
- | IID | Author | Title |
43
- +-----+--------------+-------------------------------------------------------------------------------+
44
- | 268 | XXXXXXXXXXXX | XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
45
- | 264 | XXXXXXXXXXXX | XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
46
- | 217 | XXXXXXXXXXXX | XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
47
- | 213 | XXXXXXXXXXXX | XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
48
- | 188 | XXXXXXXXXXXX | XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
49
- +-----+--------------+-------------------------------------------------------------------------------+
50
- ```
51
-
52
- Both commands offer a interactive switch which opens the selected merge request/issue after selecting:
53
-
56
+ With interactive switch
54
57
  ```bash
55
58
  $ gl issues list -i
56
59
 
@@ -62,15 +65,73 @@ Open a issue (Use ↑/↓ and ←/→ arrow keys, press Enter to select)
62
65
  405 - XXXXXXXXXXXX - XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
63
66
  404 - XXXXXXXXXXXX - XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
64
67
  ```
68
+ #### Open
69
+ Open a issue directly with the IID or viathe interactive list
70
+ ```bash
71
+ $ gl issue open 409
72
+ ```
65
73
 
66
- Your can also directly open an issue or merge request with a IID:
74
+ ### Merge Requests
75
+ #### Interactive
76
+ ```bash
77
+ $ gl mr list -i
67
78
 
79
+ Select a merge request (Use ↑/↓ arrow keys, press Enter to select, and letter keys to filter)
80
+ ‣ 2 - robert.mueller - WIP: Update README.md
81
+ ```
82
+
83
+ In interactive mode you can also perform all the other actions
68
84
  ```bash
69
- $ gl issue open 409
70
- # or
71
- $ gl mr open 213
85
+ $ gl mr list -i
86
+
87
+ Select a merge request 2 - robert.mueller - WIP: Update README.md
88
+ ┌────────────────────────────────────────WIP: Update README.md─────────────────────────────────────────┐
89
+ │ │
90
+ │ # Nec verum procul trahuntur velle │
91
+ │ │
92
+ │ ## Foedantem blandis malorum mox │
93
+ │ │
94
+ │ chipsetMyspace.perlUltra.font_document(iscsiStandbyPermalink( │
95
+ │ computing_mac_modem, streamingSli)); │
96
+ │ address_operating = 40 + binComputingTransistor + rw * minimize; │
97
+ │ wired(-1, qbe_export); │
98
+ │ │
99
+ └State: opened────────────────────────────────────────────────────────────────────────by robert.mueller┘
100
+ What to do next? (Use ↑/↓ arrow keys, press Enter to select)
101
+ ‣ open
102
+ merge
103
+ approve
104
+ exit
105
+
106
+ ```
107
+
108
+ #### List
109
+ ```bash
110
+ $ gl mr list
111
+
112
+ +-----+----------------+-----------------------+
113
+ | IID | Author | Title |
114
+ +-----+----------------+-----------------------+
115
+ | 2 | robert.mueller | WIP: Update README.md |
116
+ +-----+----------------+-----------------------+
117
+ ```
118
+
119
+ #### Open
120
+ ```bash
121
+ $ gl mr open 2
122
+ ```
123
+
124
+ #### Approve
125
+ ```bash
126
+ $ gl mr approve 2
127
+ ```
128
+
129
+ #### Merge
130
+ ```bash
131
+ $ gl mr merge 2
72
132
  ```
73
133
 
134
+ ### Registry
74
135
  With the registry subcommand you can get a overview about the registry usage.
75
136
 
76
137
  ```bash
data/gl.gemspec CHANGED
@@ -30,8 +30,10 @@ Gem::Specification.new do |spec|
30
30
 
31
31
  spec.add_dependency 'gitlab', '~> 4.12'
32
32
  spec.add_dependency 'thor', '~> 0.20.3'
33
+ spec.add_dependency 'tty-box'
33
34
  spec.add_dependency 'tty-progressbar', '~> 0.17.0'
34
35
  spec.add_dependency 'tty-prompt', '~> 0.19.0'
36
+ spec.add_dependency 'tty-screen'
35
37
  spec.add_dependency 'tty-spinner', '~> 0.9.1'
36
38
  spec.add_dependency 'tty-table', '~> 0.11.0'
37
39
 
data/lib/gl.rb CHANGED
@@ -6,6 +6,8 @@ require 'tty-spinner'
6
6
  require 'tty-progressbar'
7
7
  require 'tty-table'
8
8
  require 'tty-prompt'
9
+ require 'tty-box'
10
+ require 'tty-screen'
9
11
 
10
12
  require 'gl/cli'
11
13
 
@@ -5,20 +5,9 @@ module Gl
5
5
  desc 'list', 'list open issues'
6
6
  option :i
7
7
  def list(project = nil)
8
- issues = Gitlab.issues(Gl.current_project(project), state: :opened).auto_paginate
9
-
10
- issues_list = issues.map do |issue|
11
- [issue.iid, issue.author.name, issue.title]
12
- end
13
-
14
8
  if options[:i]
15
- prompt = TTY::Prompt.new(interrupt: :exit)
16
- choice = prompt.select('Open a issue') do |menu|
17
- issues_list.each do |issue|
18
- menu.choice issue.join(' - '), issue[0]
19
- end
20
- end
21
- Gl.open_in_browser("#{Gl.current_project}/issues/#{choice}")
9
+ id = issue_dialogue(project)
10
+ Gl.open_in_browser("#{Gl.current_project}/issues/#{id}")
22
11
  else
23
12
  table = TTY::Table.new(%w[IID Author Title],
24
13
  issues_list)
@@ -30,5 +19,49 @@ module Gl
30
19
  def open(id = nil)
31
20
  Gl.open_in_browser("#{Gl.current_project}/issues/#{id}")
32
21
  end
22
+
23
+ desc 'label', 'add a label to an issue'
24
+ def label(label)
25
+ label_action(label)
26
+ end
27
+
28
+ desc 'unlabel', 'remove a label from an issue'
29
+ def unlabel(label)
30
+ label_action(label)
31
+ end
32
+
33
+ private
34
+
35
+ def label_action(label)
36
+ id = issue_dialogue
37
+ action = caller_locations(1, 1)[0].label
38
+
39
+ begin
40
+ Gitlab.create_issue_note(Gl.current_project,
41
+ id,
42
+ "/#{action} ~\"#{label}\"")
43
+ rescue Gitlab::Error::BadRequest
44
+ true
45
+ end
46
+ end
47
+
48
+ def issue_dialogue(project = nil)
49
+ prompt = TTY::Prompt.new(interrupt: :exit)
50
+ prompt.select('Open a issue', filter: true) do |menu|
51
+ issues_list(project).each do |issue|
52
+ menu.choice issue.join(' - '), issue[0]
53
+ end
54
+ end
55
+ end
56
+
57
+ def issues_list(project)
58
+ @issues_list ||= begin
59
+ issues = Gitlab.issues(Gl.current_project(project), state: :opened).auto_paginate
60
+
61
+ issues.map do |issue|
62
+ [issue.iid, issue.author.name, issue.title]
63
+ end
64
+ end
65
+ end
33
66
  end
34
67
  end
@@ -7,7 +7,32 @@ module Gl
7
7
  def list(project = nil)
8
8
  if options[:i]
9
9
  id = merge_request_dialogue(project)
10
- Gl.open_in_browser("#{Gl.current_project}/merge_requests/#{id}")
10
+ mr = merge_requests.select { |merge_request| merge_request.iid == id.to_i }.first
11
+ box = TTY::Box.frame(
12
+ width: TTY::Screen.width,
13
+ height: mr.description.lines.count + 4,
14
+ padding: 1,
15
+ title: { top_center: mr.title[0..TTY::Screen.width - 3],
16
+ bottom_left: "State: #{mr.state}",
17
+ bottom_right: "by #{mr.author.name}" }
18
+ ) do
19
+ mr.description
20
+ end
21
+ puts box
22
+
23
+ choice = TTY::Prompt.new(interrupt: :exit).select('What to do next?') do |menu|
24
+ menu.choice :open
25
+ menu.choice :merge
26
+ menu.choice :approve
27
+ menu.choice :exit
28
+ end
29
+
30
+ case choice.to_sym
31
+ when :open then open_mr_in_browser(mr.iid)
32
+ when :merge then merge(mr.iid)
33
+ when :approve then approve(mr.iid)
34
+ when :exit then exit
35
+ end
11
36
  else
12
37
  table = TTY::Table.new(%w[IID Author Title],
13
38
  merge_requests_list(project))
@@ -15,44 +40,94 @@ module Gl
15
40
  end
16
41
  end
17
42
 
43
+ desc 'approve', 'approves a merge request'
44
+ def approve(iid = nil)
45
+ iid ||= merge_request_dialogue
46
+ begin
47
+ Gitlab.approve_merge_request(Gl.current_project, iid)
48
+ rescue Gitlab::Error::Unauthorized
49
+ TTY::Prompt.new.error('Unable to approve merge request')
50
+ end
51
+ end
52
+
18
53
  desc 'open', 'opens the merge request overview in your browser'
19
- def open(id = nil)
20
- Gl.open_in_browser("#{Gl.current_project}/merge_requests/#{id}")
54
+ def open(iid = nil)
55
+ open_mr_in_browser(iid)
56
+ end
57
+
58
+ desc 'label', 'add a label to a merge request'
59
+ def label(label)
60
+ label_action(label)
61
+ end
62
+
63
+ desc 'unlabel', 'remove a label from a merge request'
64
+ def unlabel(label)
65
+ label_action(label)
21
66
  end
22
67
 
23
- desc 'ready', 'marks a merge request as reviewable'
24
- def ready(id = nil)
25
- id ||= merge_request_dialogue
68
+ desc 'merge', 'accept a merge request'
69
+ method_option 'delete-branch', type: :boolean, default: true, desc: 'Delete branch after merge'
70
+ method_option 'squash', type: :boolean, default: false, desc: 'Squash commits'
71
+ def merge(iid = nil)
72
+ iid ||= merge_request_dialogue.split(' - ')[0]
73
+ Gitlab.accept_merge_request(Gl.current_project,
74
+ iid,
75
+ squash: options['squash'],
76
+ should_remove_source_branch: options['delete-branch'])
77
+ rescue Gitlab::Error::MethodNotAllowed => e
78
+ TTY::Prompt.new.error(
79
+ case e.response_status
80
+ when 405
81
+ 'Unable to accept merge request ' \
82
+ '(ie: Work in Progress, Closed, Pipeline Pending Completion, ' \
83
+ 'or Failed while requiring Success)'
84
+ else
85
+ "Could not merge due to unknown error: #{e.response_status}"
86
+ end
87
+ )
88
+ end
89
+
90
+ private
91
+
92
+ def open_mr_in_browser(iid)
93
+ Gl.open_in_browser("#{Gl.current_project}/merge_requests/#{iid}")
94
+ end
95
+
96
+ def label_action(label)
97
+ id = merge_request_dialogue
98
+ action = caller_locations(1, 1)[0].label
26
99
 
27
100
  begin
28
101
  Gitlab.create_merge_request_note(Gl.current_project,
29
102
  id,
30
- '/label ~"Status::Reviewable"')
103
+ "/#{action} ~\"#{label}\"")
31
104
  rescue Gitlab::Error::BadRequest
32
105
  true
33
106
  end
34
107
  end
35
108
 
36
- private
37
-
38
109
  def merge_request_dialogue(project = nil)
39
110
  prompt = TTY::Prompt.new(interrupt: :exit)
40
- prompt.select('Select a merge request') do |menu|
111
+ prompt.select('Select a merge request', filter: true) do |menu|
41
112
  merge_requests_list(project).each do |merge_request|
42
113
  menu.choice merge_request.join(' - '), merge_request[0]
43
114
  end
44
115
  end
45
116
  end
46
117
 
47
- def merge_requests_list(project)
118
+ def merge_requests_list(project = nil)
48
119
  @merge_requests_list ||= begin
49
- merge_requests = Gitlab.merge_requests(Gl.current_project(project),
50
- state: :opened).auto_paginate
51
-
52
- merge_requests.map do |mr|
120
+ merge_requests(project).map do |mr|
53
121
  [mr.iid, mr.author.name, mr.title]
54
122
  end
55
123
  end
56
124
  end
125
+
126
+ def merge_requests(project = nil)
127
+ @merge_requests ||= begin
128
+ Gitlab.merge_requests(Gl.current_project(project),
129
+ state: :opened).auto_paginate
130
+ end
131
+ end
57
132
  end
58
133
  end
@@ -43,7 +43,6 @@ module Gl
43
43
  rescue Gitlab::Error::NotFound
44
44
  next
45
45
  end
46
-
47
46
  end
48
47
  end
49
48
  puts table.render(:ascii, alignments: %i[left right], padding: [0, 1])
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gl
4
- VERSION = '0.3.1'
4
+ VERSION = '0.4.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Flipez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-19 00:00:00.000000000 Z
11
+ date: 2019-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gitlab
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.20.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: tty-box
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: tty-progressbar
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +80,20 @@ dependencies:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
82
  version: 0.19.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: tty-screen
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: tty-spinner
71
99
  requirement: !ruby/object:Gem::Requirement