readthedocs / actions

GitHub Actions for Read the Docs
MIT License
33 stars 10 forks source link

Add comment only if there are changes under certain directory #3

Closed humitos closed 1 year ago

humitos commented 2 years ago

It would be good to detect changes under certain directories (e.g. docs/) and only update the description in that situation. Example of a potential input for the action:

file-path:
  description: "Path where to check for file modifications"
  default: "docs/"
  required: false

Note we could use github.rest.pulls.listFiles to get the files changed in the PR:

const {data: pull_files } = await github.rest.pulls.listFiles({
    owner: context.repo.owner,
    repo: context.repo.repo,
    pull_number: context.issue.number,
});

for (let file of pull_files) {
    // do something here
}
humitos commented 1 year ago

This can be done with a GHA option in a simpler way instead:

on:
  pull_request_target:
    types:
      - opened
    paths:
      - "docs/**"   # <-- this line

We are using this on Read the Docs at https://github.com/readthedocs/readthedocs.org/blob/main/.github/workflows/pr-preview-links.yaml#L6-L7 and it's working fine.