Skip to content

Automatic comment when PR is made to sc_bilara_data #372

@agilgur5

Description

@agilgur5

Summary

Automatically leave a bot comment (and close?) any PRs to the sc_bilara_data directory

Motivation

  1. The sc_bilara_data directory is synchronized with the bilara-data repo and so PRs should never be made here

  2. Typos or translation issues in the Bilara texts should be reported on the forum in the Feedback category, particularly in the pinned thread on typos.

    1. Generally speaking, the respective translator will review and make changes via the Bilara app instead of directly on GitHub.
    2. See Update mn127_translation-en-sujato.json #363 (comment), Fix typo in sn44.2:17.7 EN Sujato: "bu" -> "by" bilara-data#4739 (comment) et al for the general rationale of keeping these all in one place on the forum
  3. There have been several PRs made to this repo and bilara-data to fix typos or other mistakes, including from myself.1

    1. Currently, those contributors then have to be manually redirected by someone to the forum thread. This means that someone (usually a volunteer) has to notice their issue and comment on it, during which a delay might occur, etc which is not necessarily the most optimal contributor experience (especially if a PR is just left around for months).

To more quickly and efficiently redirect people in a more standardized way, a bot can automatically leave a comment on such PRs and possibly auto-close them too(?).
Credit to @benmneb for the idea in #363 (comment)

Implementation Details

This should be fairly straightforward to implement with GitHub Actions and would be in an isolated YAML file, so it may be suitable for a beginner or new contributor.

Some examples for reference: https://docs.github.com/en/actions/how-tos/write-workflows/choose-what-workflows-do/use-github-cli, https://github.com/orgs/community/discussions/69944, https://stackoverflow.com/a/64126737/3431180, https://stackoverflow.com/a/69450384/3431180

  1. Create a new GitHub Actions (GHA) workflow YAML file, for instance bilara-pr-comment.yaml

    1. Place it in the .github/workflows/ directory. Create the directories if necessary (mkdir -p .github/workflows/)
  2. See OpenSSF Scorecard for GHA supply chain security practices, particularly Token-Permissions and Pinned-Dependencies.2

  3. Add a PR event trigger for the workflow. For example:

    name: Comment on Bilara data PRs
    
    permissions:
      contents: read # read-only by default, only add permissions per job (c.f. https://github.com/ossf/scorecard/blob/6197ba36762d21cdd09172a811953114722bfd52/docs/checks.md#token-permissions)
    
    on:
      pull_request:
        paths:
          - 'sc_bilara_data/*' # only trigger on PRs to synced Bilara data directory
  4. Create a singular job that will make the comment (and close?). For example:

    jobs:
      comment:
  5. Add the appropriate permissions for commenting (and closing?). For example:

      comment:
        permissions:
          pull-requests: write # allow commenting on PRs
  6. Skip certain users like sc-translatatron (and maybe others? like ccronje and sabbamitta who sometimes make PRs?)

      comment:
        # [...]
        if: github.actor != 'sc-translatatron' # skip bot PRs
  7. Add a step to leave a specific comment

    1. There's several ways of doing this. If you use an action, remember to pin it to a specific SHA as per above
  8. Add a step to close the PR(?)

  9. A very similar (but slightly different) workflow should be implemented for the bilara-data repo as well.

Testing / Verification

Testing locally can be difficult with GitHub Actions -- there's act, but it doesn't handle everything.

I usually test this kind of GHA workflow on my personal fork first. In this case:

  1. Push the code to main on my fork, then write a test PR to sc_bilara_data on my own fork and see if the comment is correctly made (and closed?).
  2. Then reset main on my fork (remove the commit and force push) and create a PR to the root repository from a feature branch as usual, leaving a link to my test PR on my fork as testing evidence3

  1. As examples, see Fix typo in sn44.2:17.7 EN Sujato: "bu" -> "by" bilara-data#4739, Fix typo in mn122 comment-en-sujato bilara-data#4618, Fix typo in mn102_translation-en-sujato.json bilara-data#4546, Update mn127_translation-en-sujato.json #363, Fix typo in view description in mn114_comment-en-sujato.json #357, Fix whitespace typo #351, Update mn85_translation-en-sujato.json #343, etc

  2. As examples, can see my prior work in Improve OpenSSF Scorecard checks argoproj/argo-workflows#12031, ci: ensure least privilege permissions for GHA tokens argoproj/argo-workflows#12035, ci: pin all GH Actions argoproj/argo-workflows#12619

  3. Here's one example of that, although it's not for automated commenting: ci: only run jobs when relevant files have been changed [actions testing PR] agilgur5/argo-workflows#1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions