Skip to content

Commit

Permalink
feat: Newsworthy commits are searched along the first parents only, p…
Browse files Browse the repository at this point in the history
…icking up all relevant commits (#847)
  • Loading branch information
krlmlr authored Dec 1, 2024
1 parent 9854631 commit 4a871de
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 40 deletions.
20 changes: 7 additions & 13 deletions R/commits.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ get_first_parent <- function(commit, since) {

repeat {
all_parents <- gert::git_commit_info(commit)$parents
first_parent <- get_parent_since(all_parents, since)
if (is_null(first_parent)) {
if (is_empty(all_parents)) {
return(commits)
}

first_parent <- all_parents[[1]]

if (!is_null(since) && gert::git_ahead_behind(since, first_parent)$ahead == 0) {
return(commits)
}

Expand All @@ -33,17 +38,6 @@ get_first_parent <- function(commit, since) {
}
}

get_parent_since <- function(all_parents, since) {
if (is_empty(all_parents)) {
return(NULL)
}
if (is_null(since)) {
return(all_parents[[1]])
}

purrr::detect(all_parents, ~ gert::git_ahead_behind(since, .x)$behind == 0)
}

get_last_tag_impl <- function(ref = "HEAD", pattern = NULL) {
repo_head <- gert::git_log(ref, max = 1)

Expand Down
16 changes: 8 additions & 8 deletions tests/testthat/_snaps/bump_version.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
Code
bump_version(no_change_behavior = "fail")
Message
> Digesting messages from 2 commits.
> Digesting messages from 1 commits.
Condition
Error in `bump_version_impl()`:
x No change since last version.
Expand All @@ -37,16 +37,16 @@
Code
bump_version(no_change_behavior = "noop")
Message
> Digesting messages from 2 commits.
> Digesting messages from 1 commits.
i No change since last version.

---

Code
bump_version(no_change_behavior = "bump")
Message
> Digesting messages from 2 commits.
i Internal changes only.
> Digesting messages from 1 commits.
i Same as previous version.
-- Updating NEWS --
Expand Down Expand Up @@ -91,7 +91,7 @@
Code
bump_version(no_change_behavior = "fail")
Message
> Digesting messages from 1 commits.
> Digesting messages from 2 commits.
Condition
Error in `bump_version_impl()`:
x No change since last version.
Expand All @@ -102,16 +102,16 @@
Code
bump_version(no_change_behavior = "noop")
Message
> Digesting messages from 1 commits.
> Digesting messages from 2 commits.
i No change since last version.

---

Code
bump_version(no_change_behavior = "bump")
Message
> Digesting messages from 1 commits.
i Same as previous version.
> Digesting messages from 2 commits.
i Internal changes only.
-- Updating NEWS --
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/bump_version/NEWS2.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# tea 0.0.0.9002

- Internal changes only.
- Same as previous version.


# tea 0.0.0.9001
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/bump_version/NEWS3.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# tea 0.0.0.9002

- Same as previous version.
- Internal changes only.


# tea 0.0.0.9001
Expand Down
24 changes: 11 additions & 13 deletions tests/testthat/_snaps/commits.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,41 @@
Code
get_top_level_commits_impl(repo$a)["message"]
Output
# A tibble: 3 x 1
# A tibble: 2 x 1
message
<chr>
1 "- merge\n"
2 "- b\n"
3 "- a\n"
Code
get_top_level_commits_impl(repo$b)["message"]
Output
# A tibble: 2 x 1
# A tibble: 1 x 1
message
<chr>
1 "- merge\n"
2 "- b\n"
Code
get_top_level_commits_impl(repo$e)["message"]
get_top_level_commits_impl(repo$c)["message"]
Output
# A tibble: 1 x 1
# A tibble: 3 x 1
message
<chr>
1 "- merge\n"
2 "- b\n"
3 "- a\n"
Code
# # Questioning
get_top_level_commits_impl(repo$c)["message"]
get_top_level_commits_impl(repo$d)["message"]
Output
# A tibble: 3 x 1
message
<chr>
1 "- merge\n"
2 "- d\n"
3 "- c\n"
2 "- b\n"
3 "- a\n"
Code
get_top_level_commits_impl(repo$d)["message"]
get_top_level_commits_impl(repo$e)["message"]
Output
# A tibble: 2 x 1
# A tibble: 1 x 1
message
<chr>
1 "- merge\n"
2 "- d\n"

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/demo/demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ Now that we have added bowl support to our package, it is time to bump the versi

``` r
fledge::bump_version()
## > Digesting messages from 2 commits.
## > Digesting messages from 1 commits.
## v Found 1 NEWS-worthy entry.
##
## -- Updating NEWS --
Expand Down
4 changes: 1 addition & 3 deletions tests/testthat/test-commits.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ test_that("get_top_level_commits_impl() works", {
get_top_level_commits_impl(NULL)["message"]
get_top_level_commits_impl(repo$a)["message"]
get_top_level_commits_impl(repo$b)["message"]
get_top_level_commits_impl(repo$e)["message"]

"# Questioning"
get_top_level_commits_impl(repo$c)["message"]
get_top_level_commits_impl(repo$d)["message"]
get_top_level_commits_impl(repo$e)["message"]
})
})

0 comments on commit 4a871de

Please sign in to comment.