Class: Redmine::Reporting::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/redmine/reporting/report.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Report

Returns a new instance of Report.



10
11
12
# File 'lib/redmine/reporting/report.rb', line 10

def initialize(options)
  @options = options.dup.freeze
end

Instance Method Details

#commitObject



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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/redmine/reporting/report.rb', line 30

def commit
  reference_id = "#{Zlib.crc32(Time.now.to_f.to_s).to_s(16)}#{Zlib.crc32(@subject).to_s(16)}#{Zlib.crc32(@description).to_s(16)}"

  options = (config[:http_options] || {}).merge({
    headers: {
      'Content-type' => 'application/json',
      'X-Redmine-API-Key' => config[:api_key]
    }
  })

  if saved_issue_id.nil?
    # add reference_id to description if updates are disabled
    desc = config[:no_update] ? "h1. #{reference_id}\n\n#{@description}" : @description

    resp = HTTParty.post("#{config[:base_url]}/issues.json", options.merge({
        body: {
          issue: {
            subject: @subject.strip,
            project_id: config[:project],
            description: desc.strip,
            tracker_id: config[:tracker],
            category_id: config[:category]
          }
        }.to_json
      }))

    iid = resp['issue']['id'] rescue nil

    save_issue_data(iid, reference_id) unless iid.nil?
  end

  return false if (issue_id = saved_issue_id).nil?

  return saved_reference_id if config[:no_update]

  resp = HTTParty.put("#{config[:base_url]}/issues/#{issue_id}.json", options.merge({
      body: {
        issue: {
          notes: "h1. #{reference_id}\n\n#{@notes}".strip
        }
      }.to_json
    }))

  save_issue_data(issue_id, reference_id)

  reference_id
rescue => e
  # TODO ignore
  nil
end

#description(d = nil, &block) ⇒ Object



18
19
20
21
22
# File 'lib/redmine/reporting/report.rb', line 18

def description(d=nil, &block)
  @description ||= ''
  @current_var = @description
  data_to_syntax(d, &block)
end

#notes(n = nil, &block) ⇒ Object



24
25
26
27
28
# File 'lib/redmine/reporting/report.rb', line 24

def notes(n=nil, &block)
  @notes ||= ''
  @current_var = @notes
  data_to_syntax(n, &block)
end

#subject(s) ⇒ Object



14
15
16
# File 'lib/redmine/reporting/report.rb', line 14

def subject(s)
  @subject = s
end