lib/danger/request_sources/vsts.rb in danger-9.1.0 vs lib/danger/request_sources/vsts.rb in danger-9.2.0

- old
+ new

@@ -1,7 +1,5 @@ -# coding: utf-8 - require "danger/helpers/comments_helper" require "danger/request_sources/vsts_api" module Danger module RequestSources @@ -23,18 +21,17 @@ end def initialize(ci_source, environment) self.ci_source = ci_source - @is_vsts_git = environment["BUILD_REPOSITORY_PROVIDER"] == "TfsGit" + @is_vsts_ci = environment.key? "DANGER_VSTS_HOST" - project, slug = ci_source.repo_slug.split("/") - @api = VSTSAPI.new(project, slug, ci_source.pull_request_id, environment) + @api = VSTSAPI.new(ci_source.repo_slug, ci_source.pull_request_id, environment) end def validates_as_ci? - @is_vsts_git + @is_vsts_ci end def validates_as_api_source? @api.credentials_given? end @@ -130,10 +127,11 @@ comment_content = comment[:content].nil? ? "" : comment[:content] # Skip the comment if it wasn't posted by danger next unless comment_content.include?("generated_by_#{danger_id}") # Skip the comment if it's an inline comment next unless c[:threadContext].nil? + # Updated the danger posted comment @api.update_comment(thread_id, comment_id, new_comment) comment_updated = true end # If no comment was updated, post a new one @@ -203,13 +201,13 @@ previous_violations.reject! { |v| messages_are_equivalent(v, m) } end matching_threads = danger_threads.select do |comment_data| if comment_data.key?(:threadContext) && !comment_data[:threadContext].nil? && - comment_data[:threadContext][:filePath] == m.file && - comment_data[:threadContext].key?(:rightFileStart) && - comment_data[:threadContext][:rightFileStart][:line] == m.line + comment_data[:threadContext][:filePath] == m.file && + comment_data[:threadContext].key?(:rightFileStart) && + comment_data[:threadContext][:rightFileStart][:line] == m.line # Parse it to avoid problems with strikethrough violation = violations_from_table(comment_data[:comments].first[:content]).first if violation messages_are_equivalent(violation, m) else @@ -255,10 +253,11 @@ cmp = proc do |a, b| next -1 unless a.file && a.line next 1 unless b.file && b.line next a.line <=> b.line if a.file == b.file + next a.file <=> b.file end # Sort to group inline comments by file { @@ -272,9 +271,8 @@ def merge_violations(*violation_groups) violation_groups.inject({}) do |accumulator, group| accumulator.merge(group) { |_, old, fresh| old + fresh } end end - end end end