Sha256: 15c8c060b97a422fac0cbb4d01bfd4094591724de4cafcb421b8b157e3308f6e

Contents?: true

Size: 1.47 KB

Versions: 2

Compression:

Stored size: 1.47 KB

Contents

class YouTrack::Client::ApplyIssueCommand < YouTrack::Client::Request
  include YouTrack::Client::ParameterRequest

  def identity
    params.fetch("id")
  end

  def real
    service.request(
      :path   => "/issue/#{identity}/execute",
      :query  => params,
      :method => :post,
    )
  end

  def mock
    issue      = find(:issues, identity)
    comment_id = "#{Cistern::Mock.random_numbers(2)}-#{Cistern::Mock.random_numbers(5)}"

    if comment = params["comment"]
      service.data[:comments][comment_id] = {
        "id"             => comment_id,
        "author"         => service.username,
        "deleted"        => false,
        "text"           => comment,
        "shownForIssuer" => false,
        "created"        => ms_time,
        "issueId"        => identity,
      }
    end

    if params["command"]
      commands = params["command"].split.each_slice(2).map { |a| [a[0], a[1]] }
      commands.each do |field, value|
        prototype = service.data[:custom_fields].fetch(field)

        bundle_value = if bundle = service.data[:bundles][prototype["defaultBundle"]]
                         bundle["values"].find { |v| v["value"] == value }
                       else # @fixme explode
                         {}
                       end

        if bundle_value["resolved"] == "true"
          issue["resolved"] = ms_time(Time.now)
        end

        issue["custom_fields"].find { |name, _| name == field }[1] = value
      end
    end

    service.response
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
you_track-0.4.6 lib/you_track/client/requests/apply_issue_command.rb
you_track-0.4.5 lib/you_track/client/requests/apply_issue_command.rb