git_fonky 0.1.0 → 0.3.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: fedc3ea4cef24087688dad0840fcf2430663e021b6859cdd849400d58d07b7ac
4
- data.tar.gz: 4c8473ee344f81d98b5f5343b3490bdeb1969de0b52b3faf0211479098e44d4a
3
+ metadata.gz: 075ddc336d9482d77d083db40a4b6ff7553ece62c759b3213a92df3bf277cfe9
4
+ data.tar.gz: bc74101affa62955eb5a1ed03a430cce6f59038aad66aeb99f3821dc264a55c4
5
5
  SHA512:
6
- metadata.gz: 946149e9bf2329e7598810279af9512e5823c3b9f7533bda8bc2bc5ecd2606c8bee63e156adff73da47d28413666c2ffbbebd0590bfd2c87e68ae3fed8edac3f
7
- data.tar.gz: 16301de2e6b7da6d295453f77d6e9790b1aa4e207666f55e8e48a2ac48751b028c5f225b1125afb84464fb44cc69b925b92941656b3eea8874fe73574b99630a
6
+ metadata.gz: c2b26d77154d1281978063c57be33fe6f31d82c09879f81b41081542eceaaf7af032c05824fadba674d8fb5d7388253119756c9d0b9f433cc6831ff48c655674
7
+ data.tar.gz: ca914d2c8d384f32b37b91f0ba87cdcefc9ff40bb8cbd6bfaa42a93415899cae27ec592d5b9afbda35d57a0fe7010347c493fd9bf4fa08442f923ac5c7c22754
@@ -0,0 +1,34 @@
1
+ module GitFonky
2
+ class Command
3
+ attr_reader :repo_dir
4
+
5
+ def initialize(repo_dir)
6
+ @repo_dir = repo_dir
7
+ end
8
+
9
+ def current_branch
10
+ `git branch --show-current`.strip
11
+ end
12
+
13
+ def fetch_upstream
14
+ announce("fetching")
15
+ `git fetch upstream #{repo_dir.branch} 2>&1`
16
+ end
17
+
18
+ def pull_upstream
19
+ announce("pulling")
20
+ `git pull upstream #{repo_dir.branch} 2>&1`
21
+ end
22
+
23
+ def push_to_origin
24
+ announce("pushing", "to", "origin")
25
+ `git push origin #{repo_dir.branch} 2>&1`
26
+ end
27
+
28
+ private
29
+
30
+ def announce(action, direction = "from", remote = "upstream")
31
+ puts "-----> #{action} #{direction} #{remote} #{repo_dir.branch}"
32
+ end
33
+ end
34
+ end
@@ -1,86 +1,37 @@
1
+ require_relative "reporter"
2
+ require_relative "command"
3
+
1
4
  module GitFonky
2
5
  class RepoDir
3
- attr_reader :dirname
6
+ attr_reader :command, :dirname, :reporter
4
7
 
5
8
  def initialize(dirname)
9
+ @command = Command.new(self)
6
10
  @dirname = dirname
11
+ @reporter = Reporter.new(self)
7
12
  end
8
13
 
9
14
  def branch
10
- @branch ||= `git branch --show-current`.strip
15
+ @branch ||= command.current_branch
11
16
  end
12
17
 
13
18
  def sync
14
- announce_update
15
- fetch_upstream
16
- pull_upstream
17
- if $?.success?
18
- push_to_origin
19
- else
20
- failed_pull_msg
21
- end
22
- end
19
+ Dir.chdir dirname do
20
+ reporter.announce_update
21
+ return reporter.invalid_branch_msg if on_invalid_branch?
23
22
 
24
- def on_invalid_branch?
25
- !branch.match?(/(main|master)/)
26
- end
23
+ command.fetch_upstream
24
+ command.pull_upstream
27
25
 
28
- def invalid_branch_msg
29
- msg = "You are not on the main/master branch. Please checkout the main/master branch and try again."
30
- sub_msg = "-----> skipping #{dirname} | #{branch} branch <-----"
31
- border = border_for(msg, "*")
26
+ return reporter.failed_pull_msg unless $?.success?
32
27
 
33
- puts border
34
- puts warning_header.center(border.length)
35
- puts msg.center(border.length)
36
- puts sub_msg.center(border.length)
37
- puts border
38
- end
39
-
40
- private
41
-
42
- def failed_pull_msg
43
- msg = "-----> Failed to pull upstream #{branch}. Moving on to next repo. <-----"
44
- border = border_for(msg, "*")
45
-
46
- puts border
47
- puts warning_header.center(border.length)
48
- puts msg.center(border.length)
49
- puts border
50
- end
51
-
52
- def announce_update
53
- update_msg = "Updating -> #{dirname} | #{branch} branch "
54
- puts "=" * update_msg.length
55
- puts update_msg
56
- puts "=" * update_msg.length
57
- end
58
-
59
- def announce(action, direction = "from", remote = "upstream")
60
- puts "-----> #{action} #{direction} #{remote} #{branch}"
61
- end
62
-
63
- def fetch_upstream
64
- # announce("fetching")
65
- `git fetch upstream #{branch} 2>&1`
66
- end
67
-
68
- def pull_upstream
69
- announce("pulling")
70
- `git pull upstream #{branch} 2>&1`
71
- end
72
-
73
- def push_to_origin
74
- announce("pushing", "to", "origin")
75
- `git push origin #{branch} 2>&1`
76
- end
77
-
78
- def warning_header
79
- "WARNING"
28
+ command.push_to_origin
29
+ reporter.announce_success
30
+ end
80
31
  end
81
32
 
82
- def border_for(msg, border_char)
83
- border_char * (msg.length + 20)
33
+ def on_invalid_branch?
34
+ !branch.match?(/(main|master)/)
84
35
  end
85
36
  end
86
37
  end
@@ -0,0 +1,53 @@
1
+ module GitFonky
2
+ class Reporter
3
+ attr_reader :repo_dir
4
+
5
+ def initialize(repo_dir)
6
+ @repo_dir = repo_dir
7
+ end
8
+
9
+ def announce_success
10
+ puts "-----> Successfully updated #{repo_dir.dirname} | #{repo_dir.branch} branch"
11
+ end
12
+
13
+ def announce_update
14
+ msg = "Updating -> #{repo_dir.dirname} | #{repo_dir.branch} branch "
15
+ border = calculate_border_for("=", msg)
16
+
17
+ output_border_and_msg(border, msg, warn: false)
18
+ end
19
+
20
+ def invalid_branch_msg
21
+ msg = "You are not on the main/master branch. Please checkout the main/master branch and try again."
22
+ sub_msg = "-----> skipping #{repo_dir.dirname} | #{repo_dir.branch} branch <-----"
23
+ border = calculate_border_for("*", msg)
24
+
25
+ output_border_and_msg(border, msg, sub_msg)
26
+ end
27
+
28
+ def failed_pull_msg
29
+ msg = "-----> Failed to pull upstream #{branch}. Moving on to next repo. <-----"
30
+ border = calculate_border_for(msg, "*")
31
+
32
+ output_border_and_msg(border, msg)
33
+ end
34
+
35
+ private
36
+
37
+ def calculate_border_for(border_char, msg)
38
+ border_char * (msg.length + 20)
39
+ end
40
+
41
+ def output_border_and_msg(border, msg, sub_msg = nil, warn: true)
42
+ puts border
43
+ puts warning_header.center(border.length) if warn
44
+ puts msg.center(border.length)
45
+ puts sub_msg.center(border.length) if sub_msg
46
+ puts border
47
+ end
48
+
49
+ def warning_header
50
+ "WARNING"
51
+ end
52
+ end
53
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GitFonky
4
- VERSION = "0.1.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/git_fonky.rb CHANGED
@@ -10,17 +10,8 @@ module GitFonky
10
10
  def self.sync_repos
11
11
  Dir.chdir "#{Dir.home}/code" do
12
12
  WORK_REPO_NAMES.each do |dir|
13
- repo = RepoDir.new(dir)
14
-
15
- Dir.chdir repo.dirname do
16
- puts repo.dirname.upcase
17
-
18
- next repo.invalid_branch_msg if repo.on_invalid_branch?
19
-
20
- repo.sync
21
- end
22
-
23
- puts "\n\n"
13
+ RepoDir.new(dir).sync
14
+ puts "\n\n\n"
24
15
  end
25
16
  end
26
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_fonky
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Collin Jilbert
@@ -27,7 +27,9 @@ files:
27
27
  - bin/gfonk
28
28
  - git_fonky.gemspec
29
29
  - lib/git_fonky.rb
30
+ - lib/git_fonky/command.rb
30
31
  - lib/git_fonky/repo_dir.rb
32
+ - lib/git_fonky/reporter.rb
31
33
  - lib/git_fonky/version.rb
32
34
  - lib/git_fonky/work_repo_names.rb
33
35
  - sig/git_fonky.rbs