Sha256: fa3d08f741133513db09a45942eb4b77cc4be62391bbd176a01425ee2f3755c9

Contents?: true

Size: 1.54 KB

Versions: 11

Compression:

Stored size: 1.54 KB

Contents

module CC
  class Service
    class PullRequestsPresenter
      include ActiveSupport::NumberHelper

      def initialize(payload)
        issue_comparison_counts = payload["issue_comparison_counts"]

        if issue_comparison_counts
          @fixed_count = issue_comparison_counts["fixed"]
          @new_count = issue_comparison_counts["new"]
        end
      end

      def error_message
        "Code Climate encountered an error attempting to analyze this pull request."
      end

      def pending_message
        "Code Climate is analyzing this code."
      end

      def skipped_message
        "Code Climate has skipped analysis of this commit."
      end

      def success_message
        if both_issue_counts_zero?
          "Code Climate didn't find any new or fixed issues."
        else
          "Code Climate found #{formatted_issue_counts}."
        end
      end

    private

      def both_issue_counts_zero?
        issue_counts.all?(&:zero?)
      end

      def formatted_fixed_issues
        if @fixed_count > 0
          "#{number_to_delimited(@fixed_count)} fixed #{"issue".pluralize(@fixed_count)}"
        else
          nil
        end
      end

      def formatted_new_issues
        if @new_count > 0
          "#{number_to_delimited(@new_count)} new #{"issue".pluralize(@new_count)}"
        else
          nil
        end
      end

      def formatted_issue_counts
        [formatted_new_issues, formatted_fixed_issues].compact.to_sentence
      end

      def issue_counts
        [@new_count, @fixed_count]
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
codeclimate-services-1.2.0 lib/cc/presenters/pull_requests_presenter.rb
codeclimate-services-1.1.0 lib/cc/presenters/pull_requests_presenter.rb
codeclimate-services-1.0.1 lib/cc/presenters/pull_requests_presenter.rb
codeclimate-services-1.0.0 lib/cc/presenters/pull_requests_presenter.rb
codeclimate-services-0.6.2 lib/cc/presenters/pull_requests_presenter.rb
codeclimate-services-0.6.1 lib/cc/presenters/pull_requests_presenter.rb
codeclimate-services-0.6.0 lib/cc/presenters/pull_requests_presenter.rb
codeclimate-services-0.5.3 lib/cc/presenters/pull_requests_presenter.rb
codeclimate-services-0.5.2 lib/cc/presenters/pull_requests_presenter.rb
codeclimate-services-0.5.1 lib/cc/presenters/pull_requests_presenter.rb
codeclimate-services-0.5.0 lib/cc/presenters/pull_requests_presenter.rb