R-ecology-lesson
R-ecology-lesson copied to clipboard
See if styler could be used to automatically format content (and PRs)
https://github.com/r-lib/styler
it would reduce nitpicking on contributions while maintaining consistent formatting across the lesson
Also, implementing this would support git-novice/09-conflict
's advice to "use code style tools".
I believe there is now a github action template for auto-styling pull requests: https://github.com/r-lib/actions/tree/master/examples#commands-workflow
It can be added to the repository with usethis::use_github_action_pr_commands(open = TRUE)
I've modified the workflow from the example a bit. I believe, we need something like this -- it automatically styles the .Rmd and .R files for each new PR. At least, that's what I think it does. I haven't tested it...
# github/workflows/format-r-code.yml
name: format-r-code
on: [pull_request]
jobs:
style:
runs-on: macOS-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2
- uses: r-lib/actions/pr-fetch@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: r-lib/actions/setup-r@v1
- name: Install dependencies
run: Rscript -e 'install.packages("styler")'
- name: Style
run: Rscript -e 'styler::style_dir(filetype = c("R", "Rmd"))'
- name: commit
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Actions"
git add \*.R
git add \*.Rmd
git commit -m 'Style'
- uses: r-lib/actions/pr-push@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}