Skip to content

Commit

Permalink
i #275 Fixes authentication requests
Browse files Browse the repository at this point in the history
Authentications requests did not work on Kaiaulu
JIRA. This commit fixes the authentication issue.

Data can be downloaded both with and without
authentication (tested on geronimo w/o and on
kaiaulu with).

In addition, httr verbose was incorporated, which
helps with troubleshooting. The agent now also
is specified, pointing to Kaiaulu repo.

Signed-off-by: Carlos Paradis <carlosviansi@gmail.com>
  • Loading branch information
carlosparadis committed Apr 15, 2024
1 parent 9161bae commit 09a9622
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 33 deletions.
39 changes: 32 additions & 7 deletions R/jira.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ download_jira_issues <- function(domain,
} # Resume downloading

# Construct the API endpoint URL
url <- paste0(domain, "/rest/api/2/search")
#url <- paste0(domain, "/rest/api/2/search")
url <- httr::parse_url(domain)

#Authenticate if username and password are provided
if(!is.null(username)&&!is.null(password)) {
Expand All @@ -104,14 +105,38 @@ download_jira_issues <- function(domain,
auth <- NULL
}

url<-httr::modify_url(url = url,
scheme = if(is.null(url$scheme)){"https"},
path = c(url$path,"/rest/api/2/search"),
query=list(jql = jql_query,
fields = paste(fields, collapse = ","),
startAt = start_at,
maxResults = max_results))

url <- httr::parse_url(url)
url_built <- httr::build_url(url)

# Prepare query parameters for the API call
query_params <- list(jql = jql_query, fields = paste(fields, collapse = ","), maxResults = max_results, startAt = start_at)
#query_params <- list(jql = jql_query, fields = paste(fields, collapse = ","), maxResults = max_results, startAt = start_at)

if (verbose && (download_count == 0)){
message("Query parameters: ", query_params)
}
# if (verbose && (download_count == 0)){
# message("Query parameters: ", query_params)
# }
# Make the API call
response <- httr::GET(url, query = query_params)
if(!is.null(username)&&!is.null(password)){
response <- httr::GET(url_built,
if(verbose){httr::verbose()},
auth,
httr::user_agent("github.com/sailuh/kaiaulu"))
}else{
response <- httr::GET(url_built,
if(verbose){httr::verbose()},
httr::user_agent("github.com/sailuh/kaiaulu"))
}

if(verbose){
message("Requested: ", response$request$url)
}

# Stop if there's an HTTP error
if (httr::http_error(response)) {
Expand Down Expand Up @@ -145,7 +170,7 @@ download_jira_issues <- function(domain,


# The file name prefix is the JIRA project key. The from and to unix timestamps are then added.
file_name <- stringi::stri_extract_first_regex(str=s, pattern="(?<=project=')[:alpha:]+")
file_name <- stringi::stri_extract_first_regex(str=jql_query, pattern="(?<=project=')[:alpha:]+")

# Extract 'created' dates
created_dates <- sapply(r_object_content$issues, function(issue) issue$fields$created)
Expand Down
66 changes: 40 additions & 26 deletions vignettes/download_jira_issues.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ output:
number_sections: true
vignette: >
%\VignetteEngine{knitr::rmarkdown}
%\VignetteIndexEntry{Download JIRA Issues and Commentss}
%\VignetteIndexEntry{Download JIRA Issues and Comments}
%\VignetteEncoding{UTF-8}
---

Expand Down Expand Up @@ -41,7 +41,7 @@ Password: jondoespassword
Details on [how to obtain an atlassian token](https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/)

```{r}
conf <- yaml::read_yaml("../conf/geronimo.yml")
conf <- yaml::read_yaml("../conf/kaiaulu.yml")
# Project domain
issue_tracker_domain <- conf[["issue_tracker"]][["jira"]][["domain"]]
# Project key
Expand All @@ -63,26 +63,7 @@ password <- credentials[2]

## Create the directories specified in the config files.

The file schema of files for JIRA projects will be ../../rawdata/JIRA/project_name/issues or ../../rawdata/JIRA/project_name/issues_comments

If you have already created your directories, there is no need to run this chunk.
```{r eval = FALSE}
# Check if the directory for issues exists, create if it doesn't
if (!dir.exists(refresh_issues)) {
dir.create(refresh_issues)
message("Directory ", refresh_issues, " created")
} else {
message("Directory ", refresh_issues, " already exists")
}
# Check if the directory for issue comments exists, create if it doesn't
if (!dir.exists(refresh_issue_comments)) {
dir.create(refresh_issue_comments)
message("Directory ", refresh_issue_comments, " created")
} else {
message("Directory ", refresh_issue_comments, " already exists")
}
```
Before proceeding, make sure you created the folder structure you specified on the project configuration file. This Notebook will not create the folders automatically.

## Download issues

Expand All @@ -105,7 +86,13 @@ all_issues <- download_jira_issues(issue_tracker_domain,
"components",
"created",
"updated",
"resolutiondate"),
"resolutiondate",
"priority",
"votes",
"watches",
"versions",
"fixVersions",
"labels"),
# username = username,
# password,
save_path_issue_tracker_issues,
Expand Down Expand Up @@ -149,7 +136,13 @@ all_issues <- download_jira_issues_by_date (issue_tracker_domain,
"components",
"created",
"updated",
"resolutiondate"),
"resolutiondate",
"priority",
"votes",
"watches",
"versions",
"fixVersions",
"labels"),
save_path_issue_tracker_issues,
max_results = 50,
max_total_downloads = 5000,
Expand All @@ -171,6 +164,9 @@ If issues with issue key greater than an issue key value are desired, set issue_
issue_key_lower_bound <- "GERONIMO-500"
issue_key_upper_bound <- "GERONIMO-560"
#issue_key_lower_bound <- "SAILUH-1"
#issue_key_upper_bound <- "SAILUH-3"
all_issues <- download_jira_issues_by_issue_key(domain = issue_tracker_domain,
jql_query = paste0("project='",issue_tracker_project_key,"'"),
fields = c("summary",
Expand All @@ -184,15 +180,27 @@ all_issues <- download_jira_issues_by_issue_key(domain = issue_tracker_domain,
"components",
"created",
"updated",
"resolutiondate"),
"resolutiondate",
"priority",
"votes",
"watches",
"versions",
"fixVersions",
"labels"),
# username = username,
# password = password,
save_folder_path = save_path_issue_tracker_issues,
max_results = 50,
max_total_downloads = 5000,
issue_key_lower_bound = issue_key_lower_bound,
issue_key_upper_bound = issue_key_upper_bound,
verbose = TRUE)
```


```{r}
parsed_jira_issues <- parse_jira(save_path_issue_tracker_issues)
parsed_jira_issues[["issues"]]
Expand Down Expand Up @@ -220,7 +228,13 @@ refresh_jira_issues(
"components",
"created",
"updated",
"resolutiondate"),
"resolutiondate",
"priority",
"votes",
"watches",
"versions",
"fixVersions",
"labels"),
save_path_issue_tracker_issues,
max_results = 50,
max_total_downloads = 5000,
Expand Down

0 comments on commit 09a9622

Please sign in to comment.