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 = <<~GQL
        query($id:ID!){
          node(id:$id){
            ... on ProjectV2Item{ content{ __typename ... on Issue{id} ... on PullRequest{id} } }
          }
        }
      GQL
      request_gql(query: q, variables: { id: item_id })
        .dig("node", "content", "id")
    end

  raise NotImplementedError, "Draft cards cannot receive comments" unless content_id

  mutation = <<~GQL
    mutation($subject:ID!, $body:String!){
      addComment(input:{subjectId:$subject, body:$body}){ commentEdge{ node{ id body author{login}
        createdAt updatedAt } } }
    }
  GQL
  comment_node = request_gql(query: mutation,
                             variables: { subject: content_id, body: body })
                 .dig("addComment", "commentEdge", "node")

  map_comment(comment_node, item_id)
end

#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 = <<~GQL
    mutation($id:ID!){
      deleteIssueComment(input:{id:$id}){ clientMutationId }
    }
  GQL
  request_gql(query: mutation, variables: { id: comment_id })
  true
end

#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 = <<~GQL
    mutation($id:ID!, $body:String!){
      updateIssueComment(input:{id:$id, body:$body}){
        issueComment { id body updatedAt }
      }
    }
  GQL
  node = request_gql(query: mutation,
                     variables: { id: comment_id, body: body })
         .dig("updateIssueComment", "issueComment")

  map_comment(node, node["id"])
end