git_fonky 0.6.2 → 1.1.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: 569a71f22be3048bd2fc4b3f46679d6af099ed0f482c9789881c0ee9f0d4e838
4
- data.tar.gz: c3d5be166a60aacc49d6d22bb43e5bc02d3dcce2b4a30c53c0a18b920be3ca7f
3
+ metadata.gz: 0deef2f35a250276eb51333666b35228b724a4e521165688d615348b08940add
4
+ data.tar.gz: d63a6a52ae1b19d21b7db78aace3c800a8cfb943b63b0edbf882afec9aa63084
5
5
  SHA512:
6
- metadata.gz: 12d8d769b85b90de655d289b22b9a61bbe1d15ab599b91ceeffbed58f9b6fb112e383d74ca9c8087590cd06f00cfc657c9a45c62f28bc235f699aa608894325f
7
- data.tar.gz: '08655ce1ce0a65fbb9c28b6eb94c561dd51f07bfb650df7152aae6e8e41afcfe1d8cb255f756fb57ab51af607ebfe50b066f5d49bd97d2315caad8788786f46d'
6
+ metadata.gz: 1a6f0aee6c476ae13227af2f4157794511a1bc9ff18a0071f73176eb19f0c04bbbcb7a7a3cf4c5495bc49844bd64abc9a6913fbd1185248a30704fcf68105d7f
7
+ data.tar.gz: 54711e1932255d1eb6db2cf1c8c25cf96ed217ea6f49a09a7fca046cb37c12a24d31cd91b3a356fb6941fd257ae571f5fe5aa7ade9cf4a7354cdc84994b0f806
data/README.md CHANGED
@@ -1,24 +1,40 @@
1
1
  # GitFonky
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
4
-
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/git_fonky`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Time to GitFonky! What do we do here you ask? Well, if you're like us, you have numerous repositories that you work on with others and keeping them all up-to-date can be a real drag.
4
+ That's where we come in with the funk! We take care of pulling in all the latest code for each repository you tell us by running one command!
6
5
 
7
6
  ## Installation
8
7
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
8
+ `gem install git_fonky`
9
+
10
+ ## Usage
10
11
 
11
- Install the gem and add to the application's Gemfile by executing:
12
+ GitFonky uses two environment variables in order to do its thing - `GFONK_DIR` and `GFONK_REPOS`.
12
13
 
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
14
+ ### `GFONK_DIR`
14
15
 
15
- If bundler is not being used to manage dependencies, install the gem by executing:
16
+ Set this environment variable if you wish to override the default directory that GitFonky uses to look for your repositories within. If you do not set this
17
+ environment variable then the defualt is to use the current users HOME directory and then a directory called `/code`. This is would be something like `/Users/somebody/code` done via `"#{Dir.home}/code`.
16
18
 
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
19
+ If you set the `GFONK_DIR` environment variable you should set it to the path to the directory that contains all of the repositories you want to
20
+ stop faking the funk with.
18
21
 
19
- ## Usage
22
+ ### GFONK_REPOS
20
23
 
21
- TODO: Write usage instructions here
24
+ This environment variable must be set if you want any funk to happen! The value of this environment variable should be a string of repository names separated
25
+ only by commas (NO SPACES!):
26
+ ```bash
27
+ export GFONK_REPOS="repo1,repo2,repo3"
28
+ ```
29
+
30
+ You can also specify a branch to use with a given repository. To specify the branch add a colon after the repository
31
+ name followed by the name of the branch.
32
+ ```bash
33
+ export GFONK_REPOS="repo1,repo2:main,repo3:staging"
34
+ ```
35
+
36
+ If you do not specify a branch for a repository then whatever the current branch is that you are on in a given
37
+ repository directory is the branch that will be used to attempt to sync the repository between the remotes.
22
38
 
23
39
  ## Development
24
40
 
@@ -28,12 +44,8 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
28
44
 
29
45
  ## Contributing
30
46
 
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/git_fonky. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/git_fonky/blob/main/CODE_OF_CONDUCT.md).
47
+ Bug reports and pull requests are welcome on the [GitHub page](https://github.com/cjilbert504/git_fonky.) for the gem.
32
48
 
33
49
  ## License
34
50
 
35
51
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
36
-
37
- ## Code of Conduct
38
-
39
- Everyone interacting in the GitFonky project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/git_fonky/blob/main/CODE_OF_CONDUCT.md).
data/bin/gfonk CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  require "git_fonky"
4
4
 
5
- GitFonky.sync_repos
5
+ GitFonky.sync_repos
data/git_fonky.gemspec CHANGED
@@ -33,6 +33,7 @@ Gem::Specification.new do |spec|
33
33
 
34
34
  # Uncomment to register a new dependency of your gem
35
35
  # spec.add_dependency "example-gem", "~> 1.0"
36
+ spec.add_dependency "colorize", "~> 1.1"
36
37
 
37
38
  # For more information and examples about making a new gem, check out our
38
39
  # guide at: https://bundler.io/guides/creating_gem.html
@@ -1,6 +1,6 @@
1
1
  module GitFonky
2
2
  class Command
3
- attr_accessor :branch_name
3
+ attr_writer :branch_name
4
4
 
5
5
  def initialize(branch_name = nil)
6
6
  @branch_name = branch_name
@@ -11,15 +11,15 @@ module GitFonky
11
11
  end
12
12
 
13
13
  def fetch_upstream
14
- `git fetch upstream #{branch_name} 2>&1`
14
+ `git fetch upstream #{@branch_name} 2>&1`
15
15
  end
16
16
 
17
17
  def pull_upstream
18
- `git pull upstream #{branch_name} 2>&1`
18
+ `git pull upstream #{@branch_name} 2>&1`
19
19
  end
20
20
 
21
21
  def push_to_origin
22
- `git push origin #{branch_name} 2>&1`
22
+ `git push origin #{@branch_name} 2>&1`
23
23
  end
24
24
  end
25
25
  end
@@ -1,26 +1,27 @@
1
1
  module GitFonky
2
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)
3
+ def output_message(msg, heading: false, warning: true)
4
+ warn build_message(msg, heading: heading, warning: warning)
6
5
  end
7
6
 
8
7
  private
9
8
 
10
- def calculate_border_for(msg, border_char)
11
- border_char * (msg.length + 20)
9
+ def warning_header
10
+ "WARNING: ".blink
12
11
  end
13
12
 
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
13
+ def warning_footer
14
+ " Moving on to next repo."
20
15
  end
21
16
 
22
- def warning_header
23
- "WARNING"
17
+ def build_message(msg, heading:, warning:)
18
+ if warning
19
+ (warning_header + msg + warning_footer).yellow
20
+ elsif heading
21
+ msg.underline
22
+ else
23
+ msg.green
24
+ end
24
25
  end
25
26
  end
26
27
  end
@@ -1,29 +1,25 @@
1
- require_relative "branch"
2
1
  require_relative "command"
3
2
  require_relative "reporter"
4
3
 
5
4
  module GitFonky
6
5
  class RepoDir
7
- attr_reader :branch, :command, :dirname, :reporter
8
-
9
- def initialize(dirname, command = Command, branch = Branch, reporter = Reporter)
10
- @dirname = dirname
6
+ def initialize(repo_name: nil, branch: nil, command: Command, reporter: Reporter)
7
+ @repo_name = repo_name
11
8
  @command = command.new
12
- @branch = branch.new(@command.current_branch)
13
- @command.branch_name = @branch.name
14
- @reporter = reporter.new(@dirname, @branch.name)
9
+ @branch = branch || get_current_branch
10
+ @command.branch_name = @branch
11
+ @reporter = reporter.new(@repo_name, @branch)
15
12
  end
16
13
 
17
- def self.sync(dirname)
18
- Dir.chdir(dirname) do
19
- new(dirname).sync
14
+ def self.sync(repo_name:, branch_name:)
15
+ Dir.chdir(repo_name.to_s) do
16
+ new(repo_name: repo_name, branch: branch_name).sync
20
17
  end
21
18
  end
22
19
 
23
20
  def sync
24
21
  catch(:skip_repo) do
25
22
  announce_sync_attempt
26
- fetch
27
23
  pull
28
24
  push
29
25
  announce_sync_success
@@ -32,27 +28,26 @@ module GitFonky
32
28
 
33
29
  private
34
30
 
35
- def announce_sync_attempt
36
- branch.valid? ? reporter.announce_sync_attempt : throw(:skip_repo, reporter.invalid_branch_msg)
31
+ def get_current_branch
32
+ @command.current_branch
37
33
  end
38
34
 
39
- def fetch
40
- command.fetch_upstream
41
- process_successful? ? reporter.announce("fetched") : throw(:skip_repo, reporter.failed_fetch_msg)
35
+ def announce_sync_attempt
36
+ @reporter.announce_sync_attempt
42
37
  end
43
38
 
44
39
  def pull
45
- command.pull_upstream
46
- process_successful? ? reporter.announce("pulled") : throw(:skip_repo, reporter.failed_pull_msg)
40
+ @command.pull_upstream
41
+ process_successful? ? @reporter.announce("pulled") : throw(:skip_repo, @reporter.failed_pull_msg)
47
42
  end
48
43
 
49
44
  def push
50
- command.push_to_origin
51
- process_successful? ? reporter.announce("pushed", "to", "origin") : throw(:skip_repo, reporter.failed_push_msg)
45
+ @command.push_to_origin
46
+ process_successful? ? @reporter.announce("pushed", "to", "origin") : throw(:skip_repo, @reporter.failed_push_msg)
52
47
  end
53
48
 
54
49
  def announce_sync_success
55
- reporter.announce_sync_success
50
+ @reporter.announce_sync_success
56
51
  end
57
52
 
58
53
  def process_successful?
@@ -1,51 +1,41 @@
1
1
  require_relative "message_formatter"
2
+
2
3
  module GitFonky
3
4
  class Reporter
4
- attr_reader :formatter, :repo_name, :repo_branch
5
-
6
- def initialize(repo_name, repo_branch, formatter = MessageFormatter)
5
+ def initialize(repo_name, branch_name, formatter = MessageFormatter)
7
6
  @repo_name = repo_name
8
- @repo_branch = repo_branch
7
+ @branch_name = branch_name
9
8
  @formatter = formatter.new
10
9
  end
11
10
 
12
- def announce(action, direction = "from", remote = "upstream")
13
- STDERR.puts "-----> #{action} #{direction} #{remote} #{repo_branch}"
11
+ def announce_sync_attempt
12
+ msg = "Attempting to sync -> #{@repo_name} | #{@branch_name} branch"
13
+ @formatter.output_message(msg, heading: true, warning: false)
14
14
  end
15
15
 
16
- def announce_sync_success
17
- puts "-----> Successfully synced #{repo_name} | #{repo_branch} branch"
16
+ def announce(action, direction = "from", remote = "upstream")
17
+ msg = "-----> #{action.capitalize} #{direction} #{remote} #{@branch_name}"
18
+ @formatter.output_message(msg, warning: false)
18
19
  end
19
20
 
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)
21
+ def announce_sync_success
22
+ msg = "-----> Successfully synced #{@repo_name} | #{@branch_name} branch"
23
+ @formatter.output_message(msg, warning: false)
23
24
  end
24
25
 
25
26
  def invalid_branch_msg
26
- msg = "You are not on the main/master branch. Please checkout the main/master branch and try again."
27
- sub_msg = "-----> skipping #{repo_name} | #{repo_branch} branch <-----"
28
- formatter.message_with_border(msg: msg, sub_msg: sub_msg)
29
- end
30
-
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)
27
+ msg = "Failed to validate upstream #{@branch_name}."
28
+ @formatter.output_message(msg)
34
29
  end
35
30
 
36
31
  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)
32
+ msg = "Failed to pull from upstream #{@branch_name}."
33
+ @formatter.output_message(msg)
39
34
  end
40
35
 
41
36
  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)
44
- end
45
-
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)
37
+ msg = "Failed to push to origin #{@branch_name}."
38
+ @formatter.output_message(msg)
49
39
  end
50
40
  end
51
41
  end
@@ -0,0 +1,24 @@
1
+ module GitFonky
2
+ class Repositories
3
+ def self.parse_env
4
+ new.parse_gfonk_repos_env_var
5
+ rescue NoMethodError
6
+ warn "The $GFONK_REPOS environment variable is not properly set."
7
+ warn "Please set the variable to point to a string list of repository names separated only by commas (NO SPACES)."
8
+ warn "You can optionally specify the branch name to use for a given repository by separating the repository and branch names with a colon."
9
+ warn "EXAMPLE:"
10
+ warn "export GFONK_REPOS='repo1,repo2,repo3:branch_name'"
11
+ exit 1
12
+ end
13
+
14
+ def parse_gfonk_repos_env_var
15
+ ENV["GFONK_REPOS"].split(",").map { |repo_config| repo_config.split(":") }.map do |repo_name, branch_name|
16
+ if branch_name.nil?
17
+ [repo_name.to_sym, nil]
18
+ else
19
+ [repo_name.to_sym, branch_name]
20
+ end
21
+ end.to_h
22
+ end
23
+ end
24
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GitFonky
4
- VERSION = "0.6.2"
4
+ VERSION = "1.1.0"
5
5
  end
data/lib/git_fonky.rb CHANGED
@@ -1,18 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "colorize"
3
4
  require_relative "git_fonky/version"
4
5
  require_relative "git_fonky/repo_dir"
5
- require_relative "git_fonky/repo_names"
6
+ require_relative "git_fonky/repositories"
6
7
 
7
8
  module GitFonky
8
9
  class Error < StandardError; end
9
10
 
11
+ GFONK_DIR = ENV["GFONK_DIR"] || "#{Dir.home}/code"
12
+
10
13
  def self.sync_repos
11
- Dir.chdir "#{Dir.home}/code" do
12
- REPO_NAMES.each do |dir|
13
- RepoDir.sync(dir)
14
- puts "\n\n\n"
14
+ Dir.chdir(GFONK_DIR) do
15
+ Repositories.parse_env.each do |repo, branch|
16
+ RepoDir.sync(repo_name: repo, branch_name: branch)
17
+ puts "\n" * 3
15
18
  end
16
19
  end
20
+
21
+ puts "Process complete. See output for any errors or warnings."
22
+ puts "DON'T FAKE THE FONK!"
17
23
  end
18
24
  end
metadata CHANGED
@@ -1,14 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_fonky
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Collin Jilbert
8
8
  bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
- dependencies: []
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: colorize
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '1.1'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '1.1'
12
26
  description: Do 'em all at once.
13
27
  email:
14
28
  - cjilbert504@gmail.com
@@ -26,12 +40,11 @@ files:
26
40
  - bin/gfonk
27
41
  - git_fonky.gemspec
28
42
  - lib/git_fonky.rb
29
- - lib/git_fonky/branch.rb
30
43
  - lib/git_fonky/command.rb
31
44
  - lib/git_fonky/message_formatter.rb
32
45
  - lib/git_fonky/repo_dir.rb
33
- - lib/git_fonky/repo_names.rb
34
46
  - lib/git_fonky/reporter.rb
47
+ - lib/git_fonky/repositories.rb
35
48
  - lib/git_fonky/version.rb
36
49
  - sig/git_fonky.rbs
37
50
  homepage: https://github.com/cjilbert504/git_fonky
@@ -55,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
68
  - !ruby/object:Gem::Version
56
69
  version: '0'
57
70
  requirements: []
58
- rubygems_version: 3.6.9
71
+ rubygems_version: 3.7.2
59
72
  specification_version: 4
60
73
  summary: Sync all of your git repos with one command.
61
74
  test_files: []
@@ -1,13 +0,0 @@
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,3 +0,0 @@
1
- module GitFonky
2
- REPO_NAMES = %w[gr hatchbox-v2 jumpstart-marketing jumpstart-pro-rails noticed pay]
3
- end