Giter Site home page Giter Site logo

auto_pr_comments_from_forks's Introduction

This is a demo showing how to work around GitHub Actions limitation of CI jobs not being able to post comments to the upstream repo's pull requests. The same approach could be used for other actions that require upstream security access. Use with care to avoid compromising your primary repo's security token.

Problem

Common scenario in the FOSS community:

  • You want community to fork your repo and submit pull requests
  • You want your CI job to post run results as a comment to the pull request
  • GitHub does not allow GitHub Actions running from a forked repo to modify parent repo, even to post comments on its own PR.

Workaround

  • 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.

Implementation and Testing

The code was written using a bash script with curl and jq, without any other libraries. It is already running on this repo, and has created this PR message. Feel free to test it further by forking this repository, creating a dummy change, and creating a pull request. The cron job performs these steps on each run:

  • 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)

Volunteers Needed

It would be great if the same algorithm could be implemented as a proper packaged action, rather than a curl+jq hack :)

auto_pr_comments_from_forks's People

Contributors

nyurik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

auto_pr_comments_from_forks's Issues

Private repos don't work - auth_crl should be used always

For private repos (which can have forks), curl requests will not work without a bearer token.

Runs will fail like this:

Error parsing pull requests
{
  "message": "Not Found",
  "documentation_url": "https://docs.github.com/rest/reference/pulls#list-pull-requests"
}
jq: error (at /dev/fd/63:4): Cannot index string with string "locked"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.