GitHub Action:查找评论

GitHub Action:查找评论

1. 项目介绍

find-comment 是一个GitHub Action,用于在GitHub的_issues_或_pull requests_中查找匹配特定条件的评论。该Action可以搜索包含特定字符串、由特定用户发布或符合正则表达式模式的评论,并输出评论的相关信息。

2. 项目快速启动

以下是一个快速启动find-comment的步骤:

首先,在你的GitHub仓库中创建一个新的.github/workflows目录(如果尚未存在)。

然后,创建一个新的YAML文件来定义你的工作流程,例如find-comment.yml

name: Find Comment Example

on: [issue_comment]

jobs:
  find-comment-job:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Find Comment
        uses: peter-evans/find-comment@v3
        with:
          issue-number: ${{ github.event.issue.number }}
          body-includes: '特定搜索字符串'
        id: fc

      - name: Output Comment Details
        run: |
          echo "Comment ID: ${{ steps.fc.outputs.comment-id }}"
          echo "Comment Node ID: ${{ steps.fc.outputs.comment-node-id }}"
          echo "Comment Body: ${{ steps.fc.outputs.comment-body }}"
          echo "Comment Author: ${{ steps.fc.outputs.comment-author }}"
          echo "Comment Created At: ${{ steps.fc.outputs.comment-created-at }}"

在上面的示例中,我们定义了一个工作流程,它在有新的评论添加到问题时触发。它使用find-comment Action来搜索包含特定字符串的评论,并输出找到的评论的详细信息。

3. 应用案例和最佳实践

查找第一个包含特定字符串的评论

- name: Find First Comment with String
  uses: peter-evans/find-comment@v3
  with:
    issue-number: 1
    body-includes: '特定搜索字符串'

查找第一个由特定作者发表的评论

- name: Find First Comment by Author
  uses: peter-evans/find-comment@v3
  with:
    issue-number: 1
    comment-author: '作者的用户名'

查找第一个符合正则表达式的评论

- name: Find First Comment with Regex
  uses: peter-evans/find-comment@v3
  with:
    issue-number: 1
    body-regex: '^.*特定搜索字符串.*$'

查找最后一个包含特定字符串的评论

- name: Find Last Comment with String
  uses: peter-evans/find-comment@v3
  with:
    issue-number: 1
    body-includes: '特定搜索字符串'
    direction: 'last'

查找第n个包含特定字符串的评论

- name: Find Nth Comment with String
  uses: peter-evans/find-comment@v3
  with:
    issue-number: 1
    body-includes: '特定搜索字符串'
    nth: 2  # 0索引,表示第3个匹配的评论

4. 典型生态项目

find-comment 可以与GitHub的其他Action一起使用,例如用于自动化工作流程的actions/checkout,用于通知的actions/github等。通过整合这些Action,可以创建一个强大的自动化生态系统,用于处理和组织GitHub仓库中的评论和问题。

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值