Sha256: 2731fbdeefb114fe8bd7681b7528b810b23fac5d8659b59f9a28252cc417d195

Contents?: true

Size: 1.94 KB

Versions: 31

Compression:

Stored size: 1.94 KB

Contents

# frozen_string_literal: true

module CiToolkit
  # Utilities to create markdown text from build messages
  class PrMessengerText
    def initialize(
      build = CiToolkit::Build.new,
      env = CiToolkit::BitriseEnv.new
    )
      @build = build
      @app_url = env.app_url
    end

    def for_new_build(name, version_name, tag)
      "#### New `#{name}` build deployed 🚀\nVersion **#{version_name}** with\
 build number **#{@build.number}** on tag **#{tag}** deployed\
 from [this](#{@build.url}) build"
    end

    def for_build_failure(reason)
      "#{build_failure_title}️\n#{body(reason.to_s)}"
    end

    def for_duplicated_files_report(report)
      "#{duplicated_files_title}\n#{body(report)}"
    end

    def for_lint_report(report)
      "#{lint_report_title}\n#{body(report)}"
    end

    def build_failure_title
      "#### Build failed ⛔"
    end

    def duplicated_files_title
      warning_with_message("There are duplicated files found")
    end

    def lint_report_title
      "#### Swiftlint report 🕵️‍♀️"
    end

    def realm_modified_warning_title
      warning_with_message("Realm module modified. Did you remember to add migrations?")
    end

    def big_pr_warning_title
      warning_with_message("Big PR")
    end

    def work_in_progress_title
      "PR is Work in Progress 🚧"
    end

    def warning_with_message(message)
      "Warning: #{message} ⚠️"
    end

    def create_duplicate_files_report(finder)
      report = ""
      finder.duplicate_groups.each do |dups|
        report = "#{report}\n#{dups.join("\n")}\n"
      end
      report
    end

    def footer
      "###### 🔮 _Comment via [CI](#{@app_url}) on build [#{@build.number}](#{@build.url})_"
    end

    def body(text)
      formatted_text = "```\n#{text.to_s[0...60_000]}\n```"
      formatted_text = "<details>\n<summary>Details</summary>\n\n#{formatted_text}\n</details>" if text.lines.count > 6
      "#{formatted_text}\n"
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
ci_toolkit-1.6.3 lib/ci_toolkit/pr_messenger_text.rb
ci_toolkit-1.6.2 lib/ci_toolkit/pr_messenger_text.rb
ci_toolkit-1.6.1 lib/ci_toolkit/pr_messenger_text.rb
ci_toolkit-1.6.0 lib/ci_toolkit/pr_messenger_text.rb
ci_toolkit-1.5.24 lib/ci_toolkit/pr_messenger_text.rb
ci_toolkit-1.5.23 lib/ci_toolkit/pr_messenger_text.rb
ci_toolkit-1.5.22 lib/ci_toolkit/pr_messenger_text.rb
ci_toolkit-1.5.21 lib/ci_toolkit/pr_messenger_text.rb
ci_toolkit-1.5.20 lib/ci_toolkit/pr_messenger_text.rb
ci_toolkit-1.5.19 lib/ci_toolkit/pr_messenger_text.rb
ci_toolkit-1.5.17 lib/ci_toolkit/pr_messenger_text.rb
ci_toolkit-1.5.16 lib/ci_toolkit/pr_messenger_text.rb
ci_toolkit-1.5.15 lib/ci_toolkit/pr_messenger_text.rb
ci_toolkit-1.5.14 lib/ci_toolkit/pr_messenger_text.rb
ci_toolkit-1.5.13 lib/ci_toolkit/pr_messenger_text.rb
ci_toolkit-1.5.12 lib/ci_toolkit/pr_messenger_text.rb
ci_toolkit-1.5.11 lib/ci_toolkit/pr_messenger_text.rb
ci_toolkit-1.5.10 lib/ci_toolkit/pr_messenger_text.rb
ci_toolkit-1.5.9 lib/ci_toolkit/pr_messenger_text.rb
ci_toolkit-1.5.8 lib/ci_toolkit/pr_messenger_text.rb