github.com/ezbuy/gauge@v0.9.4-0.20171013092048-7ac5bd3931cd/build/create_release_text.rb (about) 1 # Copyright 2015 ThoughtWorks, Inc. 2 3 # This file is part of Gauge. 4 5 # Gauge is free software: you can redistribute it and/or modify 6 # it under the terms of the GNU General Public License as published by 7 # the Free Software Foundation, either version 3 of the License, or 8 # (at your option) any later version. 9 10 # Gauge is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 15 # You should have received a copy of the GNU General Public License 16 # along with Gauge. If not, see <http://www.gnu.org/licenses/>. 17 18 require 'net/http' 19 require 'uri' 20 require 'json' 21 22 if ARGV.length < 1 23 puts 'Usage: ruby create_release_text.rb <repo name> 24 Example: ruby create_release_text.rb gauge. 25 ' 26 exit 1 27 end 28 29 repo_name = ARGV[0] 30 uri = URI("https://api.github.com/repos/getgauge/#{repo_name}/releases/latest") 31 timestamp = JSON.parse(Net::HTTP.get(uri))['published_at'] 32 33 if timestamp.nil? || timestamp.empty? 34 uri = URI("https://api.github.com/search/issues?q=repo:getgauge/#{repo_name}+state:closed") 35 else 36 uri = URI("https://api.github.com/search/issues?q=repo:getgauge/#{repo_name}+closed:>#{timestamp}") 37 end 38 response = Net::HTTP.get(uri) 39 40 data = JSON.parse(response) 41 42 categories = {"new feature" => [], "enhancement" => [], "bug" => [], "misc" => []} 43 headers = {"new feature" => "New Features", "enhancement" => "Enhancements", "bug" => "Bug Fixes", "misc" => "Miscellaneous"} 44 45 data['items'].each do |i| 46 issue_text = "- ##{i['number']} - #{i['title']}" 47 issue_labels = i['labels'].map {|x| x['name']} 48 if (issue_labels & ["moved", "duplicate"]).empty? 49 label = issue_labels & categories.keys 50 categories[label[0] || "misc"] << issue_text 51 end 52 end 53 54 categories.each_key do |k| 55 puts "## #{headers[k]}\n\n" 56 categories[k].each {|v| puts v} 57 puts "\n" 58 end