从分叉存储库发布GitHub操作的注释的解决方法 [英] Workaround to post comments from GitHub actions from forked repos

查看:64
本文介绍了从分叉存储库发布GitHub操作的注释的解决方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在GitHub动作完成后向GitHub提取请求中发布评论,例如FOSS社区成员提交PR时.我知道,当操作从派生的仓库中执行时,令牌没有对父仓库的写权限,因此它无法发布评论.

I need to post comments to GitHub pull request after GitHub action completes, e.g. when a FOSS community member submits a PR. I know that when an action runs from a forked repo, the token has no write access to the parent repo, so it cannot post a comment.

人们为此找到了可行的解决方法吗?

Are there any viable workarounds that people have found for this?

推荐答案

我找不到任何现成的动作,所以这是一个

I couldn't find any ready-made actions, so here's a complete code to work around GitHub Actions' limitation, written in bash + jq + curl, and calling GitHub API directly.

  • 拉动请求操作创建一个具有Github markdown注释内容的.md文件,并将其另存为人工文件.此操作在分叉的仓库中运行,因此无法发布PR评论.
  • 常规定时作业查看所有未完成的请求请求和最近完成的操作运行,查找发布的工件,并将其内容作为注释复制到相应的请求请求中,从而在重复运行时更新现有注释.
  • Pull request action creates an .md file with Github markdown comment content, and saves it as an artifact under some name. This action runs in the context of the forked repo, so it has no way to post a PR comment.
  • A regular cron job looks at all the open pull requests and recently completed action runs, looks for the posted artifacts, and copies their content as comments to the corresponding pull requests, updating existing comment on repeated runs.

cron对工作的深入步骤是:

The cron's job in-depth steps are:

  • 获取所有打开的拉取请求
  • 获取所有最近运行的工作流
  • 将拉取请求及其当前SHA与为同一SHA运行的上一个工作流程进行匹配
  • 对于每个找到的<pull-request-number><workflow-run-id>匹配项,
  • :
    • 从工作流程运行中下载工件-希望包含降价内容的单个文件
    • 浏览现有的PR评论,看看我们之前是否发表过评论 (使用隐藏的魔术头来标识我们的评论)
    • 创建或更新带有新文本的评论(如果已更改)
    • get all open pull requests
    • get all recent workflow runs
    • match pull requests and their current SHA with the last workflow run for the same SHA
    • for each found match of <pull-request-number> and <workflow-run-id> :
      • download artifact from the workflow run -- expects a single file with markdown content
      • look through existing PR comments to see if we have posted a comment before (uses a hidden magical header to identify our comment)
      • either create or update the comment with the new text (if changed)

      这篇关于从分叉存储库发布GitHub操作的注释的解决方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆