Class: ChangelogMerger::Merger
- Inherits:
-
Object
- Object
- ChangelogMerger::Merger
- Defined in:
- lib/changelog_merger.rb
Overview
Your code goes here…
Instance Method Summary collapse
- #add_commit_push ⇒ Object
- #check_existing_changelog_file ⇒ Object
- #check_exit_status(output) ⇒ Object
- #clone_repo_and_cd ⇒ Object
- #execute_line(line) ⇒ Object
- #generate_change_log ⇒ Object
- #generate_pr_message ⇒ Object
- #go_to_work_dir ⇒ Object
-
#initialize ⇒ Merger
constructor
A new instance of Merger.
- #run_generator ⇒ Object
Constructor Details
#initialize ⇒ Merger
8 9 10 |
# File 'lib/changelog_merger.rb', line 8 def initialize = Parser. end |
Instance Method Details
#add_commit_push ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'lib/changelog_merger.rb', line 79 def add_commit_push execute_line('hub fork') execute_line('git checkout -b add-change-log-file') execute_line("git add #{@options[:output]}") execute_line("git commit -v -m '#{@options[:message]}'") execute_line('git push skywinder') # execute_line('git push') execute_line("hub pull-request -m '#{@options[:pr_message]}' -o") end |
#check_existing_changelog_file ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/changelog_merger.rb', line 30 def check_existing_changelog_file if [:output] == 'CHANGELOG.md' if File.exist? [:output] puts "#{@options[:output]} found" [:chagelog_exists] = 'CHANGELOG.md' extension = File.extname([:output]) base = File.basename([:output], extension) [:output] = base + '_AUTO' + extension puts "Change it to: #{@options[:output]}" end end if File.exist? 'HISTORY.md' [:chagelog_exists] = 'HISTORY.md' end end |
#check_exit_status(output) ⇒ Object
114 115 116 117 118 119 |
# File 'lib/changelog_merger.rb', line 114 def check_exit_status(output) if $?.exitstatus != 0 puts "Output:\n#{output}\nExit status = #{$?.exitstatus} ->Terminate script." exit end end |
#clone_repo_and_cd ⇒ Object
93 94 95 96 97 98 99 100 |
# File 'lib/changelog_merger.rb', line 93 def clone_repo_and_cd if Dir.exist?([:project]) execute_line("rm -rf #{@options[:project]}") end execute_line("hub clone #{@options[:repo]}") [:dry_run] || Dir.chdir("./#{@options[:project]}") puts "Go to #{Dir.pwd}" end |
#execute_line(line) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/changelog_merger.rb', line 102 def execute_line(line) if [:dry_run] puts "Dry run: #{line}" return nil end puts line value = %x(#{line}) puts value check_exit_status(value) value end |
#generate_change_log ⇒ Object
89 90 91 |
# File 'lib/changelog_merger.rb', line 89 def generate_change_log execute_line("github_changelog_generator #{@options[:repo]} -o #{@options[:output]}") end |
#generate_pr_message ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/changelog_merger.rb', line 47 def [:pr_message] = "Add automatically generated change log file. Hi, as I can see, you are carefully fill tags and labels for issues in your repo. For such cases I create a [github_changelog_generator](https://github.com/skywinder/github-changelog-generator), that generate change log file based on **tags**, **issues** and merged **pull requests** from :octocat: Issue Tracker. This PR add change log file to your repo (generated by this script). You can check, how it is look like here: [Change Log](https://github.com/skywinder/#{@options[:project]}/blob/add-change-log-file/#{@options[:output]}) Some essential features, that has this script: - it **exclude** not-related to changelog issues (any issue, that has label \`question\` \`duplicate\` \`invalid\` \`wontfix\` ) - Distinguish issues **according labels**: - Merged pull requests (all \`merged\` pull-requests) - Bug fixes (by label \`bug\` in issue) - Enhancements (by label \`enhancement\` in issue) - Issues (closed issues \`w/o any labels\`) - Generate neat Change Log file according basic [change log guidelines](http://keepachangelog.com). You can easily update this file in future by simply run script: \`github_changelog_generator #{@options[:repo]}\` in your repo folder and it make your Change Log file up-to-date again! Hope you find this commit as useful. :wink:" unless [:chagelog_exists].nil? [:pr_message] += " P.S. I know that you already has #{@options[:chagelog_exists]} file but give this script a chance and compare it with yours change log. Hope, you will love it! :blush:" end end |
#go_to_work_dir ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/changelog_merger.rb', line 121 def go_to_work_dir Dir.chdir([:path]) merger_folder = 'changelog_merger_dir' unless Dir.exist?(merger_folder) puts "Creating directory #{merger_folder}" Dir.mkdir(merger_folder) end Dir.chdir("./#{merger_folder}") puts "Go to #{Dir.pwd}" end |
#run_generator ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/changelog_merger.rb', line 12 def run_generator begin if [:run_wo_pr] generate_change_log execute_line("open #{@options[:output]}") else go_to_work_dir clone_repo_and_cd check_existing_changelog_file generate_change_log add_commit_push end rescue execute_line('git push skywinder :add-change-log-file && git checkout master && git branch -D add-change-log-file') end end |