git_fonky 0.2.0 → 0.3.0

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: 25baa00e3edcbddf36eb6d5565e3932666268d06a2429734fd51b842bec0fac3
4
- data.tar.gz: e43f2d96ce2b617994ef2d898e18cfdf6d8ad78f2ccb3c10652cc24da11f3159
3
+ metadata.gz: 075ddc336d9482d77d083db40a4b6ff7553ece62c759b3213a92df3bf277cfe9
4
+ data.tar.gz: bc74101affa62955eb5a1ed03a430cce6f59038aad66aeb99f3821dc264a55c4
5
5
  SHA512:
6
- metadata.gz: 71e58c2e8f0494c80d7f92fa3c68de56ad34dfdca3312aabec1e9cb29e8e19789b0fe68549feda406372ab9efae32df3f38116f97b3cf54804b4f41375852f96
7
- data.tar.gz: bb929fdc4346b7281d7b8bed3c7f063e22a4bbf1b323063f4610886c1173b5092368860ee3a174151a61e713561f2c3e70b81afd5162b9a6a5d284c823107d0d
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,97 +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
19
  Dir.chdir dirname do
15
- announce_update
16
- next invalid_branch_msg if on_invalid_branch?
17
- fetch_upstream
18
- pull_upstream
19
- if $?.success?
20
- push_to_origin
21
- announce_success
22
- else
23
- failed_pull_msg
24
- end
25
- end
26
- puts "\n\n"
27
- end
28
-
29
- def on_invalid_branch?
30
- !branch.match?(/(main|master)/)
31
- end
32
-
33
- def invalid_branch_msg
34
- msg = "You are not on the main/master branch. Please checkout the main/master branch and try again."
35
- sub_msg = "-----> skipping #{dirname} | #{branch} branch <-----"
36
- border = border_for(msg, "*")
37
-
38
- puts border
39
- puts warning_header.center(border.length)
40
- puts msg.center(border.length)
41
- puts sub_msg.center(border.length)
42
- puts border
43
- end
44
-
45
- private
46
-
47
- def failed_pull_msg
48
- msg = "-----> Failed to pull upstream #{branch}. Moving on to next repo. <-----"
49
- border = border_for(msg, "*")
50
-
51
- puts border
52
- puts warning_header.center(border.length)
53
- puts msg.center(border.length)
54
- puts border
55
- end
20
+ reporter.announce_update
21
+ return reporter.invalid_branch_msg if on_invalid_branch?
56
22
 
57
- def announce_update
58
- msg = "Updating -> #{dirname} | #{branch} branch "
59
- border = border_for(msg, "=")
23
+ command.fetch_upstream
24
+ command.pull_upstream
60
25
 
61
- puts border
62
- puts msg.center(border.length)
63
- puts border
64
- end
65
-
66
- def announce_success
67
- puts "-----> Successfully updated #{dirname} | #{branch} branch"
68
- end
69
-
70
- def announce(action, direction = "from", remote = "upstream")
71
- puts "-----> #{action} #{direction} #{remote} #{branch}"
72
- end
73
-
74
- def fetch_upstream
75
- announce("fetching")
76
- `git fetch upstream #{branch} 2>&1`
77
- end
26
+ return reporter.failed_pull_msg unless $?.success?
78
27
 
79
- def pull_upstream
80
- announce("pulling")
81
- `git pull upstream #{branch} 2>&1`
82
- end
83
-
84
- def push_to_origin
85
- announce("pushing", "to", "origin")
86
- `git push origin #{branch} 2>&1`
87
- end
88
-
89
- def warning_header
90
- "WARNING"
28
+ command.push_to_origin
29
+ reporter.announce_success
30
+ end
91
31
  end
92
32
 
93
- def border_for(msg, border_char)
94
- border_char * (msg.length + 20)
33
+ def on_invalid_branch?
34
+ !branch.match?(/(main|master)/)
95
35
  end
96
36
  end
97
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.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/git_fonky.rb CHANGED
@@ -11,6 +11,7 @@ module GitFonky
11
11
  Dir.chdir "#{Dir.home}/code" do
12
12
  WORK_REPO_NAMES.each do |dir|
13
13
  RepoDir.new(dir).sync
14
+ puts "\n\n\n"
14
15
  end
15
16
  end
16
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.2.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