【问题标题】:How to access GraphQL mutation result in Github Workflow如何在 Github Workflow 中访问 GraphQL 变异结果
【发布时间】:2021-04-24 07:33:09
【问题描述】:

我在 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。有没有办法得到它?

【问题讨论】:

标签: graphql workflow github-script github-actions


【解决方案1】:

好吧,console.log(result.addComment.commentEdge.node.id) 成功了。

【讨论】:

    猜你喜欢
    • 2019-06-11
    • 2016-08-28
    • 2020-06-30
    • 2017-06-20
    • 2017-06-20
    • 2020-05-24
    • 2016-11-22
    • 2020-06-01
    • 2021-03-10
    相关资源
    最近更新 更多