From 2cdf849712daadc9624879c6d02db3505e1383e8 Mon Sep 17 00:00:00 2001 From: Tan Ho <38083823+tanho63@users.noreply.github.com> Date: Tue, 19 Dec 2023 14:50:48 -0500 Subject: [PATCH] add PR commands + dictionary check --- .github/workflows/pr-commands.yaml | 131 +++++++++++++++++++++++++++ data-raw/build_teamplayer_mappings.R | 72 ++++++++------- data-raw/dictionary_check.R | 5 +- 3 files changed, 172 insertions(+), 36 deletions(-) create mode 100644 .github/workflows/pr-commands.yaml diff --git a/.github/workflows/pr-commands.yaml b/.github/workflows/pr-commands.yaml new file mode 100644 index 00000000..cc1081a2 --- /dev/null +++ b/.github/workflows/pr-commands.yaml @@ -0,0 +1,131 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + issue_comment: + types: [created] + +name: Commands + +jobs: + document: + if: ${{ github.event.issue.pull_request && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER') && startsWith(github.event.comment.body, '/document') }} + name: document + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v3 + + - uses: r-lib/actions/pr-fetch@v2 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::roxygen2 + needs: pr-document + + - name: Document + run: roxygen2::roxygenise() + shell: Rscript {0} + + - 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 commit -m 'Document' + + - uses: r-lib/actions/pr-push@v2 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + + style: + if: ${{ github.event.issue.pull_request && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER') && startsWith(github.event.comment.body, '/style') }} + name: style + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v3 + + - uses: r-lib/actions/pr-fetch@v2 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + + - uses: r-lib/actions/setup-r@v2 + + - name: Install dependencies + run: install.packages("styler") + shell: Rscript {0} + + - name: Style + run: styler::style_pkg() + shell: Rscript {0} + + - name: commit + run: | + git config --local user.name "$GITHUB_ACTOR" + git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" + git add \*.R + git commit -m 'Style' + + - uses: r-lib/actions/pr-push@v2 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + + rebuild-data-dictionary: + if: ${{ github.event.issue.pull_request && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER') && startsWith(github.event.comment.body, '/rebuild-dictionary') }} + name: rebuild-data-dictionary + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + NFLVERSE_GH_TOKEN: ${{ secrets.NFLVERSE_GH_TOKEN }} + steps: + - uses: actions/checkout@v3 + + - uses: r-lib/actions/pr-fetch@v2 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + + - uses: r-lib/actions/setup-r@v2 + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + cache-version: 1 + extra-packages: | + any::usethis + any::dplyr + any::data.table + any::tidyr + any::stringr + any::tibble + any::here + any::skimr + any::waldo + + - name: Rebuild Dictionaries + run: | + Rscript data-raw/build_data_dictionaries.R + Rscript data-raw/build_teamplayer_mappings.R + shell: bash + + - name: Check Dictionaries + run: | + Rscript data-raw/dictionary_check.R + shell: bash + + - name: Commit + run: | + git config --local user.name "$GITHUB_ACTOR" + git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" + git add data + git commit -m 'rebuild dictionaries' + + - uses: r-lib/actions/pr-push@v2 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/data-raw/build_teamplayer_mappings.R b/data-raw/build_teamplayer_mappings.R index 7a5ae8f7..dbb7bfe5 100644 --- a/data-raw/build_teamplayer_mappings.R +++ b/data-raw/build_teamplayer_mappings.R @@ -1,5 +1,6 @@ library(nflreadr) -library(tidyverse) +library(dplyr) +library(tidyr) library(usethis) player_name_mapping <- read.csv("data-raw/clean_player_names.csv") |> @@ -11,40 +12,41 @@ player_name_mapping <- read.csv("data-raw/clean_player_names.csv") |> usethis::use_data(player_name_mapping, overwrite = TRUE) teams <- csv_from_url("https://github.com/nflverse/nfldata/raw/master/data/teams.csv") %>% - select(team,nfl,espn,pfr,pfflabel,fo) %>% - pivot_longer(-team,names_to = NULL, values_to = "alternate") %>% - distinct() %>% - filter(alternate!="") %>% - bind_rows( - tribble(~team,~alternate, - "GB","GBP", - "KC","KCC", - "LV","LVR", - "NE","NEP", - "NO","NOS", - "LAC","SDC", - "TB","TBB", - "WAS","WFT", - "LV","OAK", - "LA","STL", - "LA","SL", - "STL","SL", - "LAC","SD", - "SD","SDC", - "AFC", "AFC", - "NFC", "NFC", - "NFL", "NFL" - ) + dplyr::select(team,nfl, espn, pfr, pfflabel, fo) %>% + dplyr::pivot_longer(-team, names_to = NULL, values_to = "alternate") %>% + dplyr::distinct() %>% + dplyr::filter(alternate!="") %>% + dplyr::bind_rows( + tibble::tribble( + ~team,~alternate, + "GB","GBP", + "KC","KCC", + "LV","LVR", + "NE","NEP", + "NO","NOS", + "LAC","SDC", + "TB","TBB", + "WAS","WFT", + "LV","OAK", + "LA","STL", + "LA","SL", + "STL","SL", + "LAC","SD", + "SD","SDC", + "AFC", "AFC", + "NFC", "NFC", + "NFL", "NFL" + ) ) %>% - arrange(alternate) + dplyr::arrange(alternate) team_abbr_mapping <- teams %>% - filter(!team %in% c("OAK","STL","SD")) %>% - select(alternate,team) %>% - deframe() + dplyr::filter(!team %in% c("OAK","STL","SD")) %>% + dplyr::select(alternate,team) %>% + tibble::deframe() team_abbr_mapping_norelocate <- teams %>% - filter( + dplyr::filter( !(team == "LV" & alternate %in% c("OAK")), !(team == "LAC" & alternate %in% c("SD","SDG","SDC")), !(team == "LA" & alternate %in% c("STL","SL")), @@ -53,10 +55,10 @@ team_abbr_mapping_norelocate <- teams %>% !(team == "OAK" & alternate %in% c("LV","LVR","RAI")), !(team == "SD" & alternate %in% c("LAC","LACH")) ) %>% - arrange(alternate) %>% - select(alternate,team) %>% - deframe() + dplyr::arrange(alternate) %>% + dplyr::select(alternate,team) %>% + tibble::deframe() -use_data(team_abbr_mapping, overwrite = TRUE) -use_data(team_abbr_mapping_norelocate, overwrite = TRUE) +usethis::use_data(team_abbr_mapping, overwrite = TRUE) +usethis::use_data(team_abbr_mapping_norelocate, overwrite = TRUE) diff --git a/data-raw/dictionary_check.R b/data-raw/dictionary_check.R index 0ecdbc79..72c7b26f 100644 --- a/data-raw/dictionary_check.R +++ b/data-raw/dictionary_check.R @@ -1,6 +1,9 @@ # data dictionary checking devtools::load_all() -library(tidyverse) +library(dplyr) +library(skimr) +library(waldo) +library(data.table) dict_check <- function(df,dict){ actual_vars <- df |>