class Tenma::Prepare::ReleaseBranch
Constants
- TEMP_DIR
Public Class Methods
new(context)
click to toggle source
# File lib/tenma/prepare/release_branch.rb, line 11 def initialize(context) @context = context end
Public Instance Methods
changelog(note)
click to toggle source
# File lib/tenma/prepare/release_branch.rb, line 46 def changelog(note) return '' if note.nil? ERB.new(note).result(binding) end
create()
click to toggle source
# File lib/tenma/prepare/release_branch.rb, line 15 def create @workdir = Dir.mktmpdir git = Git.clone(repo_url, TEMP_DIR, path: @workdir, depth: 1, branch: base_branch) git.branch(release_branch).checkout File.write(version_file, @context.options.raw.version) git.add(version_file) git.commit("version++") changelogs = @context.config.raw.release_branch&.changelogs changelogs&.each do |changelog| file = create_changelog_file(changelog) git.add(file) git.commit("Add changelog to #{changelog.path}") end git.push(git.remote("origin"), release_branch) end
create_changelog_file(changelog)
click to toggle source
# File lib/tenma/prepare/release_branch.rb, line 35 def create_changelog_file(changelog) FileUtils::mkdir_p(File.join(@workdir, TEMP_DIR, changelog.path)) file = changelog_file(changelog.path) File.open(file, 'w') do |file| file.puts changelog(changelog.body) end return file end
Private Instance Methods
base_branch()
click to toggle source
# File lib/tenma/prepare/release_branch.rb, line 58 def base_branch if @context.options.hotfix? ERB.new(@context.config.raw.release_branch.hotfix.base).result(binding) else ERB.new(@context.config.raw.release_branch.normal.base).result(binding) end end
changelog_file(path)
click to toggle source
# File lib/tenma/prepare/release_branch.rb, line 70 def changelog_file(path) file = parse_version.to_s + '.txt' File.absolute_path(File.join(@workdir, TEMP_DIR, path, file)) end
parse_version()
click to toggle source
# File lib/tenma/prepare/release_branch.rb, line 75 def parse_version version = @context.options.raw.version major = version.split('.')[0].to_i minor = version.split('.')[1].to_i patch = version.split('.')[2].to_i return major * 1000 * 1000 + minor * 1000 + patch end
release_branch()
click to toggle source
# File lib/tenma/prepare/release_branch.rb, line 83 def release_branch if @context.options.hotfix? ERB.new(@context.config.raw.release_branch.hotfix.branch).result(binding) else ERB.new(@context.config.raw.release_branch.normal.branch).result(binding) end end
repo_url()
click to toggle source
# File lib/tenma/prepare/release_branch.rb, line 53 def repo_url base = URI.parse(@context.config.raw.github.web_url) return base.scheme + "://" + @context.options.raw.github_token + ":x-oauth-basic@" + base.host + "/" + @context.config.github_reponame + ".git" end
version_file()
click to toggle source
# File lib/tenma/prepare/release_branch.rb, line 66 def version_file File.absolute_path(File.join(@workdir, TEMP_DIR, @context.config.raw.release_branch.version_file)) end