Skip to content

Commit

Permalink
Add the ability to push when done
Browse files Browse the repository at this point in the history
If commit_finalize is true, Reissue will commit the changes.
Use push_finalize to configure whether or not these changes should be automatically pushed
to the remote repository.

Set push_finalize to ':branch' to create a separate branch. This is the default.
Or set it to true to push directly to the working branch.
Set it to false to disable this feature independently of commit_finalize.
  • Loading branch information
saturnflyer committed Sep 6, 2024
1 parent d50bf75 commit ce052a3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [0.2.2] - Unreleased

### Added

- Add a `reissue:branch` task to create a new branch for the next version
- Add a `reissue:push` task to push the new branch to the remote repository

### Fixed

- Require the 'date' library in tests to ensure the Date constant is present
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ This will add the following rake tasks:
the latest version.
- `rake reissue:reformat[version_limit]` - Reformat the CHANGELOG.md file and
optionally limit the number of versions to maintain.
- `rake reissue:branch[branch-name]` - Create a new branch for the next version.
Controlled by the `push_finalize` and `commit_finalize` options.
- `rake reissue:push` - Push the changes to the remote repository. Controlled
by the `push_finalize` and `commit_finalize` options.

This will also update the `build` task from rubygems to first run
`reissue:finalize` and then build the gem, ensuring that your changelog is
Expand Down Expand Up @@ -105,6 +109,9 @@ Reissue::Task.create :your_name_and_namespace do |task|

# Optional: Whether or not to commit the results of the finalize task. Defaults to true.
task.commit_finalize = false

# Optional: Whether to push the changes automatically. Defaults to :branch.
task.push_finalize = :branch # or false, or true to push the working branch
end
```

Expand Down
30 changes: 30 additions & 0 deletions lib/reissue/rake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ def updated_paths
# Whether to commit the finalize change to the changelog. Default: true.
attr_accessor :commit_finalize

# Whether to branch and push the changes. Default: :branch.
# Requires commit_finialize to be true.
#
# Set this to false to disable pushing.
# Set this to true to push to the current branch.
# Set this to :branch to push to a new branch.
attr_accessor :push_finalize

def initialize(name = :reissue)
@name = name
@description = "Prepare the code for work on a new version."
Expand All @@ -52,10 +60,19 @@ def initialize(name = :reissue)
@changelog_file = "CHANGELOG.md"
@commit = true
@commit_finalize = true
@push_finalize = false
@version_limit = 2
@version_redo_proc = nil
end

def finalize_with_branch?
push_finalize == :branch
end

def push_finalize?
!!push_finalize
end

def define
desc description
task name, [:segment] do |task, args|
Expand Down Expand Up @@ -98,12 +115,25 @@ def define
version, date = Reissue.finalize(date, changelog_file:)
finalize_message = "Finalize the changelog for version #{version} on #{date}"
if commit_finalize
Rake::Task["#{name}:branch"].invoke("reissue/#{version}") if finalize_with_branch?
system("git add -u")
system("git commit -m '#{finalize_message}'")
Rake::Task["#{name}:push"].invoke if push_finalize?
else
system("echo '#{finalize_message}'")
end
end

desc "Create a new branch for the next version."
task "#{name}:branch" => [:branch] do |task, args|
raise "No branch name specified" unless args[:branch]
system("git checkout -b #{args[:branch]}")
end

desc "Push the current branch to the remote repository."
task "#{name}:push" do
system("git push origin HEAD")
end
end
end
end

0 comments on commit ce052a3

Please sign in to comment.