git_fonky 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0bd9807def500bd1e7286efca533211095677446bc0584da352701faff3b70a6
4
- data.tar.gz: 2a0ea855b1bd0f879eb0a565b96543841f98ae930dde9957186f43a376ddcb2e
3
+ metadata.gz: 076cf7e6f05362ab912197732e48649abffb67bfaf179cd55916fda375f26115
4
+ data.tar.gz: 2a6005c936aa4fa6b3e4d4a19eeb4de34fd836483b128dc151d78fe0c631dd75
5
5
  SHA512:
6
- metadata.gz: '0956e4742a538e2127bbd899673c4b0c02827961746e16fd7b4eb8f68e8f588a4660736269de450c6fcc73099891a6be7a9c819403cee078b757df985a28603a'
7
- data.tar.gz: 978574bcfe3da9f6195aab61c15b9254f10690400f98f12656fb95d94ce733dc2f8527e2f7d0bff8bed43c4c7f5eec13f176f2677458ab821b832dcd40191c16
6
+ metadata.gz: d6d39a6139345648528b1520806bbf782df65fda3c46f2ec9c10b52c58454819a96ca4e3da40db4c92d338e9a514373c1f7db70e2ad53cce97f9476c74cb3afe
7
+ data.tar.gz: dc39a274c029ddf4aeb00a4ccd8bc5aca0e979818bc2277969d4ee6303395de858ea5202bb1b61b76da4f55e89983f3b630c5ae5dfc20f7dcea5bf33d544c8b0
@@ -0,0 +1,13 @@
1
+ module GitFonky
2
+ class Branch
3
+ attr_reader :name
4
+
5
+ def initialize(name)
6
+ @name = name
7
+ end
8
+
9
+ def valid?(pattern = /(main|master)/)
10
+ name.match?(pattern)
11
+ end
12
+ end
13
+ end
@@ -1,10 +1,9 @@
1
1
  module GitFonky
2
2
  class Command
3
- attr_reader :repo_dir, :reporter
3
+ attr_accessor :branch_name
4
4
 
5
- def initialize(repo_dir:, reporter:)
6
- @repo_dir = repo_dir
7
- @reporter = reporter
5
+ def initialize(branch_name = nil)
6
+ @branch_name = branch_name
8
7
  end
9
8
 
10
9
  def current_branch
@@ -12,18 +11,15 @@ module GitFonky
12
11
  end
13
12
 
14
13
  def fetch_upstream
15
- reporter.announce("fetching")
16
- `git fetch upstream #{repo_dir.branch} 2>&1`
14
+ `git fetch upstream #{branch_name} 2>&1`
17
15
  end
18
16
 
19
17
  def pull_upstream
20
- reporter.announce("pulling")
21
- `git pull upstream #{repo_dir.branch} 2>&1`
18
+ `git pull upstream #{branch_name} 2>&1`
22
19
  end
23
20
 
24
21
  def push_to_origin
25
- reporter.announce("pushing", "to", "origin")
26
- `git push origin #{repo_dir.branch} 2>&1`
22
+ `git push origin #{branch_name} 2>&1`
27
23
  end
28
24
  end
29
25
  end
@@ -0,0 +1,26 @@
1
+ module GitFonky
2
+ class MessageFormatter
3
+ def message_with_border(**params)
4
+ border = calculate_border_for(params[:msg], params.delete(:border_char) { "*" })
5
+ output_border_and_msg(border: border, **params)
6
+ end
7
+
8
+ private
9
+
10
+ def calculate_border_for(msg, border_char)
11
+ border_char * (msg.length + 20)
12
+ end
13
+
14
+ def output_border_and_msg(border:, msg:, sub_msg: nil, io_stream: STDERR, warn: true)
15
+ io_stream.puts border
16
+ io_stream.puts warning_header.center(border.length) if warn
17
+ io_stream.puts msg.center(border.length)
18
+ io_stream.puts sub_msg.center(border.length) if sub_msg
19
+ io_stream.puts border
20
+ end
21
+
22
+ def warning_header
23
+ "WARNING"
24
+ end
25
+ end
26
+ end
@@ -1,37 +1,62 @@
1
- require_relative "reporter"
1
+ require_relative "branch"
2
2
  require_relative "command"
3
+ require_relative "reporter"
3
4
 
4
5
  module GitFonky
5
6
  class RepoDir
6
- attr_reader :command, :dirname, :reporter
7
+ attr_reader :branch, :command, :dirname, :reporter
7
8
 
8
- def initialize(dirname)
9
+ def initialize(dirname, command = Command, branch = Branch, reporter = Reporter)
9
10
  @dirname = dirname
10
- @reporter = Reporter.new(self)
11
- @command = Command.new(repo_dir: self, reporter: reporter)
11
+ @command = command.new
12
+ @branch = branch.new(@command.current_branch)
13
+ @command.branch_name = @branch.name
14
+ @reporter = reporter.new(@dirname, @branch.name)
12
15
  end
13
16
 
14
- def branch
15
- @branch ||= command.current_branch
17
+ def self.sync(dirname)
18
+ Dir.chdir(dirname) do
19
+ new(dirname).sync
20
+ end
16
21
  end
17
22
 
18
23
  def sync
19
- Dir.chdir dirname do
20
- reporter.announce_update
21
- return reporter.invalid_branch_msg if on_invalid_branch?
24
+ catch(:skip_repo) do
25
+ announce_sync_attempt
26
+ fetch
27
+ pull
28
+ push
29
+ announce_sync_success
30
+ end
31
+ end
22
32
 
23
- command.fetch_upstream
24
- command.pull_upstream
33
+ private
25
34
 
26
- return reporter.failed_pull_msg unless $?.success?
35
+ def announce_sync_attempt
36
+ branch.valid? ? reporter.announce_sync_attempt : throw(:skip_repo, reporter.invalid_branch_msg)
37
+ end
27
38
 
28
- command.push_to_origin
29
- reporter.announce_success
30
- end
39
+ def fetch
40
+ command.fetch_upstream
41
+ process_successful? ? reporter.announce("fetched") : throw(:skip_repo, reporter.failed_fetch_msg)
42
+ end
43
+
44
+ def pull
45
+ command.pull_upstream
46
+ process_successful? ? reporter.announce("pulled") : throw(:skip_repo, reporter.failed_pull_msg)
47
+ end
48
+
49
+ def push
50
+ command.push_to_origin
51
+ process_successful? ? reporter.announce("pushed", "to", "origin") : throw(:skip_repo, reporter.failed_push_msg)
52
+ end
53
+
54
+ def announce_sync_success
55
+ reporter.announce_sync_success
31
56
  end
32
57
 
33
- def on_invalid_branch?
34
- !branch.match?(/(main|master)/)
58
+ def process_successful?
59
+ $?.success?
35
60
  end
36
61
  end
37
62
  end
@@ -0,0 +1,3 @@
1
+ module GitFonky
2
+ REPO_NAMES = %w[gorails hatchbox-v2 jumpstart-marketing jumpstart-pro-rails noticed pay]
3
+ end
@@ -1,57 +1,51 @@
1
+ require_relative "message_formatter"
1
2
  module GitFonky
2
3
  class Reporter
3
- attr_reader :repo_dir
4
+ attr_reader :formatter, :repo_name, :repo_branch
4
5
 
5
- def initialize(repo_dir)
6
- @repo_dir = repo_dir
6
+ def initialize(repo_name, repo_branch, formatter = MessageFormatter)
7
+ @repo_name = repo_name
8
+ @repo_branch = repo_branch
9
+ @formatter = formatter.new
7
10
  end
8
11
 
9
12
  def announce(action, direction = "from", remote = "upstream")
10
- puts "-----> #{action} #{direction} #{remote} #{repo_dir.branch}"
13
+ STDERR.puts "-----> #{action} #{direction} #{remote} #{repo_branch}"
11
14
  end
12
15
 
13
- def announce_success
14
- puts "-----> Successfully updated #{repo_dir.dirname} | #{repo_dir.branch} branch"
16
+ def announce_sync_success
17
+ puts "-----> Successfully synced #{repo_name} | #{repo_branch} branch"
15
18
  end
16
19
 
17
- def announce_update
18
- msg = "Updating -> #{repo_dir.dirname} | #{repo_dir.branch} branch "
19
- border = calculate_border_for("=", msg)
20
-
21
- output_border_and_msg(border, msg, warn: false)
20
+ def announce_sync_attempt
21
+ msg = "Attempting to sync -> #{repo_name} | #{repo_branch} branch "
22
+ formatter.message_with_border(msg: msg, border_char: "=", warn: false)
22
23
  end
23
24
 
24
25
  def invalid_branch_msg
25
26
  msg = "You are not on the main/master branch. Please checkout the main/master branch and try again."
26
- sub_msg = "-----> skipping #{repo_dir.dirname} | #{repo_dir.branch} branch <-----"
27
- border = calculate_border_for("*", msg)
28
-
29
- output_border_and_msg(border, msg, sub_msg)
27
+ sub_msg = "-----> skipping #{repo_name} | #{repo_branch} branch <-----"
28
+ formatter.message_with_border(msg: msg, sub_msg: sub_msg)
30
29
  end
31
30
 
32
- def failed_pull_msg
33
- msg = "-----> Failed to pull upstream #{branch}. Moving on to next repo. <-----"
34
- border = calculate_border_for(msg, "*")
35
-
36
- output_border_and_msg(border, msg)
31
+ def failed_fetch_msg
32
+ msg = "-----> Failed to fetch from upstream #{repo_branch}. Moving on to next repo. <-----"
33
+ formatter.message_with_border(msg: msg)
37
34
  end
38
35
 
39
- private
40
-
41
- def calculate_border_for(border_char, msg)
42
- border_char * (msg.length + 20)
36
+ def failed_pull_msg
37
+ msg = "-----> Failed to pull from upstream #{repo_branch}. Moving on to next repo. <-----"
38
+ formatter.message_with_border(msg: msg)
43
39
  end
44
40
 
45
- def output_border_and_msg(border, msg, sub_msg = nil, warn: true)
46
- puts border
47
- puts warning_header.center(border.length) if warn
48
- puts msg.center(border.length)
49
- puts sub_msg.center(border.length) if sub_msg
50
- puts border
41
+ def failed_push_msg
42
+ msg = "-----> Failed to push to origin #{repo_branch}. Moving on to next repo. <-----"
43
+ formatter.message_with_border(msg: msg)
51
44
  end
52
45
 
53
- def warning_header
54
- "WARNING"
46
+ def failed_sync_msg
47
+ msg = "-----> Failed to sync #{repo_name} | #{repo_branch}. Moving on to next repo. <-----"
48
+ formatter.message_with_border(msg: msg)
55
49
  end
56
50
  end
57
51
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GitFonky
4
- VERSION = "0.5.0"
4
+ VERSION = "0.6.0"
5
5
  end
data/lib/git_fonky.rb CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  require_relative "git_fonky/version"
4
4
  require_relative "git_fonky/repo_dir"
5
- require_relative "git_fonky/work_repo_names"
5
+ require_relative "git_fonky/repo_names"
6
6
 
7
7
  module GitFonky
8
8
  class Error < StandardError; end
9
9
 
10
10
  def self.sync_repos
11
11
  Dir.chdir "#{Dir.home}/code" do
12
- WORK_REPO_NAMES.each do |dir|
13
- RepoDir.new(dir).sync
12
+ REPO_NAMES.each do |dir|
13
+ RepoDir.sync(dir)
14
14
  puts "\n\n\n"
15
15
  end
16
16
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_fonky
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Collin Jilbert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-09 00:00:00.000000000 Z
11
+ date: 2023-12-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Do 'em all at once.
14
14
  email:
@@ -27,11 +27,13 @@ files:
27
27
  - bin/gfonk
28
28
  - git_fonky.gemspec
29
29
  - lib/git_fonky.rb
30
+ - lib/git_fonky/branch.rb
30
31
  - lib/git_fonky/command.rb
32
+ - lib/git_fonky/message_formatter.rb
31
33
  - lib/git_fonky/repo_dir.rb
34
+ - lib/git_fonky/repo_names.rb
32
35
  - lib/git_fonky/reporter.rb
33
36
  - lib/git_fonky/version.rb
34
- - lib/git_fonky/work_repo_names.rb
35
37
  - sig/git_fonky.rbs
36
38
  homepage: https://github.com/cjilbert504/git_fonky
37
39
  licenses:
@@ -55,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
57
  - !ruby/object:Gem::Version
56
58
  version: '0'
57
59
  requirements: []
58
- rubygems_version: 3.4.21
60
+ rubygems_version: 3.5.1
59
61
  signing_key:
60
62
  specification_version: 4
61
63
  summary: Sync all of your git repos with one command.
@@ -1,3 +0,0 @@
1
- module GitFonky
2
- WORK_REPO_NAMES = %w[gorails hatchbox-v2 jumpstart-marketing jumpstart-pro-rails noticed pay]
3
- end