## ----setup-knitr-vignette, include = FALSE------------------------------------
knitr::opts_chunk$set(
    collapse = TRUE,
    comment = "#>"
)

## ----setup-IssueTrackeR, eval = TRUE, echo = FALSE----------------------------
# Handle credentials for GitLab if available
if (Sys.getenv("GITLAB_TRACTORTOM_API") != "") {
    gitlabr::set_gitlab_connection(
        gitlab_url = "https://gitlab.com",
        private_token = Sys.getenv("GITLAB_TRACTORTOM_API")
    )
}

## ----loading-IssueTrackeR, eval = TRUE, echo = TRUE---------------------------
library("IssueTrackeR")

## ----different-sources, eval = TRUE, echo = TRUE------------------------------
# GitHub selector
gh_sel <- init_selector(
    source = "GitHub",
    owner = "TanguyBarthelemy",
    repo = "IssueTrackeR"
)

# GitLab selector
gl_sel <- init_selector(source = "GitLab", project_id = 4578L)

# Local selector
local_sel <- init_selector(
    source = "local",
    dataset_dir = system.file("data_issues", package = "IssueTrackeR"),
    dataset_name = NULL
)

## ----display_selector, eval = TRUE, echo = TRUE-------------------------------
# Displaying them
print(gh_sel)
print(gl_sel)
print(local_sel)

## ----add_selector, eval = TRUE, echo = TRUE-----------------------------------
sel1 <- init_selector(
    source = "GitHub",
    owner = "TanguyBarthelemy",
    repo = "IssueTrackeR"
)
sel2 <- init_selector(
    source = "local",
    dataset_dir = system.file("data_issues", package = "IssueTrackeR"),
    dataset_name = NULL
)

combined_sel <- merge_selector(sel1, sel2)
print(combined_sel)

## ----extract_selector, eval = TRUE, echo = TRUE-------------------------------
extracted <- extract_nth(combined_sel, 1L)
print(extracted)

## ----remove_selector, eval = TRUE, echo = TRUE--------------------------------
# Let's create a list of 3 selectors to demonstrate
sel3 <- init_selector(
    source = "GitHub",
    owner = "rstudio",
    repo = "rstudio"
)
list_sel <- merge_selector(sel1, sel2, sel3)

# Remove the second one
reduced_sel <- remove_nth(list_sel, 2L)
print(reduced_sel)

## ----set_option, eval = TRUE, echo = TRUE-------------------------------------
# Check the current default
get_default_selector()

# Set a default selector
set_default_selector(sel1)
get_default_selector()

## ----reset_option, eval = TRUE, echo = TRUE-----------------------------------
reset_options()

