Module: ActiveProject::Adapters::Jira::Comments

Included in:
ActiveProject::Adapters::JiraAdapter
Defined in:
lib/active_project/adapters/jira/comments.rb

Instance Method Summary collapse

Instance Method Details

#add_comment(issue_id_or_key, comment_body, _context = {}) ⇒ ActiveProject::Resources::Comment

Adds a comment to an issue in Jira using the V3 endpoint.

Parameters:

  • issue_id_or_key (String, Integer)

    The ID or key of the issue.

  • comment_body (String)

    The text of the comment.

  • context (Hash)

    Optional context (ignored).

Returns:



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/active_project/adapters/jira/comments.rb', line 12

def add_comment(issue_id_or_key, comment_body, _context = {})
  path = "/rest/api/3/issue/#{issue_id_or_key}/comment"

  payload = {
    body: {
      type: "doc", version: 1,
      content: [ { type: "paragraph", content: [ { type: "text", text: comment_body } ] } ]
    }
  }.to_json

  comment_data = make_request(:post, path, payload)
  map_comment_data(comment_data, issue_id_or_key)
end

#delete_comment(comment_id, context = {}) ⇒ Boolean

Deletes a comment from an issue in Jira.

Parameters:

  • comment_id (String, Integer)

    The ID of the comment to delete.

  • context (Hash) (defaults to: {})

    Required context: { issue_id: ‘…’ }.

Returns:

  • (Boolean)

    True if successfully deleted.



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/active_project/adapters/jira/comments.rb', line 55

def delete_comment(comment_id, context = {})
  issue_id_or_key = context[:issue_id]
  unless issue_id_or_key
    raise ArgumentError,
          "Missing required context: :issue_id must be provided for JiraAdapter#delete_comment"
  end

  path = "/rest/api/3/issue/#{issue_id_or_key}/comment/#{comment_id}"
  make_request(:delete, path)
  true
end

#update_comment(comment_id, body, context = {}) ⇒ ActiveProject::Resources::Comment

Updates a comment on an issue in Jira using the V3 endpoint.

Parameters:

  • comment_id (String, Integer)

    The ID of the comment.

  • body (String)

    The new comment text.

  • context (Hash) (defaults to: {})

    Required context: { issue_id: ‘…’ }.

Returns:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/active_project/adapters/jira/comments.rb', line 31

def update_comment(comment_id, body, context = {})
  issue_id_or_key = context[:issue_id]
  unless issue_id_or_key
    raise ArgumentError,
          "Missing required context: :issue_id must be provided for JiraAdapter#update_comment"
  end

  path = "/rest/api/3/issue/#{issue_id_or_key}/comment/#{comment_id}"

  payload = {
    body: {
      type: "doc", version: 1,
      content: [ { type: "paragraph", content: [ { type: "text", text: body } ] } ]
    }
  }.to_json

  comment_data = make_request(:put, path, payload)
  map_comment_data(comment_data, issue_id_or_key)
end