Class: Rookie::Tasks::Git
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- Rookie::Tasks::Git
- Defined in:
- lib/rookie/tasks/git.rb
Overview
This task provides a way to quickly and easily release git projects using a gem specification.
Instance Attribute Summary collapse
-
#logger ⇒ Object
Lazily created logger.
-
#release_version ⇒ Object
The version the project will be released under.
-
#working_directory ⇒ Object
Directory which contains the git repository.
Instance Method Summary collapse
-
#already_tagged?(tag_name) ⇒ Boolean
Returns whether the repository already contains the given tag name.
-
#define_tasks! ⇒ Object
Defines the git tasks.
-
#initialize(release_version = nil, working_dir = Dir.pwd, logger = nil) {|_self| ... } ⇒ Git
constructor
Creates a new git task with the given parameters.
-
#push!(remote = 'origin', branch = 'master', tags = false) ⇒ Object
Pushes the changes in the given branch to the given remote repository.
-
#release!(version_tag = release_tag, remote = 'origin', branch = 'master') ⇒ Object
Tags the latest commit with the given version tag and pushes the given branch to the given remote repository, including tags.
-
#release_tag(version = release_version) ⇒ Object
Computes a release tag for the given version.
-
#tag!(tag_name) ⇒ Object
Tags the latest commit in the repository with the given tag name.
Constructor Details
#initialize(release_version = nil, working_dir = Dir.pwd, logger = nil) {|_self| ... } ⇒ Git
Creates a new git task with the given parameters. Yields the instance if given a block.
Tasks do not get defined automatically; don’t forget to call #define_tasks!
32 33 34 35 36 37 |
# File 'lib/rookie/tasks/git.rb', line 32 def initialize(release_version = nil, working_dir = Dir.pwd, logger = nil) self.logger = logger self.working_directory = working_dir self.release_version = release_version yield self if block_given? end |
Instance Attribute Details
#logger ⇒ Object
Lazily created logger.
23 24 25 |
# File 'lib/rookie/tasks/git.rb', line 23 def logger @logger ||= create_logger end |
#release_version ⇒ Object
The version the project will be released under.
13 14 15 |
# File 'lib/rookie/tasks/git.rb', line 13 def release_version @release_version end |
#working_directory ⇒ Object
Directory which contains the git repository.
16 17 18 |
# File 'lib/rookie/tasks/git.rb', line 16 def working_directory @working_directory end |
Instance Method Details
#already_tagged?(tag_name) ⇒ Boolean
Returns whether the repository already contains the given tag name.
72 73 74 75 76 |
# File 'lib/rookie/tasks/git.rb', line 72 def already_tagged?(tag_name) git.tag tag_name rescue ::Git::GitTagNameDoesNotExist false end |
#define_tasks! ⇒ Object
Defines the git tasks.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/rookie/tasks/git.rb', line 79 def define_tasks! namespace :git do desc 'Tags latest commit with the given tag name' task :tag, :tag_name do |task, args| tag! args[:tag_name] end desc 'Pushes changes to a remote repository' task :push, :remote, :branch do |task, args| args.with_defaults remote: 'origin', branch: 'master' push! args[:remote], args[:branch] end namespace :push do desc 'Pushes tags to a remote repository' task :tags, :remote, :branch do |task, args| args.with_defaults remote: 'origin', branch: 'master' push! args[:remote], args[:branch] end end desc 'Release current version' task :release, :version, :remote, :branch do |task, args| args.with_defaults version: release_tag, remote: 'origin', branch: 'master' release! args[:version], args[:remote], args[:branch] end end end |
#push!(remote = 'origin', branch = 'master', tags = false) ⇒ Object
Pushes the changes in the given branch to the given remote repository.
Tags will be pushed too if tags
is true
.
60 61 62 |
# File 'lib/rookie/tasks/git.rb', line 60 def push!(remote = 'origin', branch = 'master', = false) git.push remote, branch, end |
#release!(version_tag = release_tag, remote = 'origin', branch = 'master') ⇒ Object
Tags the latest commit with the given version tag and pushes the given branch to the given remote repository, including tags.
66 67 68 69 |
# File 'lib/rookie/tasks/git.rb', line 66 def release!(version_tag = release_tag, remote = 'origin', branch = 'master') tag! version_tag push! remote, branch, true end |
#release_tag(version = release_version) ⇒ Object
Computes a release tag for the given version.
40 41 42 |
# File 'lib/rookie/tasks/git.rb', line 40 def release_tag(version = release_version) "v#{version}" end |
#tag!(tag_name) ⇒ Object
Tags the latest commit in the repository with the given tag name.
If the tag is invalid or already in the repository, an error will be raised prior to tagging.
48 49 50 51 52 53 54 55 |
# File 'lib/rookie/tasks/git.rb', line 48 def tag!(tag_name) raise "Tag '#{tag_name}' is invalid" if tag_name.nil? or tag_name.empty? if already_tagged? tag_name raise "Tag '#{tag_name}' already in repository" else git.add_tag tag_name end end |