Class: YouTrack::Client::CreateIssue

Inherits:
Request
  • Object
show all
Defined in:
lib/you_track/client/requests/create_issue.rb

Overview

Instance Method Summary collapse

Methods inherited from Request

#find, #ms_time, #require_parameters

Instance Method Details

#mock(_params) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/you_track/client/requests/create_issue.rb', line 11

def mock(_params)
  params = Cistern::Hash.stringify_keys(_params)

  issue = Cistern::Hash.slice(params, "project", "description", "summary")

  project_id = issue["projectShortName"] = issue.delete("project")
  find(:projects, project_id)

  index = service.data[:issues].size + 1
  project_index = service.data[:issues].values.select { |i| i["projectShortName"] == project_id }.size

  identity = "#{project_id}-#{index}"

  issue.merge!(
    "id"               => identity,
    "tag"              => "",
    "numberInProject"  => project_index,
    "created"          => ms_time(Time.now),
    "updated"          => ms_time(Time.now),
    "updaterName"      => service.username,
    "updaterFullName"  => service.username.capitalize,
    "reporterName"     => service.username,
    "reporterFullName" => service.username.capitalize,
    "commentsCount"    => "0",
    "votes"            => "0",
    "attachments"      => [],
    "custom_fields"    => [],
  )

  service.data[:project_custom_fields][project_id].each { |prototype|
    default = if bundle = service.data[:bundles][prototype["defaultBundle"]]
                bundle["values"][prototype["attachBundlePolicy"].to_i]
              else
                {}
              end

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

    issue["custom_fields"] << [ prototype["name"], default["value"] ]
  }

  service.data[:issues][identity] = issue

  service.response(
    :response_headers => {
      "Location" => service.url_for("/issue/#{identity}"),
    },
    :status => 201,
  )
end

#real(params) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/you_track/client/requests/create_issue.rb', line 3

def real(params)
  service.request(
    :path   => "/issue",
    :method => :put,
    :params => params,
  )
end