git_fonky 1.1.1 → 2.0.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: eccc8024d2a7647279b20745e3391b414b457c855d7c15aac9b266e477728129
4
- data.tar.gz: c3070a7b5cf6cf91383f128d0005d672b3abd3c4e485a6b2b3d610d9435d1df6
3
+ metadata.gz: 3dc42a2c9f6a3f9c09b5e882e292535f541c4b90eec5475757a362a2826d874f
4
+ data.tar.gz: 67dd28ee616f0e3cd735b44c5d61b0ed6b20b89604a76d6204f704a3944e3868
5
5
  SHA512:
6
- metadata.gz: 2b6970b50cf13f82a013a68ea477e44d0f482f8fa051297f6d6ea36b5eea5d78dad480d4ce924c1b006de643b7f7e10ecb30425e8e828a271c69690260496365
7
- data.tar.gz: 31a75d1eff266a71b12923338d34316f15876526e70055f8ca997426c9fa79badb11c758ef15157bb6244223009f15da0020c7eca6ad5615ec636bc8476bc2f6
6
+ metadata.gz: 692d2868f54038afd4357ee2120e2da2bdf2956dc0ec8ceb9b80a0a669032d74df398222aeb8f33b959c371a2fe73a11a9200d6807476e28732b7faac75f204c
7
+ data.tar.gz: 0de8717d683e42418a763aa8192ea878c527db43ca7bb888829337cadbaecaa51fa25c074ace37610fd0a1ef10e6ba423225be118678c3842fc83d6ac980b74b
data/README.md CHANGED
@@ -27,14 +27,16 @@ only by commas (NO SPACES!):
27
27
  export GFONK_REPOS="repo1,repo2,repo3"
28
28
  ```
29
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.
30
+ You can also specify a branch, origin remote and fork remote to use with a given repository. To specify these add a colon after the repository
31
+ name followed by the name of the branch, origin remote and fork remote.
32
32
  ```bash
33
- export GFONK_REPOS="repo1,repo2:main,repo3:staging"
33
+ export GFONK_REPOS="repo1,repo2:main,repo3:staging:origin_remote:fork_remote"
34
34
  ```
35
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.
36
+ If you do not specify a branch, origin remote or fork remote the following defaults will be used:
37
+ default branch: `main`
38
+ default origin remote: `origin`
39
+ default fork remote: `fork`
38
40
 
39
41
 
40
42
  ### Running the fonk
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitFonky
4
+ class Parser
5
+ def self.parse_env
6
+ new.parse_gfonk_repos_env_var
7
+ rescue NoMethodError
8
+ warn "The $GFONK_REPOS environment variable is not properly set."
9
+ warn "Please set the variable to point to a string list of repository names separated only by commas (NO SPACES)."
10
+ warn "You can optionally specify the branch, origin remote and fork remote to use for a given repository by separating each with a colon."
11
+ warn "EXAMPLE:"
12
+ warn "export GFONK_REPOS='repo1,repo2:branch,repo3:branch_name:origin_remote_name:fork_remote_name'"
13
+ exit 1
14
+ end
15
+
16
+ def parse_gfonk_repos_env_var
17
+ keys = [:repo, :branch, :origin_remote, :fork_remote]
18
+
19
+ split_repo_details.each_with_index.to_h do |values, index|
20
+ [index, keys.zip(values).to_h]
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def split_repo_details
27
+ ENV["GFONK_REPOS"].split(",").map do |repo|
28
+ repo.split(":")
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,41 +1,42 @@
1
- require_relative "message_formatter"
1
+ # frozen_string_literal: true
2
+
3
+ require "colorize"
2
4
 
3
5
  module GitFonky
4
6
  class Reporter
5
- def initialize(repo_name, branch_name, formatter = MessageFormatter)
6
- @repo_name = repo_name
7
- @branch_name = branch_name
8
- @formatter = formatter.new
7
+ def initialize(repo, branch)
8
+ @repo = repo
9
+ @branch = branch
9
10
  end
10
11
 
11
12
  def announce_sync_attempt
12
- msg = "Attempting to sync -> #{@repo_name} | #{@branch_name} branch"
13
- @formatter.output_message(msg, heading: true, warning: false)
13
+ report("Attempting to sync -> #{@repo} | #{@branch} branch", heading: true)
14
14
  end
15
15
 
16
- def announce(action, direction = "from", remote = "upstream")
17
- msg = "-----> #{action.capitalize} #{direction} #{remote} #{@branch_name}"
18
- @formatter.output_message(msg, warning: false)
16
+ def announce(action, direction, remote)
17
+ report("-----> #{action.capitalize} #{direction} #{remote} #{@branch}")
19
18
  end
20
19
 
21
20
  def announce_sync_success
22
- msg = "-----> Successfully synced #{@repo_name} | #{@branch_name} branch"
23
- @formatter.output_message(msg, warning: false)
21
+ report("-----> Successfully synced #{@repo} | #{@branch} branch")
24
22
  end
25
23
 
26
24
  def invalid_branch_msg
27
- msg = "Failed to validate upstream #{@branch_name}."
28
- @formatter.output_message(msg)
25
+ report("Failed to validate upstream #{@branch}.")
29
26
  end
30
27
 
31
28
  def failed_pull_msg
32
- msg = "Failed to pull from upstream #{@branch_name}."
33
- @formatter.output_message(msg)
29
+ "#{"WARNING".blink}: Failed to pull from upstream #{@branch}. Moving on to next repo.".yellow
34
30
  end
35
31
 
36
32
  def failed_push_msg
37
- msg = "Failed to push to origin #{@branch_name}."
38
- @formatter.output_message(msg)
33
+ "#{"WARNING".blink}: Failed to push to origin #{@branch}. Moving on to next repo.".yellow
34
+ end
35
+
36
+ private
37
+
38
+ def report(msg, heading: false)
39
+ puts heading ? msg.underline : msg.green
39
40
  end
40
41
  end
41
42
  end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "open3"
4
+ require_relative "reporter"
5
+
6
+ module GitFonky
7
+ class Repository
8
+ def initialize(repo:, branch: "main", origin_remote: "origin", fork_remote: "fork", reporter: Reporter)
9
+ @repo = repo
10
+ @branch = branch
11
+ @origin_remote = origin_remote
12
+ @fork_remote = fork_remote
13
+ @reporter = reporter.new(@repo, @branch)
14
+ end
15
+
16
+ def sync
17
+ Dir.chdir(@repo.to_s) do
18
+ @reporter.announce_sync_attempt
19
+ attempt_pull
20
+ attempt_push
21
+ @reporter.announce_sync_success
22
+ true
23
+ rescue PullError, PushError => exception
24
+ warn exception.message
25
+ false
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def attempt_pull
32
+ _stdout, stderr, status = Open3.capture3("git", "pull", @origin_remote, @branch)
33
+
34
+ if status.success?
35
+ @reporter.announce("pulled", "from", @origin_remote.to_s)
36
+ else
37
+ raise PullError, "#{@reporter.failed_pull_msg}\n#{stderr}".yellow
38
+ end
39
+ end
40
+
41
+ def attempt_push
42
+ _stdout, stderr, status = Open3.capture3("git", "push", @fork_remote, @branch)
43
+
44
+ if status.success?
45
+ @reporter.announce("pushed", "to", @fork_remote.to_s)
46
+ else
47
+ raise PushError, "#{@reporter.failed_push_msg}\n#{stderr}".yellow
48
+ end
49
+ end
50
+ end
51
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GitFonky
4
- VERSION = "1.1.1"
4
+ VERSION = "2.0.0"
5
5
  end
data/lib/git_fonky.rb CHANGED
@@ -1,19 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "colorize"
4
3
  require_relative "git_fonky/version"
5
- require_relative "git_fonky/repo_dir"
6
- require_relative "git_fonky/repositories"
4
+ require_relative "git_fonky/repository"
5
+ require_relative "git_fonky/parser"
7
6
 
8
7
  module GitFonky
9
8
  class Error < StandardError; end
10
9
 
10
+ class PullError < Error; end
11
+
12
+ class PushError < Error; end
13
+
11
14
  GFONK_DIR = ENV["GFONK_DIR"] || "#{Dir.home}/code"
12
15
 
13
16
  def self.sync_repos
14
17
  Dir.chdir(GFONK_DIR) do
15
- Repositories.parse_env.each do |repo_name, branch_name|
16
- RepoDir.sync(repo_name, branch_name)
18
+ Parser.parse_env.values.each do |repo_config|
19
+ Repository.new(**repo_config.compact!).sync
17
20
  puts "\n" * 3
18
21
  end
19
22
  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: 1.1.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Collin Jilbert
@@ -33,20 +33,16 @@ extra_rdoc_files: []
33
33
  files:
34
34
  - ".standard.yml"
35
35
  - CHANGELOG.md
36
- - CODE_OF_CONDUCT.md
37
36
  - LICENSE.txt
38
37
  - README.md
39
38
  - Rakefile
40
39
  - bin/gfonk
41
40
  - git_fonky.gemspec
42
41
  - lib/git_fonky.rb
43
- - lib/git_fonky/command.rb
44
- - lib/git_fonky/message_formatter.rb
45
- - lib/git_fonky/repo_dir.rb
42
+ - lib/git_fonky/parser.rb
46
43
  - lib/git_fonky/reporter.rb
47
- - lib/git_fonky/repositories.rb
44
+ - lib/git_fonky/repository.rb
48
45
  - lib/git_fonky/version.rb
49
- - sig/git_fonky.rbs
50
46
  homepage: https://github.com/cjilbert504/git_fonky
51
47
  licenses:
52
48
  - MIT
data/CODE_OF_CONDUCT.md DELETED
@@ -1,84 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
-
7
- We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
-
9
- ## Our Standards
10
-
11
- Examples of behavior that contributes to a positive environment for our community include:
12
-
13
- * Demonstrating empathy and kindness toward other people
14
- * Being respectful of differing opinions, viewpoints, and experiences
15
- * Giving and gracefully accepting constructive feedback
16
- * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
- * Focusing on what is best not just for us as individuals, but for the overall community
18
-
19
- Examples of unacceptable behavior include:
20
-
21
- * The use of sexualized language or imagery, and sexual attention or
22
- advances of any kind
23
- * Trolling, insulting or derogatory comments, and personal or political attacks
24
- * Public or private harassment
25
- * Publishing others' private information, such as a physical or email
26
- address, without their explicit permission
27
- * Other conduct which could reasonably be considered inappropriate in a
28
- professional setting
29
-
30
- ## Enforcement Responsibilities
31
-
32
- Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
-
34
- Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
-
36
- ## Scope
37
-
38
- This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
-
40
- ## Enforcement
41
-
42
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at cjilbert504@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
-
44
- All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
-
46
- ## Enforcement Guidelines
47
-
48
- Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
-
50
- ### 1. Correction
51
-
52
- **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
-
54
- **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
-
56
- ### 2. Warning
57
-
58
- **Community Impact**: A violation through a single incident or series of actions.
59
-
60
- **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
-
62
- ### 3. Temporary Ban
63
-
64
- **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
-
66
- **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
-
68
- ### 4. Permanent Ban
69
-
70
- **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
-
72
- **Consequence**: A permanent ban from any sort of public interaction within the community.
73
-
74
- ## Attribution
75
-
76
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
- available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
-
79
- Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
-
81
- [homepage]: https://www.contributor-covenant.org
82
-
83
- For answers to common questions about this code of conduct, see the FAQ at
84
- https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
@@ -1,25 +0,0 @@
1
- module GitFonky
2
- class Command
3
- attr_writer :branch_name
4
-
5
- def initialize(branch_name = nil)
6
- @branch_name = branch_name
7
- end
8
-
9
- def current_branch
10
- `git branch --show-current`.strip
11
- end
12
-
13
- def fetch_upstream
14
- `git fetch upstream #{@branch_name} 2>&1`
15
- end
16
-
17
- def pull_upstream
18
- `git pull upstream #{@branch_name} 2>&1`
19
- end
20
-
21
- def push_to_origin
22
- `git push origin #{@branch_name} 2>&1`
23
- end
24
- end
25
- end
@@ -1,27 +0,0 @@
1
- module GitFonky
2
- class MessageFormatter
3
- def output_message(msg, heading: false, warning: true)
4
- warn build_message(msg, heading: heading, warning: warning)
5
- end
6
-
7
- private
8
-
9
- def warning_header
10
- "WARNING: ".blink
11
- end
12
-
13
- def warning_footer
14
- " Moving on to next repo."
15
- end
16
-
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
25
- end
26
- end
27
- end
@@ -1,57 +0,0 @@
1
- require_relative "command"
2
- require_relative "reporter"
3
-
4
- module GitFonky
5
- class RepoDir
6
- def initialize(repo_name = nil, branch = nil, command: Command, reporter: Reporter)
7
- @repo_name = repo_name
8
- @command = command.new
9
- @branch = branch || get_current_branch
10
- @command.branch_name = @branch
11
- @reporter = reporter.new(@repo_name, @branch)
12
- end
13
-
14
- def self.sync(repo_name, branch_name)
15
- Dir.chdir(repo_name.to_s) do
16
- new(repo_name, branch_name).sync
17
- end
18
- end
19
-
20
- def sync
21
- catch(:skip_repo) do
22
- announce_sync_attempt
23
- pull
24
- push
25
- announce_sync_success
26
- end
27
- end
28
-
29
- private
30
-
31
- def get_current_branch
32
- @command.current_branch
33
- end
34
-
35
- def announce_sync_attempt
36
- @reporter.announce_sync_attempt
37
- end
38
-
39
- def pull
40
- @command.pull_upstream
41
- process_successful? ? @reporter.announce("pulled") : throw(:skip_repo, @reporter.failed_pull_msg)
42
- end
43
-
44
- def push
45
- @command.push_to_origin
46
- process_successful? ? @reporter.announce("pushed", "to", "origin") : throw(:skip_repo, @reporter.failed_push_msg)
47
- end
48
-
49
- def announce_sync_success
50
- @reporter.announce_sync_success
51
- end
52
-
53
- def process_successful?
54
- $?.success?
55
- end
56
- end
57
- end
@@ -1,24 +0,0 @@
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
data/sig/git_fonky.rbs DELETED
@@ -1,4 +0,0 @@
1
- module GitFonky
2
- VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
- end