如何使用 github 操作创建对提交的评论?

Meh*_*iee 9 github github-api github-actions

我在此配置中使用 github 操作

name: Node CI

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v1
      - name: install node
        uses: actions/setup-node@v1
        with:
          node-version: 12.x
      - name: npm install
        run: npm install
      - name: npm build
        run: npm run build --if-present
      - name: npm test
        run: npm test
      - name: make storybook
        run: npm run build-storybook
      - uses: dswistowski/surge-sh-action@v1
        with:
          domain: 'https://react-strix-$(git rev-parse --short HEAD).surge.sh'
          project: '.out'
          login: straxico@gmail.com
          token: ${{ secrets.SURGE_PASSWORD }}
      - name: deploy image
        run: |
          docker login docker.pkg.github.com --username straxico --password ${{ secrets.DOCKER_PASSWORD }}
          docker build . --file Dockerfile --tag docker.pkg.github.com/straxico/react-strix/master:$(git describe --tags)
          docker push docker.pkg.github.com/straxico/react-strix/master:$(git describe --tags)
Run Code Online (Sandbox Code Playgroud)

我想在最新推送的提交上自动创建评论,包括我的故事书和 docker URL。就像“现在”机器人

在此处输入图片说明

如何使用 github 操作对提交发表评论?

pet*_*ans 13

更新:我写了一个动作来简化创建提交注释。我将在下面留下原始解决方案以供参考。

有关完整的使用详细信息,请参阅提交评论

      - name: Create commit comment
        uses: peter-evans/commit-comment@v1
        with:
          body: |
            This is a multi-line test comment
            - With GitHub **Markdown**
            - Created by [commit-comment][1]

            [1]: https://github.com/peter-evans/commit-comment
Run Code Online (Sandbox Code Playgroud)

提交评论操作示例

原始解决方案:以下工作流程应该是一个很好的起点。您可以在此处找到 API 的完整文档:https : //developer.github.com/v3/repos/comments/#create-a-commit-comment

name: commit comment
on: push
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - name: Add commit comment
        run: |
          jq -nc '{"body": "test comment"}' | \
          curl -sL  -X POST -d @- \
            -H "Content-Type: application/json" \
            -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
            "https://api.github.com/repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA/comments"
Run Code Online (Sandbox Code Playgroud)

它将像这样在提交上创建评论。 提交评论示例