如何在 Github 工作流中访问 GraphQL 变异结果

How to access GraphQL mutation result in Github Workflow

我在 github 工作流作业中有一个步骤,如下所示:

      - 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)

可以创建评论并输出结果:

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

我需要访问结果中的 ID。有办法得到吗?

嗯,console.log(result.addComment.commentEdge.node.id) 就可以了。