# Workflow derived from https://github.com/r-lib/actions/tree/master/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
  issue_comment:
    types: [created]


name: PR-commands

jobs:
  document-style-pr-commands  :
    if: startsWith(github.event.comment.body, '/document-style')
    name: document-style-pr-commands
    runs-on: ubuntu-latest
    env:
      GITHUB_PAT: ${{ secrets.PAT_GITHUB }}
    steps:
      - uses: actions/checkout@v2

      - uses: r-lib/actions/pr-fetch@v2
        with:
          repo-token: ${{ secrets.PAT_GITHUB }}

      - name: Set up R
        uses: r-lib/actions/setup-r@v2
        with:
          use-public-rspm: true

      - name: Set up Dependencies
        uses: r-lib/actions/setup-r-dependencies@v2
        with:
          extra-packages: |
            any::roxygen2
            any::styler

      - name: Document
        run: Rscript -e 'roxygen2::roxygenise()'

      - name: Style
        run: Rscript -e 'styler::style_pkg()'

      - name: commit
        run: |
          git config --local user.name "$GITHUB_ACTOR"
          git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com"
          git add man/\* NAMESPACE
          git add \*.R
          git commit -m 'Document and style'
      - uses: r-lib/actions/pr-push@v1
        with:
          repo-token: ${{ secrets.PAT_GITHUB }}
