Nithador/CORE-RI
0
1 2github_client <- httr2::oauth_client(3 id = "Iv23liHRRpBY2Y4snPkZ",4 token_url = "https://github.com/login/oauth/access_token",5 secret = httr2::obfuscated("z8xK2AQ6IBqwGUqJ5h4bxOXrGton7iXq6FHXq2zGgIXvRuRbUOobVNilVKtKvXXoyTYnCcB5WR4")6)7 8git_token <- httr2::oauth_flow_auth_code(9 client = github_client,10 auth_url = "https://github.com/login/oauth/authorize",11 redirect_uri = "http://localhost"12)13 14gh::gh(15 "https://api.github.com/repos/{owner}/{repos}/issues",16 # .method = "POST",17 # .token = git_token,18 owner = "Nithador",19 repos = "api_test"20 # .send_header = list(Accept = "application/vnd.github+json"),21 # list(title = "Testing API",22 # body = "I am testing API issue creation.")23)24 25gh::gh(26 "https://api.github.com/repos/{owner}/{repos}/issues",27 .method = "POST",28 .token = git_token$access_token,29 owner = "Nithador",30 repos = "api_test",31 .send_header = list(Accept = "application/vnd.github+json",32 "Content-Type" = "application/json"),33 title = "Testing API",34 body = "I am testing API issue creation."35)36 37 38 39resp <- httr2::request("https://api.github.com/repos/Nithador/api_test/issues") |>40 httr2::req_auth_bearer_token(git_token$access_token) |>41 httr2::req_headers(Accept = "application/vnd.github+json",42 `X-GitHub-Api-Version` = "2022-11-28") |>43 # httr2::req_dry_run()44 httr2::req_perform()45resp |> httr2::resp_body_json()46 47resp2 <- httr2::request("https://api.github.com/repos/Nithador/api_test/issues") |>48 httr2::req_auth_bearer_token(git_token$access_token) |>49 httr2::req_headers(Accept = "application/vnd.github+json",50 `X-GitHub-Api-Version` = "2022-11-28") |>51 httr2::req_body_json(52 list(title = "New issue from API")53 ) |>54 # httr2::req_dry_run()55 httr2::req_perform()56resp2 |> httr2::resp_body_json()57 58 59 60 61# Comments processing ----62library("gh")63library("stringr")64 65# Setup ========================================================================66BaseName <- "BioDT-RI-Interface-Template" # this is where the GitHub UserName for the Organisation that represents an RI Node goes67 68 69comments <- gh("GET /repos/{username}/{reponame}/issues/comments", username = BaseName, reponame = "CORE-Helpdesk", 70 state = "all" # can also be "open" or "closed"71)72 73comments_ind <- purrr::map_int(comments, function(x){74 temp <- stringr::str_split(x$issue_url, "/")[[1]]75 return(temp[length(temp)] |> as.integer())}76 )77 78comments_divs <- purrr::map_chr(my_events, function(x){paste0('<div class="comment">', x$user$login, ' </br> <p>', x$body, '</p></div>')}) #|> stringr::str_c(collapse = " ")79 80comments_list <- list()81 82for (i in seq_along(comments_ind)) {83 ind <- comments_ind[i]84 # || if first is true second is not tested so it does not failed85 if (length(comments_list) < ind || is.null(comments_list[[ind]])) {86 comments_list[[ind]] <- comments_divs[i]87 } else {88 comments_list[[ind]] <- paste(comments_list[[ind]], comments_divs[i])89 }90}91 92 93my_events <- gh("POST /repos/{username}/{reponame}/issues/1/comments",94 .token = git_token$access_token,95 username = BaseName,96 reponame = "CORE-Helpdesk",97 body = "testing API comment"98)99 100 101 102a <- summarise_issues(RIAcc = "BioDT-RI-Interface-Template",103 Repo = "Helpdesk")104 