ninny 0.1.12 → 0.1.17

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: df20c749d0ff68d76160dd8c49af839c0d5bca44b2bc843c6869c54847d6cd2a
4
- data.tar.gz: fd04479d94849368b53d539ad1f3084e024c90d4a89d879787213dc5fd5de9a9
3
+ metadata.gz: 911ed6720d5cd72ff5afd2b8a12e3ef1ab98aeb325cc5ddf39db0f3c9ff2fca5
4
+ data.tar.gz: 9f490c34b1e2c5a090e78b4985aa5a53b02e2d788552f51512a7ed8b9ab6fe51
5
5
  SHA512:
6
- metadata.gz: 7882708a164cfc52316f496f26c7203458d39c996d155a67b5fc8afedb58a9b9d60a9b44badc97ba4860815c497017ac1e47cc7dcbdd4fd89b24e4d9e3e7162c
7
- data.tar.gz: 954e986c09b28bc6ce678fb7a88ff04f872f212ce71c8637699342eb683229b28286ba50dc32b9523ca43dbee59cece29e9ad06546fe27f600712b479a70fd3b
6
+ metadata.gz: e0d3d5d823fd4d7856e0a3972ede2cd5c15eb1cfb60b8d95a6257d9a1c6ecee91d259289fcc71c09733b4f0220b545d0655f944934e8a41f627107a02e6c5cb8
7
+ data.tar.gz: c9a8bc0909bd2b2befb51fce77da37316b728bf79bb34aea68e655f3b2dbaad72faabee748b32f18df04f5420059f38d397fc41df6d415a795eb115fe28ea927
@@ -11,7 +11,7 @@ jobs:
11
11
  strategy:
12
12
  fail-fast: false
13
13
  matrix:
14
- ruby: [2.6.3, 2.6.6, 2.7.0, 2.7.2]
14
+ ruby: [2.6, 2.7, 3.0]
15
15
  steps:
16
16
  - uses: actions/checkout@v2
17
17
  with:
@@ -19,7 +19,6 @@ jobs:
19
19
  - uses: ruby/setup-ruby@v1
20
20
  with:
21
21
  ruby-version: ${{ matrix.ruby }}
22
- bundler: 1.17.3
23
22
  bundler-cache: true
24
23
  - run: bundle exec rake
25
24
  pronto:
@@ -0,0 +1,47 @@
1
+ name: Scheduled
2
+ on:
3
+ schedule:
4
+ - cron: "0 4 * * 1" # 4am UTC on Mondays (10pm/11pm CT on Sundays)
5
+
6
+ jobs:
7
+ bundler-audit:
8
+ if:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v2
12
+ with:
13
+ fetch-depth: 0
14
+ - uses: ruby/setup-ruby@v1
15
+ with:
16
+ ruby-version: 3.0
17
+ bundler-cache: true
18
+ - run: |
19
+ gem install bundler-audit
20
+ bundler-audit update
21
+ bundler-audit
22
+
23
+ if [ $? -eq 0 ]; then
24
+ echo "No vulnerabilities found."
25
+ else
26
+ echo "Gem vulnerabilities found!"
27
+ exit 1
28
+ fi
29
+ bundle-outdated:
30
+ runs-on: ubuntu-latest
31
+ steps:
32
+ - uses: actions/checkout@v2
33
+ with:
34
+ fetch-depth: 0
35
+ - uses: ruby/setup-ruby@v1
36
+ with:
37
+ ruby-version: 3.0
38
+ bundler-cache: true
39
+ - run: |
40
+ bundle outdated --strict
41
+
42
+ if [ $? -eq 0 ]; then
43
+ echo "No outdated gems found."
44
+ else
45
+ echo "Outdated gems found!"
46
+ exit 1
47
+ fi
data/.rubocop.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  AllCops:
2
2
  NewCops: enable
3
3
  SuggestExtensions: false
4
- TargetRubyVersion: 2.7
4
+ TargetRubyVersion: 3.0
5
5
  Exclude:
6
6
  - vendor/**/*
7
7
 
@@ -11,6 +11,10 @@ Gemspec/RequiredRubyVersion:
11
11
  Style/Documentation:
12
12
  Enabled: false
13
13
 
14
+ Layout/LineLength:
15
+ Exclude:
16
+ - spec/**/*
17
+
14
18
  Lint/EmptyClass:
15
19
  Enabled: false
16
20
 
@@ -20,8 +24,22 @@ Lint/EmptyBlock:
20
24
  Lint/MissingSuper:
21
25
  Enabled: false
22
26
 
27
+ Metrics/BlockLength:
28
+ Enabled: true
29
+ Exclude:
30
+ - spec/**/*
31
+ - ninny.gemspec
32
+
23
33
  Metrics/MethodLength:
24
34
  Max: 15
25
35
 
36
+ Style/AccessModifierDeclarations:
37
+ EnforcedStyle: inline
38
+
39
+ Style/BlockDelimiters:
40
+ Enabled: true
41
+ Exclude:
42
+ - spec/**/*
43
+
26
44
  Style/OptionalBooleanParameter:
27
45
  Enabled: false
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7.2
1
+ 3.0.1
data/README.md CHANGED
@@ -42,9 +42,15 @@ Then, each developer on the project should set up a file at `~/.ninny.yml` on th
42
42
 
43
43
  ```bash
44
44
  $ ninny setup
45
- Do you have a new GitLab private token? (Y/n) y # enter 'y'
45
+ Do you have a new GitLab private token? (Y/n) Yes # enter 'y'
46
46
  Enter private token: abc123def456ghi789jk # enter your private token
47
- User config updated
47
+ User config updated!
48
+ ```
49
+
50
+ Or, you can pass the private token in as part of the command:
51
+ ```bash
52
+ $ ninny setup --token abc123def456ghi789jk # or '-t abc123def456ghi789jk' for short
53
+ User config updated!
48
54
  ```
49
55
 
50
56
  The private token should be a personal access token for that person's GitLab account (generated [here](https://gitlab.com/-/profile/personal_access_tokens)).
data/lib/ninny/cli.rb CHANGED
@@ -54,6 +54,7 @@ module Ninny
54
54
 
55
55
  desc 'setup', 'Interactively setup configuration'
56
56
  method_option :help, aliases: '-h', type: :boolean, desc: 'Display usage information'
57
+ method_option :token, aliases: '-t', type: :string, desc: 'The GitLab token to add to the ~/.ninny.yml file'
57
58
  def setup(*)
58
59
  if options[:help]
59
60
  invoke :help, ['setup']
data/lib/ninny/command.rb CHANGED
@@ -83,7 +83,7 @@ module Ninny
83
83
  # @api public
84
84
  def prompt(**options)
85
85
  require 'tty-prompt'
86
- TTY::Prompt.new(options)
86
+ TTY::Prompt.new(*options)
87
87
  end
88
88
 
89
89
  # Get terminal screen properties
@@ -13,11 +13,12 @@ module Ninny
13
13
  def execute(output: $stdout)
14
14
  create_branch
15
15
  delete_old_branches
16
- output.puts "#{branch_name} created"
16
+ output.puts "Branch #{branch_name} successfully created."
17
17
  end
18
18
 
19
19
  # Public: Create the desired branch
20
20
  def create_branch
21
+ prompt.say "Attempting to create branch #{branch_name}."
21
22
  Ninny.git.new_branch(branch_name, Ninny.project_config.deploy_branch)
22
23
  end
23
24
 
@@ -22,6 +22,8 @@ module Ninny
22
22
 
23
23
  self.pull_request_id ||= select_pull_request
24
24
 
25
+ return nil if pull_request_id.nil?
26
+
25
27
  check_out_branch
26
28
  merge_pull_request
27
29
  comment_about_merge
@@ -29,7 +31,12 @@ module Ninny
29
31
 
30
32
  def select_pull_request
31
33
  choices = Ninny.repo.open_pull_requests.map { |pr| { name: pr.title, value: pr.number } }
32
- prompt.select("Which #{Ninny.repo.pull_request_label}?", choices)
34
+
35
+ if choices.empty?
36
+ prompt.say "There don't seem to be any open merge requests."
37
+ else
38
+ prompt.select("Which #{Ninny.repo.pull_request_label}?", choices)
39
+ end
33
40
  end
34
41
  private :select_pull_request
35
42
 
@@ -5,29 +5,28 @@ require_relative '../command'
5
5
  module Ninny
6
6
  module Commands
7
7
  class Setup < Ninny::Command
8
- attr_reader :config
8
+ attr_reader :config, :private_token
9
9
 
10
10
  def initialize(options)
11
11
  @options = options
12
+ @private_token = options[:token]
12
13
  @config = Ninny.user_config
13
14
  end
14
15
 
15
16
  def execute(output: $stdout)
16
17
  try_reading_user_config
17
18
 
18
- private_token = prompt_for_gitlab_private_token
19
+ unless @private_token
20
+ @private_token = prompt_for_gitlab_private_token
19
21
 
20
- begin
21
- # TODO: This only works with thor gem < 1. So, we need to make this work when TTY
22
- # releases versions compatible with thor versions >= 1 as well.
23
- config.write(force: true)
24
- rescue StandardError
25
- puts ' Unable to write config file via TTY... continuing anyway...'
26
- File.open("#{ENV['HOME']}/.ninny.yml", 'w') do |file|
27
- file.puts "gitlab_private_token: #{private_token}"
22
+ unless @private_token
23
+ output.puts "Please create a private token on GitLab and then rerun 'ninny setup'."
24
+ return
28
25
  end
29
26
  end
30
27
 
28
+ set_response = config_set_gitlab_private_token(@private_token)
29
+ write_gitlab_private_token(@private_token, set_response)
31
30
  output.puts "User config #{@result}!"
32
31
  end
33
32
 
@@ -38,6 +37,27 @@ module Ninny
38
37
  @result = 'created'
39
38
  end
40
39
 
40
+ def config_set_gitlab_private_token(private_token)
41
+ # TODO: This only works with thor gem < 1. So, we need to make this work when TTY
42
+ # releases versions compatible with thor versions >= 1 as well.
43
+ config.set(:gitlab_private_token, value: private_token)
44
+ :success
45
+ rescue ArgumentError
46
+ puts ' Unable to set new token via TTY... continuing anyway...'
47
+ :failed
48
+ end
49
+
50
+ def write_gitlab_private_token(private_token, set_response)
51
+ raise StandardError unless set_response == :success
52
+
53
+ # TODO: This only works with thor gem < 1. So, we need to make this work when TTY
54
+ # releases versions compatible with thor versions >= 1 as well.
55
+ config.write(force: true)
56
+ rescue StandardError
57
+ puts ' Unable to write config file via TTY... continuing anyway...'
58
+ File.open("#{ENV['HOME']}/.ninny.yml", 'w') { |file| file.puts "gitlab_private_token: #{private_token}" }
59
+ end
60
+
41
61
  def prompt_for_gitlab_private_token
42
62
  begin
43
63
  new_token_text = config.gitlab_private_token ? ' new' : ''
@@ -47,17 +67,7 @@ module Ninny
47
67
 
48
68
  return unless prompt.yes?("Do you have a#{new_token_text} GitLab private token?")
49
69
 
50
- private_token = prompt.ask('Enter private token:', required: true)
51
-
52
- begin
53
- # TODO: This only works with thor gem < 1. So, we need to make this work when TTY
54
- # releases versions compatible with thor versions >= 1 as well.
55
- config.set(:gitlab_private_token, value: private_token)
56
- rescue ArgumentError
57
- puts ' Unable to set new token via TTY... continuing anyway...'
58
- end
59
-
60
- private_token
70
+ prompt.ask('Enter private token:', required: true)
61
71
  end
62
72
  end
63
73
  end
data/lib/ninny/git.rb CHANGED
@@ -38,7 +38,7 @@ module Ninny
38
38
 
39
39
  def merge(branch_name)
40
40
  if_clean do
41
- git.fetch
41
+ git.fetch('-p')
42
42
  command 'merge', ['--no-ff', "origin/#{branch_name}"]
43
43
  raise MergeFailed unless clean?
44
44
 
@@ -65,8 +65,8 @@ module Ninny
65
65
  # branch_name - The name of the branch to check out
66
66
  # do_after_pull - Should a pull be done after checkout?
67
67
  def check_out(branch, do_after_pull = true)
68
- git.fetch
69
- branch.checkout
68
+ git.fetch('-p')
69
+ git.checkout(branch)
70
70
  pull if do_after_pull
71
71
  raise CheckoutFailed, "Failed to check out '#{branch}'" unless current_branch.name == branch.name
72
72
  end
@@ -84,11 +84,20 @@ module Ninny
84
84
  # new_branch_name - The name of the branch to create
85
85
  # source_branch_name - The name of the branch to branch from
86
86
  def new_branch(new_branch_name, source_branch_name)
87
- git.fetch
88
- command('branch', ['--no-track', new_branch_name, "origin/#{source_branch_name}"])
89
- new_branch = branch(new_branch_name)
90
- new_branch.checkout
91
- command('push', ['-u', 'origin', new_branch_name])
87
+ git.fetch('-p')
88
+ remote_branches = command('branch', ['--remote'])
89
+
90
+ if remote_branches.include?("origin/#{new_branch_name}")
91
+ ask_to_recreate_branch(new_branch_name, source_branch_name)
92
+ else
93
+ create_branch(new_branch_name, source_branch_name)
94
+ end
95
+ rescue ::Git::GitExecuteError => e
96
+ if e.message.include?(':fatal: A branch named') && e.message.include?(' already exists')
97
+ puts "The local branch #{new_branch_name} already exists." \
98
+ ' Please delete it manually and then run this command again.'
99
+ exit 1
100
+ end
92
101
  end
93
102
 
94
103
  # Public: Delete the given branch
@@ -98,13 +107,17 @@ module Ninny
98
107
  branch = branch_name.is_a?(::Git::Branch) ? branch_name : git.branch(branch_name)
99
108
  git.push('origin', ":#{branch}")
100
109
  branch.delete
110
+ rescue ::Git::GitExecuteError => e
111
+ if e.message.include?(':error: branch') && e.message.include?(' not found.')
112
+ puts 'Could not delete local branch, but the remote branch was deleted.'
113
+ end
101
114
  end
102
115
 
103
116
  # Public: The list of branches on GitHub
104
117
  #
105
118
  # Returns an Array of Strings containing the branch names
106
119
  def remote_branches
107
- git.fetch
120
+ git.fetch('-p')
108
121
  git.branches.remote.map { |branch| git.branch(branch.name) }.sort_by(&:name)
109
122
  end
110
123
 
@@ -156,7 +169,31 @@ module Ninny
156
169
 
157
170
  def prompt(**options)
158
171
  require 'tty-prompt'
159
- TTY::Prompt.new(options)
172
+ TTY::Prompt.new(*options)
173
+ end
174
+
175
+ # Private: Ask the user if they wish to delete and recreate a branch
176
+ #
177
+ # new_branch_name: the name of the branch in question
178
+ # source_branch_name: the name of the branch the new branch is supposed to be based off of
179
+ private def ask_to_recreate_branch(new_branch_name, source_branch_name)
180
+ if prompt.yes?("The branch #{new_branch_name} already exists. Do you wish to delete and recreate?")
181
+ delete_branch(new_branch_name)
182
+ new_branch(new_branch_name, source_branch_name)
183
+ else
184
+ exit 1
185
+ end
186
+ end
187
+
188
+ # Private: Create a branch
189
+ #
190
+ # new_branch_name: the name of the branch in question
191
+ # source_branch_name: the name of the branch the new branch is supposed to be based off of
192
+ private def create_branch(new_branch_name, source_branch_name)
193
+ command('branch', ['--no-track', new_branch_name, "origin/#{source_branch_name}"])
194
+ new_branch = branch(new_branch_name)
195
+ new_branch.checkout
196
+ command('push', ['-u', 'origin', new_branch_name])
160
197
  end
161
198
 
162
199
  # Exceptions
@@ -17,7 +17,11 @@ module Ninny
17
17
  to_pr(
18
18
  gitlab.merge_requests(
19
19
  project_id,
20
- { source_branch: Ninny.git.current_branch.name, target_branch: Ninny.project_config.deploy_branch }
20
+ {
21
+ source_branch: Ninny.git.current_branch.name,
22
+ target_branch: Ninny.project_config.deploy_branch,
23
+ state: 'opened'
24
+ }
21
25
  ).last
22
26
  )
23
27
  end
data/lib/ninny/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ninny
4
- VERSION = '0.1.12'
4
+ VERSION = '0.1.17'
5
5
  end
data/ninny.gemspec CHANGED
@@ -25,17 +25,16 @@ Gem::Specification.new do |spec|
25
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
26
  spec.require_paths = ['lib']
27
27
 
28
- spec.add_dependency 'git', '~> 1.5.0'
28
+ spec.add_dependency 'git', '~> 1.5'
29
29
  spec.add_dependency 'gitlab', '~> 4.11'
30
- spec.add_dependency 'pastel', '~> 0.7.2'
30
+ spec.add_dependency 'pastel', '~> 0.8'
31
31
  spec.add_dependency 'thor', '< 2'
32
- spec.add_dependency 'tty-box', '~> 0.3.0'
32
+ spec.add_dependency 'tty-box', '~> 0.3'
33
33
  spec.add_dependency 'tty-color', '~> 0.4'
34
- spec.add_dependency 'tty-command', '~> 0.8.0'
35
- spec.add_dependency 'tty-config', '~> 0.3.0'
36
- spec.add_dependency 'tty-prompt', '~> 0.18.0'
34
+ spec.add_dependency 'tty-command', '~> 0.10'
35
+ spec.add_dependency 'tty-config', '~> 0.3'
36
+ spec.add_dependency 'tty-prompt', '~> 0.23'
37
37
 
38
- spec.add_development_dependency 'bundler', '~> 1.17'
39
38
  spec.add_development_dependency 'byebug', '~> 11.1'
40
39
  spec.add_development_dependency 'guard-rspec', '~> 4.3'
41
40
  spec.add_development_dependency 'pronto', '~> 0.11'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ninny
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dispatch Engineers
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-03 00:00:00.000000000 Z
11
+ date: 2021-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.5.0
19
+ version: '1.5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.5.0
26
+ version: '1.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: gitlab
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.7.2
47
+ version: '0.8'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.7.2
54
+ version: '0.8'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: thor
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.3.0
75
+ version: '0.3'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.3.0
82
+ version: '0.3'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: tty-color
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -100,56 +100,42 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 0.8.0
103
+ version: '0.10'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 0.8.0
110
+ version: '0.10'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: tty-config
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: 0.3.0
117
+ version: '0.3'
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: 0.3.0
124
+ version: '0.3'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: tty-prompt
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: 0.18.0
131
+ version: '0.23'
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: 0.18.0
139
- - !ruby/object:Gem::Dependency
140
- name: bundler
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - "~>"
144
- - !ruby/object:Gem::Version
145
- version: '1.17'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - "~>"
151
- - !ruby/object:Gem::Version
152
- version: '1.17'
138
+ version: '0.23'
153
139
  - !ruby/object:Gem::Dependency
154
140
  name: byebug
155
141
  requirement: !ruby/object:Gem::Requirement
@@ -286,6 +272,7 @@ extra_rdoc_files: []
286
272
  files:
287
273
  - ".github/pull_request_template.md"
288
274
  - ".github/workflows/main.yml"
275
+ - ".github/workflows/scheduled.yml"
289
276
  - ".gitignore"
290
277
  - ".rspec"
291
278
  - ".rubocop.yml"
@@ -324,7 +311,7 @@ homepage: https://github.com/dispatchinc/ninny
324
311
  licenses:
325
312
  - MIT
326
313
  metadata: {}
327
- post_install_message:
314
+ post_install_message:
328
315
  rdoc_options: []
329
316
  require_paths:
330
317
  - lib
@@ -339,8 +326,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
339
326
  - !ruby/object:Gem::Version
340
327
  version: '0'
341
328
  requirements: []
342
- rubygems_version: 3.1.4
343
- signing_key:
329
+ rubygems_version: 3.2.15
330
+ signing_key:
344
331
  specification_version: 4
345
332
  summary: 'ninny (n): an foolish person, see: git'
346
333
  test_files: []