Module: ActiveProject::Adapters::GithubProject::Comments

Included in:
ActiveProject::Adapters::GithubProjectAdapter
Defined in:
lib/active_project/adapters/github_project/comments.rb

Instance Method Summary collapse

Instance Method Details

#add_comment(item_id, body, ctx = {}) ⇒ Object Also known as: create_comment

Add a comment to the underlying Issue or PR of a ProjectV2Item. For draft items (no linked content) this raises NotImplementedError, because GitHub does not expose a comment thread for drafts.

Parameters:

  • item_id (String)

    ProjectV2Item node-ID

  • body (String)

    Markdown text

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

    MUST include :content_node_id for speed, otherwise we’ll query.

Raises:



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
# File 'lib/active_project/adapters/github_project/comments.rb', line 17

def add_comment(item_id, body, ctx = {})
  content_id =
    ctx[:content_node_id] ||
    begin
      q = "        query($id:ID!){\n          node(id:$id){\n            ... on ProjectV2Item{ content{ __typename ... on Issue{id} ... on PullRequest{id} } }\n          }\n        }\n      GQL\n      request_gql(query: q, variables: { id: item_id })\n        .dig(\"node\", \"content\", \"id\")\n    end\n\n  raise NotImplementedError, \"Draft cards cannot receive comments\" unless content_id\n\n  mutation = <<~GQL\n    mutation($subject:ID!, $body:String!){\n      addComment(input:{subjectId:$subject, body:$body}){ commentEdge{ node{ id body author{login}\n        createdAt updatedAt } } }\n    }\n  GQL\n  comment_node = request_gql(query: mutation,\n                             variables: { subject: content_id, body: body })\n                 .dig(\"addComment\", \"commentEdge\", \"node\")\n\n  map_comment(comment_node, item_id)\nend\n"

#delete_comment(comment_id) ⇒ Object



63
64
65
66
67
68
69
70
71
# File 'lib/active_project/adapters/github_project/comments.rb', line 63

def delete_comment(comment_id)
  mutation = "    mutation($id:ID!){\n      deleteIssueComment(input:{id:$id}){ clientMutationId }\n    }\n  GQL\n  request_gql(query: mutation, variables: { id: comment_id })\n  true\nend\n"

#update_comment(comment_id, body) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/active_project/adapters/github_project/comments.rb', line 48

def update_comment(comment_id, body)
  mutation = "    mutation($id:ID!, $body:String!){\n      updateIssueComment(input:{id:$id, body:$body}){\n        issueComment { id body updatedAt }\n      }\n    }\n  GQL\n  node = request_gql(query: mutation,\n                     variables: { id: comment_id, body: body })\n         .dig(\"updateIssueComment\", \"issueComment\")\n\n  map_comment(node, node[\"id\"])\nend\n"