From 6775e9808da54000307cba044c4c1406a17dc601 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Tue, 4 Nov 2014 17:28:39 +0200 Subject: [PATCH] Move all variables to constants.rb Add example file to git --- .gitignore | 1 + changelog_generator.rb | 43 ++++++++++++++++++++---------------------- dummy_constants.rb | 4 ++++ 3 files changed, 25 insertions(+), 23 deletions(-) create mode 100644 dummy_constants.rb diff --git a/.gitignore b/.gitignore index 8617481..2b94c54 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ output.txt +constants.rb diff --git a/changelog_generator.rb b/changelog_generator.rb index ce98b77..c225783 100755 --- a/changelog_generator.rb +++ b/changelog_generator.rb @@ -3,14 +3,7 @@ require 'github_api' require 'json' - -@project_path = '/Users/petrkorolev/repo/ActionSheetPicker-3.0' - -@github_user = 'skywinder' -@github_repo_name = 'ActionSheetPicker-3.0' - -tag1 = '1.1.21' -tag2 = '1.2.0' +require_relative 'constants' def print_json(json) puts JSON.pretty_generate(json) @@ -22,13 +15,13 @@ end def findPrevTagDate - value1 = exec_command "git log --tags --simplify-by-decoration --pretty=\"format:%ci %d\" | grep tag" + value1 = exec_command "git log --tags --simplify-by-decoration --pretty=\"format:%ci %d\" | grep tag" unless value1 puts 'not found this tag' exit end - scan_results = value1.scan(/.*tag.*/) + scan_results = value1.scan(/.*tag.*/) prev_tag = scan_results[1] @@ -44,20 +37,25 @@ end def getAllClosedPullRequests - github = Github.new oauth_token: '8587bb22f6bf125454768a4a19dbcc774ea68d48' - issues = github.pull_requests.list 'skywinder', 'ActionSheetPicker-3.0', :state => 'closed' - json = issues.body - json.each { |dict| - # print_json dict - # puts "##{dict[:number]} - #{dict[:title]} (#{dict[:closed_at]})" - } + if @oauth_token.length + github = Github.new oauth_token: @oauth_token + else + github = Github.new + end + issues = github.pull_requests.list @github_user, @github_repo_name, :state => 'closed' + json = issues.body + + json.each { |dict| + # print_json dict + # puts "##{dict[:number]} - #{dict[:title]} (#{dict[:closed_at]})" + } + + json - json end - -def compund_changelog (tag_time, pull_requests) +def compund_changelog(tag_time, pull_requests) log = '' last_tag = exec_command('git describe --abbrev=0 --tags').strip log += "## [#{last_tag}] (https://github.com/#{@github_user}/#{@github_repo_name}/tree/#{last_tag})\n" @@ -67,7 +65,7 @@ def compund_changelog (tag_time, pull_requests) pull_requests.each { |dict| merge = "#{dict[:title]} ([\\##{dict[:number]}](https://github.com/#{@github_user}/#{@github_repo_name}/pull/#{dict[:number]}))\n" - log += "- #{merge}" + log += "- #{merge}" } puts log @@ -84,5 +82,4 @@ pull_requests.delete_if { |req| t < tag_time } - -compund_changelog(tag_time, pull_requests) \ No newline at end of file +compund_changelog tag_time, pull_requests \ No newline at end of file diff --git a/dummy_constants.rb b/dummy_constants.rb new file mode 100644 index 0000000..6c58eae --- /dev/null +++ b/dummy_constants.rb @@ -0,0 +1,4 @@ +@project_path = '/path/to/project' +@github_user = 'login' +@github_repo_name = 'projectName' +@oauth_token = 'your40digitGitHubToken'