ninny 0.1.11 → 0.1.16

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: cbd94550d42dd1d2280ae1838482dc22f67ec5abaea0abacdf57feccc6fedc23
4
- data.tar.gz: 5801551978e1805825178d2544f3bd94554bf944f1e095b35f8448a7ed9e1ad5
3
+ metadata.gz: bfe22d54de55ad35cadc8f09b93881bd16ac92ff5717e2e222edc2a0fb796500
4
+ data.tar.gz: 23f0cbd70bac15210175e225f2398e2f68e564f1a0204e67abbe9f7cde81460b
5
5
  SHA512:
6
- metadata.gz: 53df5cd87f9193a26bb0976bf4bf0efbcb10a1e2c4e6c6cc25a1381ae11ad69f8279f60fcc05848f0127e19982d08a7505f2c7e49b9b62a785af957a6a717b11
7
- data.tar.gz: a9534c205c2f24cab166a80795e11038040afa0bac73592da8af8d4762a1bd820224d39b1a85fb7930b5c1e637d6f24ce9d3c0e6032ca7d78c7aba3a6c014a38
6
+ metadata.gz: d064e91bf67d2297b3f370b62218014137e6795f0289dc42d9f3f98b864aebc9267ff6edbc9e90b239c4e2c793ea1e3387290e092bdf3b1bfe694e0363d072be
7
+ data.tar.gz: 4aed2da31e91acc83f00b8347b6e992898120a722940b8a873eb86562a0bd4d9f3170ade9855630ec8d0fa8642cc13383ae531a3cd3fba0d827a07a553336d1f
@@ -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.3, 2.6.6, 2.7.0, 2.7.2, 3.0.0]
15
15
  steps:
16
16
  - uses: actions/checkout@v2
17
17
  with:
@@ -0,0 +1,49 @@
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: 2.7.2
17
+ bundler: 1.17.3
18
+ bundler-cache: true
19
+ - run: |
20
+ gem install bundler-audit
21
+ bundler-audit update
22
+ bundler-audit
23
+
24
+ if [ $? -eq 0 ]; then
25
+ echo "No vulnerabilities found."
26
+ else
27
+ echo "Gem vulnerabilities found!"
28
+ exit 1
29
+ fi
30
+ bundle-outdated:
31
+ runs-on: ubuntu-latest
32
+ steps:
33
+ - uses: actions/checkout@v2
34
+ with:
35
+ fetch-depth: 0
36
+ - uses: ruby/setup-ruby@v1
37
+ with:
38
+ ruby-version: 2.7.2
39
+ bundler: 1.17.3
40
+ bundler-cache: true
41
+ - run: |
42
+ bundle outdated --strict
43
+
44
+ if [ $? -eq 0 ]; then
45
+ echo "No outdated gems found."
46
+ else
47
+ echo "Outdated gems found!"
48
+ exit 1
49
+ fi
data/.rubocop.yml CHANGED
@@ -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/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)).
@@ -83,7 +89,7 @@ At any point, `ninny help` will show the help screen.
83
89
  * Run `bundle exec guard` to run tests continuously as you develop
84
90
  6. Test the gem locally
85
91
  * Run `gem build *.gemspec` to build the gem locally
86
- * Run `gem install --local ninny-x.x.x.gem` to install the gem locally
92
+ * Run `gem install --local ninny-X.X.X.gem` to install the gem locally
87
93
  7. Make a pull request back to this repository
88
94
 
89
95
  ### Releasing
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,12 +31,18 @@ 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
 
36
43
  # Public: Check out the branch
37
44
  def check_out_branch
45
+ prompt.say "Checking out #{branch_to_merge_into}."
38
46
  Ninny.git.check_out(branch_to_merge_into, false)
39
47
  Ninny.git.track_current_branch
40
48
  rescue Ninny::Git::NoBranchOfType
@@ -44,6 +52,7 @@ module Ninny
44
52
 
45
53
  # Public: Merge the pull request's branch into the checked-out branch
46
54
  def merge_pull_request
55
+ prompt.say "Merging #{pull_request.branch} to #{branch_to_merge_into}."
47
56
  Ninny.git.merge(pull_request.branch)
48
57
  end
49
58
 
@@ -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
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.11'
4
+ VERSION = '0.1.16'
5
5
  end
data/ninny.gemspec CHANGED
@@ -27,13 +27,13 @@ Gem::Specification.new do |spec|
27
27
 
28
28
  spec.add_dependency 'git', '~> 1.5.0'
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
38
  spec.add_development_dependency 'bundler', '~> 1.17'
39
39
  spec.add_development_dependency 'byebug', '~> 11.1'
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.11
4
+ version: 0.1.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dispatch Engineers
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-02 00:00:00.000000000 Z
11
+ date: 2021-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git
@@ -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,42 +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
138
+ version: '0.23'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: bundler
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -286,6 +286,7 @@ extra_rdoc_files: []
286
286
  files:
287
287
  - ".github/pull_request_template.md"
288
288
  - ".github/workflows/main.yml"
289
+ - ".github/workflows/scheduled.yml"
289
290
  - ".gitignore"
290
291
  - ".rspec"
291
292
  - ".rubocop.yml"