gitlabr icon indicating copy to clipboard operation
gitlabr copied to clipboard

Add functionality for milestones

Open konradmayer opened this issue 3 years ago • 2 comments

Thanks a lot for this great package!

This is a feature request for adding functionality for milestones to the package.

Being able to retreive milestones (besides issues) renders very powerful applications for project management possible - e.g. automated creation of Gantt charts using DiagrammeR.

I altereted your gl_list_issues() function for a quick try and it worked flawlessly, so it shouldn't be too much work to implement it as it basically boils down to mimic the issue functions.

gl_list_milestones <- function (project = NULL, milestone_id = NULL, verb = httr::GET, 
          api_version = 4, ...) 
{
  (if (!missing(project) && is.null(project)) 
    "milestones"
    else gl_proj_req(project, req = c("milestones", milestone_id), ...)) %>% 
    gitlab(...) %>% arpr::iffn(is.null(milestone_id), function(milestone) {
      milestone %>% unlist(recursive = TRUE) %>% t() %>% as.data.frame()
    })
}

In case I ever find the time for it I would be more than happy to contribute a PR on this issue, but I cannot give any estimate on when this might be...

konradmayer avatar Nov 17 '21 14:11 konradmayer

Thank you.
I think it can be simplified if I understand your need correctly.
Is that correct?

id <- 317

# Use existing API directly
gitlabr::gitlab(
  req = c("projects" , id, "milestones"),
  verb = httr::GET
)

# Create a function to get all milestones
gl_list_milestones <- function(project, ...) {
  gl_proj_req(project, c("milestones"), ...) %>% 
    gitlab(...)
}

all_milestones <- gl_list_milestones(project = 317)

# Get milestones issues
gl_list_issues(project = 317, milestone = all_milestones$title[2])

statnmap avatar Nov 17 '21 15:11 statnmap

Wow, thats a fast response!

outlined use case

Yes, this is perfect.

By the way, I didn't realize that milestone information also comes with gl_list_issues(), so to get a dataframe of milestones with assigned issues as a list column one can simply do:

project <- "projectname"
# this excludes milestones without assigned issues
all_issues <- gl_list_issues(project = project)
all_issues  %>% nest(issues = -starts_with("milestone."))

However, this does not include milestones without issues assigned. So, using your approach outlines above a better way to do this looks more or less like this:

gl_list_milestones <- function(project, ...) {
  gl_proj_req(project, c("milestones"), ...) %>%
    gitlab(...)
}

project <- "projectname"
# Get milestones
all_milestones <- gl_list_milestones(project = project) %>%
  setNames(paste0('milestone.', names(.)))
# Get issues
all_issues <- gl_list_issues(project = project)

# Join dataframes and nest by milestone
all_milestones %>%
  full_join(all_issues, by = names(all_milestones)) %>%
  nest(issues = -starts_with("milestone."))

feature request

My main motivation for the feature request, i.e. this issue, was the use case as shown above. However it would be useful to have all the APIs functionality (create, edit,...) available, just as it is the case for issues.

https://docs.gitlab.com/ee/api/milestones.html

konradmayer avatar Nov 18 '21 08:11 konradmayer