ninny 0.1.14 → 0.1.18

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: 56c95a75100e8d999b3c8d8797623bf50b3b27595fa1da0a496ec0821fb43d38
4
- data.tar.gz: 20c4f576d8d81047a3aee49a45993f2021a35b020a78c5701d45da4bf02a2f52
3
+ metadata.gz: ac4912e477ddf25380dd14cbf7dad07184c9b7f002d781e781917112f45cc013
4
+ data.tar.gz: 6a144e8bd809018812ad9f441aa39db5c7853bb3e0d9224bdc50eef1d6633f78
5
5
  SHA512:
6
- metadata.gz: 5f71dfc3a85f2cfe43f576dcbf751c5b323061e098caffa16862c2afd3ae0c7b1bfb4cd036088d40723f59a7f4faeef7329df467024d16446d11f5a8b5ecd09c
7
- data.tar.gz: ae54faf5617617129f155b900cdf5491442885e654f2c731cdf38d4f8ff0f0a8ed18fb3653fadb28aba2368fe2780fda86e72b0942a7c65cad99f024b9148118
6
+ metadata.gz: 436dd448436ce48fe2658d08b3cc68b1aedbda86796c836131b8f9845af39507ff99c806f276edafeebe57799db7086ff667c17a509466ec83ab38df22d7796a
7
+ data.tar.gz: dedd4a379d28c591424f2c40e7255d1151a278f9e8d2b1df7269ee5996edeb9d26339bf4f41582907acba0d06733b16b698a12a2364295b237ea33c9e9659273
@@ -0,0 +1,33 @@
1
+ name: Build
2
+ on:
3
+ push:
4
+ branches: [ main ]
5
+ workflow_dispatch:
6
+
7
+ env:
8
+ REGISTRY: ghcr.io
9
+ IMAGE_NAME: ${{ github.repository }}
10
+
11
+ jobs:
12
+ docker-build:
13
+ runs-on: ubuntu-latest
14
+ permissions:
15
+ contents: read
16
+ packages: write
17
+ steps:
18
+ - uses: actions/checkout@v2
19
+ - uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
20
+ with:
21
+ registry: ${{ env.REGISTRY }}
22
+ username: ${{ github.actor }}
23
+ password: ${{ secrets.GITHUB_TOKEN }}
24
+ - uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
25
+ id: meta
26
+ with:
27
+ images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
28
+ - uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
29
+ with:
30
+ context: .
31
+ push: true
32
+ tags: ${{ steps.meta.outputs.tags }}
33
+ labels: ${{ steps.meta.outputs.labels }}
@@ -5,7 +5,6 @@ on:
5
5
 
6
6
  jobs:
7
7
  bundler-audit:
8
- if:
9
8
  runs-on: ubuntu-latest
10
9
  steps:
11
10
  - uses: actions/checkout@v2
@@ -13,8 +12,7 @@ jobs:
13
12
  fetch-depth: 0
14
13
  - uses: ruby/setup-ruby@v1
15
14
  with:
16
- ruby-version: 2.7.2
17
- bundler: 1.17.3
15
+ ruby-version: 3.0
18
16
  bundler-cache: true
19
17
  - run: |
20
18
  gem install bundler-audit
@@ -22,7 +20,7 @@ jobs:
22
20
  bundler-audit
23
21
 
24
22
  if [ $? -eq 0 ]; then
25
- echo "No vulnerabilities found."
23
+ echo "No gem vulnerabilities found."
26
24
  else
27
25
  echo "Gem vulnerabilities found!"
28
26
  exit 1
@@ -35,8 +33,7 @@ jobs:
35
33
  fetch-depth: 0
36
34
  - uses: ruby/setup-ruby@v1
37
35
  with:
38
- ruby-version: 2.7.2
39
- bundler: 1.17.3
36
+ ruby-version: 3.0
40
37
  bundler-cache: true
41
38
  - run: |
42
39
  bundle outdated --strict
@@ -1,4 +1,4 @@
1
- name: Main
1
+ name: Test
2
2
  on:
3
3
  push:
4
4
  branches: [ main ]
@@ -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:
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.2
data/Dockerfile ADDED
@@ -0,0 +1,3 @@
1
+ FROM ruby:3.0.2-alpine
2
+ RUN apk add git
3
+ RUN gem install ninny
data/README.md CHANGED
@@ -72,7 +72,6 @@ $ ninny staging_branch
72
72
 
73
73
  # To merge the current branch into the current/latest staging branch
74
74
  $ ninny stage_up
75
-
76
75
  ```
77
76
 
78
77
  At any point, `ninny help` will show the help screen.
data/lib/ninny/cli.rb CHANGED
@@ -31,6 +31,8 @@ module Ninny
31
31
 
32
32
  desc 'stage_up [PULL_REQUEST_ID]', 'Merges PR/MR into the staging branch'
33
33
  method_option :help, aliases: '-h', type: :boolean, desc: 'Display usage information'
34
+ method_option :username, aliases: '-u', type: :string,
35
+ desc: "The name of the user who is staging up; defaults to the local git config's user"
34
36
  def stage_up(pull_request_id = nil)
35
37
  if options[:help]
36
38
  invoke :help, ['stage_up']
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
 
@@ -6,7 +6,7 @@ module Ninny
6
6
  module Commands
7
7
  class PullRequestMerge < Ninny::Command
8
8
  attr_accessor :pull_request_id, :options, :pull_request
9
- attr_reader :branch_type
9
+ attr_reader :branch_type, :username
10
10
 
11
11
  def initialize(pull_request_id, options)
12
12
  @branch_type = options[:branch_type] || Ninny::Git::STAGING_PREFIX
@@ -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
 
@@ -58,7 +65,10 @@ module Ninny
58
65
  #
59
66
  # Returns a String
60
67
  def comment_body
61
- "Merged into #{branch_to_merge_into}."
68
+ user = username || determine_local_user
69
+ body = "Merged into #{branch_to_merge_into}".dup
70
+ body << " by #{user}" if user
71
+ body << '.'
62
72
  end
63
73
 
64
74
  # Public: Find the pull request
@@ -76,6 +86,11 @@ module Ninny
76
86
  def branch_to_merge_into
77
87
  @branch_to_merge_into ||= Ninny.git.latest_branch_for(branch_type)
78
88
  end
89
+
90
+ def determine_local_user
91
+ local_user_name = `git config user.name`.strip
92
+ local_user_name.empty? ? nil : local_user_name
93
+ end
79
94
  end
80
95
  end
81
96
  end
@@ -9,6 +9,7 @@ module Ninny
9
9
  def initialize(pull_request_id, options)
10
10
  super
11
11
  @branch_type = Ninny::Git::STAGING_PREFIX
12
+ @username = options[:username]
12
13
  end
13
14
  end
14
15
  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,7 +65,7 @@ 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
68
+ git.fetch('-p')
69
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
@@ -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.14'
4
+ VERSION = '0.1.18'
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.14
4
+ version: 0.1.18
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-10 00:00:00.000000000 Z
11
+ date: 2021-08-20 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
@@ -285,13 +271,15 @@ extensions: []
285
271
  extra_rdoc_files: []
286
272
  files:
287
273
  - ".github/pull_request_template.md"
288
- - ".github/workflows/main.yml"
274
+ - ".github/workflows/build.yml"
289
275
  - ".github/workflows/scheduled.yml"
276
+ - ".github/workflows/test.yml"
290
277
  - ".gitignore"
291
278
  - ".rspec"
292
279
  - ".rubocop.yml"
293
280
  - ".ruby-gemset"
294
281
  - ".ruby-version"
282
+ - Dockerfile
295
283
  - Gemfile
296
284
  - Guardfile
297
285
  - LICENSE.txt
@@ -340,7 +328,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
340
328
  - !ruby/object:Gem::Version
341
329
  version: '0'
342
330
  requirements: []
343
- rubygems_version: 3.1.4
331
+ rubygems_version: 3.2.22
344
332
  signing_key:
345
333
  specification_version: 4
346
334
  summary: 'ninny (n): an foolish person, see: git'