diff --git a/lib/core.rb b/lib/core.rb index f704de1..e39e1c6 100644 --- a/lib/core.rb +++ b/lib/core.rb @@ -10,7 +10,7 @@ module Core extend self def cli_text(file) cli = < [--to=] [options] [-v...] [-q...] [-c ( )]... + #{file} from [--to=] [options] [-v...] [-q...] [-c ( )]... #{file} from-latest-tag [--to=] [options] [-v...] [-q...] [-c ]... #{file} -h|--help @@ -19,16 +19,16 @@ def cli_text(file) --from Specify where to stop searching for commit. For git this takes anything that rev-parse accepts. Such as HEAD~3 / Git sha or tag name. - --from-latest-tag Looks for the newest commit that the tag with points to. - - --settings= Path to the settings file used. If nothing is specified default_settings.yml is used + --from-latest-tag Looks for the newest commit that the tag with points to. - --properties= + --settings= Path to the settings file used. If nothing is specified default_settings.yml is used - Allows you to pass in additional variables to the Liquid templates. Must be in JSON format. Namespaced under properties.* in + --properties= + + Allows you to pass in additional variables to the Liquid templates. Must be in JSON format. Namespaced under properties.* in your Liquid templates. Referenced like so '{{properties.[your-variable]}}' in your templates. - JSON keys and values should be wrapped in quotation marks '"' like so: --properties='{ "title":"PAC Changelog" }' + JSON keys and values should be wrapped in quotation marks '"' like so: --properties='{ "title":"PAC Changelog" }' -v More verbose output. Can be repeated to increase output verbosity or to cancel out -q @@ -36,7 +36,7 @@ def cli_text(file) -c Override username and password. Example: `-c my_user my_password jira`. This will set username and password for task system jira. DOCOPT - cli + cli end def settings @@ -44,14 +44,14 @@ def settings {} else @@settings - end + end end def settings=(val) @@settings = val end - #Reads the command line options. And based on this it will return the + #Reads the command line options. And based on this it will return the #path of the settings file to use. def read_settings_file(input) settings_file = File.join(Dir.pwd, 'settings/default_settings.yml') @@ -59,7 +59,7 @@ def read_settings_file(input) settings_file = input['--settings'] end - unless File.exists?(settings_file) + unless File.exists?(settings_file) raise "Settings file '#{settings_file}' does not exist" end @@ -79,10 +79,6 @@ def generate_settings(cmdline, configuration) loaded[:properties] = {} end - unless cmdline['--pattern'].nil? - loaded[:vcs][:release_regex] = input['--pattern'] - end - #User name override if cmdline['-c'] (0..cmdline['-c']-1).each do |it| @@ -97,31 +93,31 @@ def generate_settings(cmdline, configuration) end end end - - unless cmdline['--properties'].nil? + + unless cmdline['--properties'].nil? json_value = JSON.parse(cmdline['--properties']) loaded[:properties] = loaded[:properties].merge(json_value) end loaded[:verbosity] = Logging.calc_verbosity(cmdline) - loaded + loaded end - + #Requires a configuration section for the task system to be applied def apply_task_system(task_system, tasks) val = true Logging.verboseprint(1, "[PAC] Applying task system #{task_system[:name]}") - if task_system[:name] == 'trac' + if task_system[:name] == 'trac' val = Task::TracTaskSystem.new(task_system).apply(tasks) end if task_system[:name] == 'jira' val = Task::JiraTaskSystem.new(task_system).apply(tasks) - end + end if task_system[:name] == 'fogbugz' val = Task::FogBugzTaskSystem.new(task_system).apply(tasks) end val end - + def vcs if @@settings[:vcs][:type] == 'git' Vcs::GitVcs.new(settings[:vcs]) @@ -133,7 +129,7 @@ def vcs end #This is now core functionality. The task of generating a collection of tasks based on the commits found - #This takes in a PACCommitCollection and returns a PACTaskCollection + #This takes in a PACCommitCollection and returns a PACTaskCollection def task_id_list(commits) regex_arr = [] @@ -145,20 +141,20 @@ def task_id_list(commits) #Regex ~ Eacb regex in the task system settings[:task_systems].each do |ts| #Loop over each task system. Parse commits for matches - if ts.has_key? :delimiter - split_pattern = eval(ts[:delimiter]) + if ts.has_key? :delimiter + split_pattern = eval(ts[:delimiter]) end - if ts.has_key? :regex + if ts.has_key? :regex tasks_for_commit = c_pac.matchtask(ts[:regex], split_pattern) - tasks_for_commit.each do |t| + tasks_for_commit.each do |t| t.applies_to = ts[:name] - end + end #If a task was found unless tasks_for_commit.empty? - referenced = true - tasks.add(tasks_for_commit) - end + referenced = true + tasks.add(tasks_for_commit) + end end end @@ -166,10 +162,10 @@ def task_id_list(commits) task = Model::PACTask.new task.add_commit(c_pac) tasks.add(task) - end + end end - tasks + tasks end end diff --git a/settings/default_settings.yml b/settings/default_settings.yml index adc8a7a..619205b 100644 --- a/settings/default_settings.yml +++ b/settings/default_settings.yml @@ -21,18 +21,8 @@ :usr: "user" :pw: "password" :regex: - - { pattern: '/(PRJ-\d+)/i', label: jira } - - - :name: trac - :trac_url: "https://my.trac.site" - :trac_usr: "user" - :trac_pwd: "pass" - :regex: - - { pattern: '/Ticket-(\d+)/i', label: trac } + - { pattern: '/(PRJ-\d+)/i', label: jira } :vcs: :type: git - :usr: - :pwd: :repo_location: '.' - :release_regex: 'tags' diff --git a/spec/pactask_spec.rb b/spec/pactask_spec.rb index 1e624df..ef269e3 100644 --- a/spec/pactask_spec.rb +++ b/spec/pactask_spec.rb @@ -17,8 +17,6 @@ end end - - describe "applies_to" do let(:pt) { Model::PACTask.new() } diff --git a/test/resources/GetCommitMessagesTestRepository_settings.yml b/test/resources/GetCommitMessagesTestRepository_settings.yml index 8ff94d5..7510f7c 100644 --- a/test/resources/GetCommitMessagesTestRepository_settings.yml +++ b/test/resources/GetCommitMessagesTestRepository_settings.yml @@ -16,5 +16,4 @@ :type: git :usr: :pwd: - :repo_location: 'test/resources/GetCommitMessagesTestRepository' - :release_regex: 'tags' \ No newline at end of file + :repo_location: 'test/resources/GetCommitMessagesTestRepository' \ No newline at end of file diff --git a/test/resources/IncludesSinceTestRepository_settings.yml b/test/resources/IncludesSinceTestRepository_settings.yml index 6a5199c..f5a734e 100644 --- a/test/resources/IncludesSinceTestRepository_settings.yml +++ b/test/resources/IncludesSinceTestRepository_settings.yml @@ -14,7 +14,4 @@ :vcs: :type: git - :usr: - :pwd: - :repo_location: 'test/resources/IncludesSinceTestRepository' - :release_regex: 'tags' \ No newline at end of file + :repo_location: 'test/resources/IncludesSinceTestRepository' \ No newline at end of file diff --git a/test/resources/idReportTestRepository_settings.yml b/test/resources/idReportTestRepository_settings.yml index ffa272b..dc07ac1 100644 --- a/test/resources/idReportTestRepository_settings.yml +++ b/test/resources/idReportTestRepository_settings.yml @@ -15,7 +15,4 @@ :vcs: :type: git - :usr: - :pwd: - :repo_location: 'test/resources/idReportTestRepository' - :release_regex: 'tags' \ No newline at end of file + :repo_location: 'test/resources/idReportTestRepository' \ No newline at end of file diff --git a/test/resources/pac-test-repo_settings.yml b/test/resources/pac-test-repo_settings.yml index 72585eb..43afcef 100644 --- a/test/resources/pac-test-repo_settings.yml +++ b/test/resources/pac-test-repo_settings.yml @@ -14,7 +14,4 @@ :vcs: :type: git - :usr: - :pwd: - :repo_location: 'test/resources/pac-test-repo' - :release_regex: 'tags' \ No newline at end of file + :repo_location: 'test/resources/pac-test-repo' \ No newline at end of file diff --git a/test/resources/repo_with_tags_settings.yml b/test/resources/repo_with_tags_settings.yml index 154fb60..f94915c 100644 --- a/test/resources/repo_with_tags_settings.yml +++ b/test/resources/repo_with_tags_settings.yml @@ -15,7 +15,4 @@ :vcs: :type: git - :usr: - :pwd: :repo_location: 'test/resources/repo_with_tags' - :release_regex: 'tags' diff --git a/test/unit/configurationtest.rb b/test/unit/configurationtest.rb index d310882..908b07c 100644 --- a/test/unit/configurationtest.rb +++ b/test/unit/configurationtest.rb @@ -11,8 +11,8 @@ def test_configuration_parsing settings_file = File.join(File.dirname(__FILE__), '../../settings/default_settings.yml') loaded = YAML::load(File.open(settings_file)) assert_true(loaded.has_key?(:general)) - assert_equal(3, loaded[:task_systems].length) - assert_equal(3, loaded[:templates].length) + assert_equal(2, loaded[:task_systems].length) + assert_equal(3, loaded[:templates].length) end #The everything ok scenario @@ -21,7 +21,7 @@ def test_properties_parsing_ok arguments = { '--settings' => "#{settings_file}", '--properties' => '{"title" : "PAC Changelog Name Override" }' } file_parsed = Core.read_settings_file(arguments) settings_parsed = Core.generate_settings(arguments, file_parsed) - assert_equal('PAC Changelog Name Override', settings_parsed[:properties]['title']) + assert_equal('PAC Changelog Name Override', settings_parsed[:properties]['title']) defined = Report::Generator.new.to_liquid_properties(settings_parsed) assert_equal('PAC Changelog Name Override', defined['properties']['title'] ) assert_equal('PAC Changelog Name Override', settings_parsed[:properties]['title']) @@ -31,39 +31,36 @@ def test_properties_parsing_ok def test_properties_incorrect_json settings_file = File.join(File.dirname(__FILE__), '../../settings/default_settings.yml') arguments = { '--settings' => "#{settings_file}", '--properties' => "{ title'PAC Chang} " } - file_parsed = Core.read_settings_file(arguments) + file_parsed = Core.read_settings_file(arguments) assert_raise do |err| settings_parsed = Core.generate_settings(arguments, file_parsed) end end - + #Credentials test (test the -c option. for username and password overrides) def test_configure_credentials settings_file = File.join(File.dirname(__FILE__), '../../settings/default_settings.yml') - #Notice the wierd way docopt handles it. The -c flag is a repeat flag, each option is then grouped positionally. So for each 'c' specified + #Notice the wierd way docopt handles it. The -c flag is a repeat flag, each option is then grouped positionally. So for each 'c' specified #c is incremented, and the index of the then the value specified. - arguments = { '--settings' => "#{settings_file}", '--properties' => '{"title" : "PAC Changelog Name Override" }', '-c' => 2, - '' => ["newuser", "tracuser"], - '' => ["newpassword", "tracpassword"], - '' => ["jira", "trac"] } + arguments = { '--settings' => "#{settings_file}", '--properties' => '{"title" : "PAC Changelog Name Override" }', '-c' => 2, + '' => ["newuser", "tracuser"], + '' => ["newpassword", "tracpassword"], + '' => ["jira", "trac"] } file_parsed = Core.read_settings_file(arguments) - settings_parsed = Core.generate_settings(arguments, file_parsed) + settings_parsed = Core.generate_settings(arguments, file_parsed) assert_equal('newuser', settings_parsed[:task_systems][1][:usr]) assert_equal('newpassword', settings_parsed[:task_systems][1][:pw]) - - assert_equal('tracuser', settings_parsed[:task_systems][2][:usr]) - assert_equal('tracpassword', settings_parsed[:task_systems][2][:pw]) end - def test_raise_exception_on_missing_settings_file + def test_raise_exception_on_missing_settings_file config = { '--settings' => 'not-there.yml' } - assert_raise RuntimeError do + assert_raise RuntimeError do Core.read_settings_file(config) end #Assert the inverse as well config['--settings'] = 'pac_settings.yml' Core.read_settings_file(config) - end + end -end \ No newline at end of file +end