git_fonky 0.2.0 → 0.4.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: 25baa00e3edcbddf36eb6d5565e3932666268d06a2429734fd51b842bec0fac3
4
- data.tar.gz: e43f2d96ce2b617994ef2d898e18cfdf6d8ad78f2ccb3c10652cc24da11f3159
3
+ metadata.gz: 2d9e659e91221b3600b3d9924a209748976b7880108f49d724d4ffaaf2189ff6
4
+ data.tar.gz: 947bf8009681841bd4fcdd46c962bcc2d824b39851161aefa3777e75f5b0cd0b
5
5
  SHA512:
6
- metadata.gz: 71e58c2e8f0494c80d7f92fa3c68de56ad34dfdca3312aabec1e9cb29e8e19789b0fe68549feda406372ab9efae32df3f38116f97b3cf54804b4f41375852f96
7
- data.tar.gz: bb929fdc4346b7281d7b8bed3c7f063e22a4bbf1b323063f4610886c1173b5092368860ee3a174151a61e713561f2c3e70b81afd5162b9a6a5d284c823107d0d
6
+ metadata.gz: 83e34338ffc13a6af5f9fe7d6684066bc74796037353122c9ee5bdc73a86e424d9438325d1634a8d5ba35cebd2ef86d3e3ecce2fcc8762bed39624b7e7ae0381
7
+ data.tar.gz: 2601863350da5d6a26b5a263cf9e9b903f43ec5b85858737c760ab122479467b7f535e3531a49255b1aab2b53324a9207d80a0e6e022b6dcc6e4d059dd433f47
@@ -0,0 +1,29 @@
1
+ module GitFonky
2
+ class Command
3
+ attr_reader :repo_dir, :reporter
4
+
5
+ def initialize(repo_dir:, reporter:)
6
+ @repo_dir = repo_dir
7
+ @reporter = reporter
8
+ end
9
+
10
+ def current_branch
11
+ `git branch --show-current`.strip
12
+ end
13
+
14
+ def fetch_upstream
15
+ reporter.announce("fetching")
16
+ `git fetch upstream #{repo_dir.branch} 2>&1`
17
+ end
18
+
19
+ def pull_upstream
20
+ reporter.announce("pulling")
21
+ `git pull upstream #{repo_dir.branch} 2>&1`
22
+ end
23
+
24
+ def push_to_origin
25
+ reporter.announce("pushing", "to", "origin")
26
+ `git push origin #{repo_dir.branch} 2>&1`
27
+ end
28
+ end
29
+ 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)
6
9
  @dirname = dirname
10
+ @reporter = Reporter.new(self)
11
+ @command = Command.new(repo_dir: self, reporter: reporter)
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,57 @@
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(action, direction = "from", remote = "upstream")
10
+ puts "-----> #{action} #{direction} #{remote} #{repo_dir.branch}"
11
+ end
12
+
13
+ def announce_success
14
+ puts "-----> Successfully updated #{repo_dir.dirname} | #{repo_dir.branch} branch"
15
+ end
16
+
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)
22
+ end
23
+
24
+ def invalid_branch_msg
25
+ 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)
30
+ end
31
+
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)
37
+ end
38
+
39
+ private
40
+
41
+ def calculate_border_for(border_char, msg)
42
+ border_char * (msg.length + 20)
43
+ end
44
+
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
51
+ end
52
+
53
+ def warning_header
54
+ "WARNING"
55
+ end
56
+ end
57
+ 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.4.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.4.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