---
subtitle: "Version"
author: ""
---

### Branches


```{r}
#| echo: false
#| output: asis

tibble::tibble(branch = system("git branch -a", intern = TRUE)) |>
  dplyr::filter(grepl("remotes", branch)) |>
  dplyr::filter(!grepl("HEAD", branch)) |>
  dplyr::mutate(branch = gsub("^.*\\/", "", branch)) |>
  dplyr::arrange(desc(branch)) |>
  dplyr::mutate(
    htmlstr = paste0(
      "## [**Version**: ",
      branch,
      "](https://drc.drwater.net/{{< var projtype >}}/",
      ifelse(grepl("pub", branch, ignore.case = TRUE), "public", "protected"),
      "/{{< var reponame >}}/",
      branch,
      "/)"
    )
  ) |>
  dplyr::pull(htmlstr) |>
  paste(collapse = "\n\n") |>
  cat()
```

### Versions

```{r}
#| echo: false
#| output: asis

# 方法2：先获取分支列表，再逐个查询
branches <- system("git branch -r", intern = TRUE)
branches <- trimws(branches) # 去除空白字符
branches <- branches[!grepl("HEAD", branches)]
branches <- tibble::tibble(branch = branches) |>
  dplyr::arrange(dplyr::desc(branch)) |>
  dplyr::pull(branch)

cat("\n")
for (branch in branches) {
  if (branch != "") {
    cat("### ", gsub("^.*/", "", branch), "\n\n")
    commits <- system(
      paste0(
        "git log --pretty=format:\"%h - %an, %ar : %s\" -5 \"",
        branch,
        "\""
      ),
      intern = TRUE
    )
    # all_commits[[branch]] <- paste0("- ", commits)
    cat(paste0("- ", commits), sep = "\n")
    cat("\n")
  }
}
```


