0

I have a step in a github workflow job that looks like this:

      - name: Create a workflow-started comment
        uses: actions/github-script@v3
        with:
          github-token: ${{secrets.GITHUB_TOKEN}}
          script: |
              // create new comment on PR and get back the comment's nodeId for updating later.
              const query = `mutation($pr_node_id:String!, $body:String!) {
                addComment(input: {subjectId:$pr_node_id, body:$body}) {
                  commentEdge{
                    node {
                      id
                    }
                  }
                }
              }`;
              const variables = {
                  pr_node_id:'${{steps.vars.outputs.pr-node-id}}',
                  body:'Workflow started!',
              }
              const result = await github.graphql(query, variables)
              console.log(result)

It can create a comment and output the result:

{ addComment: { subject: { id: 'MDExOlB1bGxSZXF...N0NTd3Nzg2NDM5' } } }

I need to get access to the id in the result. Is there a way to get it?

Konrad Kleine
  • 4,275
  • 3
  • 27
  • 35
  • https://docs.github.com/en/actions/learn-github-actions/essential-features-of-github-actions#sharing-data-between-jobs ? – xadm Jan 20 '21 at 00:31
  • @xadm this was only if I want to share data between jobs. It simply was too late for me to see the answer which was right in front of my eyes. – Konrad Kleine Jan 22 '21 at 13:45

1 Answers1

0

Well, console.log(result.addComment.commentEdge.node.id) does the trick.

Konrad Kleine
  • 4,275
  • 3
  • 27
  • 35