Skip to content

Commit

Permalink
Merge pull request #52 from fhdsl/cansavvy/dummy-data
Browse files Browse the repository at this point in the history
Creating dummy data and better classifying the data types returned by metricminer
  • Loading branch information
cansavvy authored Jan 17, 2024
2 parents bc3a4dd + 586d717 commit 6813c6c
Show file tree
Hide file tree
Showing 58 changed files with 969 additions and 185 deletions.
3 changes: 2 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
^docs$
^pkgdown$
^inst/extdata/cached-secrets/*
.Rprofile
.Rprofile
resources/*
50 changes: 50 additions & 0 deletions .github/workflows/write-data.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
on:
schedule:
# - cron: '*/2 * * * *'

jobs:
write-data:
runs-on: ubuntu-latest
steps:
- name: Set up R
uses: r-lib/actions/setup-r@v2

- name: Install googlesheets4
uses: r-lib/actions/setup-r-dependencies@v2
with:
packages: |
any::googlesheets4
- name: Install remotes
run: |
Rscript -e "install.packages('remotes')"
- name: Install metricminer from Github
run: |
Rscript -e "remotes::install_github("fhdsl/metricminer")"
- name: Check out repository
uses: actions/checkout@v3

- name: Authorize metricminer
env:
METRICMINER_CALENDLY: ${{ secrets.METRICMINER_CALENDLY }}
METRICMINER_GITHUB_PAT: ${{ secrets.METRICMINER_GITHUB_PAT }}
METRICMINER_GOOGLE_ACCESS: ${{ secrets.METRICMINER_GOOGLE_ACCESS }}
METRICMINER_GOOGLE_REFRESH: ${{ secrets.METRICMINER_GOOGLE_REFRESH }}
run: |
# Authorize Calendly
auth_from_secret("calendly", token = Sys.getenv("METRICMINER_CALENDLY"))
# Authorize GitHub
auth_from_secret("github", token = Sys.getenv("METRICMINER_GITHUB_PAT"))
# Authorize Google
auth_from_secret("google",
refresh_token = Sys.getenv("METRICMINER_GOOGLE_REFRESH"),
access_token = Sys.getenv("METRICMINER_GOOGLE_ACCESS"),
cache = TRUE
)
- name: Write data
run: # Rscript -e 'source("R/write-data.R")'
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ inst/extdata/cached-secrets/*
testthat-problems.rds
.Renviron
inst/doc
local_auth.R
local_auth_2.R
15 changes: 11 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
# Generated by roxygen2: do not edit by hand

export(all_ga_metrics)
export(auth_from_secret)
export(authorize)
export(calendly_get)
export(clean_metric_data)
export(clean_ga_metrics)
export(clean_repo_metrics)
export(delete_creds)
export(example_data_folder)
export(get_all_ga_metrics)
export(get_calendly_user)
export(get_example_data)
export(get_ga_metadata)
export(get_ga_properties)
export(get_ga_stats)
export(get_ga_user)
export(get_github)
export(get_github_metrics)
export(get_github_user)
export(get_repo_list)
export(get_org_repo_list)
export(get_repos_metrics)
export(get_slido_files)
export(get_youtube_stats)
export(get_user_repo_list)
export(get_youtube_channel_stats)
export(get_youtube_video_stats)
export(gh_repo_wrapper)
export(list_calendly_events)
export(list_example_data)
export(request_ga)
export(request_google_forms)
export(write_to_gsheet)
export(write_to_table)
import(dplyr)
importFrom(assertthat,assert_that)
importFrom(assertthat,is.string)
Expand Down
1 change: 1 addition & 0 deletions R/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.httr-oauth
4 changes: 2 additions & 2 deletions R/auth.R
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ delete_creds <- function(app_name = "all") {
#' token <- authorize("google")
#' auth_from_secret(
#' app_name = "google",
#' refresh_token = token$credentials$access_token,
#' access_token = token$credentials$refresh_token
#' access_token = token$credentials$access_token,
#' refresh_token = token$credentials$refresh_token
#' )
#' }
#'
Expand Down
1 change: 1 addition & 0 deletions R/calendly.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ calendly_get <- function(url, token = NULL, user = NULL, count = NULL, page_toke
#'
#' authorize("calendly")
#' get_calendly_user()
#'
#' }
get_calendly_user <- function(token = NULL) {
if (is.null(token)) {
Expand Down
19 changes: 0 additions & 19 deletions R/export.R

This file was deleted.

40 changes: 37 additions & 3 deletions R/github.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ get_github <- function(token = NULL, url) {
# Process and return results
result_content <- httr::content(result, "text")
result_list <- jsonlite::fromJSON(result_content)

return(result_list)
}

Expand All @@ -53,12 +54,12 @@ get_github_user <- function(token = NULL) {
)
}

#' Retrieve list of repositories for an owner
#' Retrieve list of repositories for an organization
#' @description This is a function to get the information about a repository
#' @param token You can provide the Personal Access Token key directly or this function will attempt to grab a PAT that was stored using the `authorize("github")` function
#' @param owner The owner of the repository. So for `https://github.com/fhdsl/metricminer`, it would be `fhdsl`
#' @param count The number of responses that should be returned. Default is 20 or you can say "all" to retrieve all.
#' @return Information regarding a github account
#' @return a list of repos that an organization has
#' @importFrom gh gh
#' @export
#' @examples \dontrun{
Expand All @@ -67,7 +68,7 @@ get_github_user <- function(token = NULL) {
#' get_repo_list(owner = "fhdsl")
#' }
#'
get_repo_list <- function(owner, count = "all", token = NULL) {
get_org_repo_list <- function(owner, count = "all", token = NULL) {
if (count == "all") count <- "Inf"

if (is.null(token)) {
Expand All @@ -85,6 +86,38 @@ get_repo_list <- function(owner, count = "all", token = NULL) {
return(repo_list)
}

#' Retrieve list of repositories for an organization
#' @description This is a function to get the information about a repository
#' @param token You can provide the Personal Access Token key directly or this function will attempt to grab a PAT that was stored using the `authorize("github")` function
#' @param owner The owner of the repository. So for `https://github.com/fhdsl/metricminer`, it would be `fhdsl`
#' @param count The number of responses that should be returned. Default is 20 or you can say "all" to retrieve all.
#' @return a list of repos that an organization has
#' @importFrom gh gh
#' @export
#' @examples \dontrun{
#'
#' authorize("github")
#' get_user_list(owner = "metricminer")
#' }
#'
get_user_repo_list <- function(owner, count = "all", token = NULL) {
if (count == "all") count <- "Inf"

if (is.null(token)) {
# Get auth token
token <- get_token(app_name = "github", try = TRUE)
if (is.null(token)) warning("No token found. Only public repositories will be retrieved.")
}

repo_list <- gh::gh("GET /users/{owner}/repos",
owner = owner,
.token = token,
.limit = count
)

return(repo_list)
}

#' Get the repository metrics
#' @description This is a function to get the information about a repository
#' @param token You can provide the Personal Access Token key directly or this function will attempt to grab a PAT that was stored using the `authorize("github")` function
Expand Down Expand Up @@ -134,6 +167,7 @@ get_github_metrics <- function(repo, token = NULL, count = "all", data_format =

names(results) <- names(api_calls)


if (data_format == "dataframe") {
results <- clean_repo_metrics(
repo_name = paste0(c(owner, repo), collapse = "/"),
Expand Down
Loading

0 comments on commit 6813c6c

Please sign in to comment.