如何使用github操作在commit上创建注释?

时间:2019-10-19 22:22:11

标签: 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)

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

enter image description here

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

1 个答案:

答案 0 :(得分:3)

更新:我编写了一个简化创建提交注释的操作。我将下面的原始解决方案留作参考。

有关完整的用法详细信息,请参见commit-comment

      - name: Create commit comment
        uses: peter-evans/commit-comment@v1.0.1
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          body: |
            This is a multi-line test comment
            - With GitHub **Markdown**
            - Created by [commit-comment][1]

            [1]: https://github.com/peter-evans/commit-comment

commit-comment action example

原始解决方案:以下工作流程应该是一个很好的起点。您可以在此处找到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"

它将像这样对提交创建注释。 commit comment example