Last active
January 15, 2021 12:33
-
-
Save simonthompson99/cfa0dbbdfccee068159b55d93ee8010b to your computer and use it in GitHub Desktop.
[List JIRA issues matching a query] List JIRA issues that match a jql statement #r #jira #api
This file contains hidden or 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
| list_jira_issues <- function(jql, u, p, base_url = 'https://jira.extge.co.uk', fields = c('key'), ignore = c('expand', 'self', 'id')){ | |
| # list issues on jira, returns a dataframe of results | |
| # jql - jira query language string (copy from advanced search url) | |
| # u, p - username and password | |
| # base_url - url of service | |
| # fields - vector of fields of interest | |
| # ignore - vector of column names that can be removed from the output | |
| list_jira_issues_pg <- function(jql, u, p, st, npp, base_url, fields){ | |
| # get a single page of search results | |
| require(httr) | |
| require(jsonlite) | |
| r_url <- paste0(base_url, "/rest/api/2/search?jql=", jql, "&startAt=", st, "&maxResults=", npp, '&fields=', paste0(fields, collapse = ',')) | |
| print(r_url) | |
| r <- GET(r_url, authenticate(u, p, type = 'basic')) | |
| if(!http_status(r)$category %in% 'Success'){ | |
| stop(paste('Unsuccessful attempt for', r_url, '-', http_status(r)$message)) | |
| } | |
| return(fromJSON(content(r, 'text'), flatten = T)) | |
| } | |
| # start at zero with 100 issues per page | |
| st = 0 | |
| npp = 100 | |
| # get first load of results | |
| r = list_jira_issues_pg(jql, u, p, st, npp, base_url, fields) | |
| out = r$issues | |
| # get total number of issues | |
| nr = r$total | |
| st = r$startAt | |
| while(nrow(out) != nr){ | |
| # for however long is required, get each page and update the starting point | |
| r = list_jira_issues_pg(jql, u, p, st + npp, npp, base_url) | |
| st <- r$startAt | |
| out = rbind(out, r$issues) | |
| } | |
| # return the result minus the ignored columns | |
| return(out[,!colnames(out) %in% ignore]) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment