forked from ansible-community/stats-collections
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add nicer table, survival curve, and move mongo functions to their ow…
…n file
- Loading branch information
1 parent
9fd8ab9
commit ebb55d9
Showing
7 changed files
with
503 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
|
||
#' @importFrom mongolite mongo | ||
#' @noRd | ||
setup_mongo <- function(collection) { | ||
mongo(collection, url = mongo_string()) | ||
} | ||
|
||
#' @keywords internal | ||
#' @export | ||
#' @importFrom glue glue | ||
#' @noRd | ||
mongo_string <- function() { | ||
DBUSER <- Sys.getenv('DBUSER') | ||
DBPASS <- Sys.getenv('DBPASS') | ||
DBPORT <- Sys.getenv('DBPORT') | ||
DBNAME <- Sys.getenv('DBNAME') | ||
|
||
glue("mongodb://{DBUSER}:{DBPASS}@172.17.0.1:{DBPORT}/{DBNAME}") | ||
} | ||
|
||
#' Takes a repo name and gets the relevant dataframes from Mongo | ||
#' @importFrom glue glue | ||
#' @importFrom dplyr bind_rows | ||
#' @noRd | ||
get_repo_data <- function(repo) { | ||
query <- glue('{{"repository.nameWithOwner":"{repo}"}}') | ||
base_fields <- '{ | ||
"number":true, | ||
"author":true, | ||
"title":true, | ||
"state":true, | ||
"createdAt":true, | ||
"closedAt":true, | ||
"labels":true, | ||
"repository":true | ||
}' | ||
|
||
db_issues <- setup_mongo('issues') | ||
issues <- db_issues$find(query, base_fields) %>% | ||
mutate(type = 'issue') | ||
db_issues$disconnect() ; rm(db_issues) | ||
|
||
# Add extra fields for PRs | ||
new_fields <- jsonlite::parse_json(base_fields) | ||
new_fields$mergedAt <- TRUE | ||
new_fields$merged <- TRUE | ||
new_fields$baseRefName <- TRUE | ||
new_fields <- jsonlite::toJSON(new_fields, auto_unbox = T) | ||
|
||
db_pulls <- setup_mongo('pulls') | ||
pulls <- db_pulls$find(query, new_fields) %>% | ||
mutate(type = 'pull') | ||
db_pulls$disconnect() ; rm(db_pulls) | ||
|
||
bind_rows(issues, pulls) | ||
} | ||
|
||
get_repos <- function() { | ||
# later, use mapreduce | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.