Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add which "pre-minor" and "pre-major" to update_version() #412

Merged
merged 17 commits into from
Sep 5, 2022

Conversation

maelle
Copy link
Member

@maelle maelle commented Jul 28, 2022

Fix #413

Part of #401

As you will see there are two questions in the comments

  # first check there is a fourth component, if not
  # the which should have been another one.
  # at least that's what I understand?

and

# does this assume patch/minor can't already be higher than 99?

@maelle
Copy link
Member Author

maelle commented Jul 28, 2022

I added tests so you can see whether what's here is what you expected.

@maelle

This comment was marked as resolved.

@maelle

This comment was marked as resolved.


fledge_bump_version <- function(desc, which) {
if (which %in% c("patch", "minor", "major", "dev")) {
desc$bump_version(which)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we forbid > 99 here? We can roll our own bumping, we won't need suppressMessages() above too.

Perhaps:

new_version <- switch(which,
  "dev" = c(major, minor, patch, (dev + 1) %||% 9000),
  "patch" = {
    if (patch >= 99) abort(...)
    c(...)
  },
  "minor" = ...
)

with explicit local variables for the four components?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we forbid > 99 here

And abort if patch/minor are already higher? I had wondered about this in a comment too.

We can roll our own bumping, we won't need suppressMessages() above too.

  • Actually the desc issue was solved so that's not needed anyway.
  • I find it easier to separate both cases as we need to check the fourth component (dev) is present for "pre-minor" and "pre-major" (at least I assume so: one can't go from not dev to "pre-minor"/"pre-major"?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to abort if patch >= 99, as in the code example, overall it looks like it will be simpler without desc::bump_version() .

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the error. Does the behavior in the test file look ok?

Why would removing

  if (which %in% c("patch", "minor", "major", "dev")) {
    desc$bump_version(which)
    return(desc)
  }

be simpler?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel the current code gets the "easiest cases" out of the way right away but I can amend further obviously.

@maelle maelle requested a review from krlmlr September 1, 2022 10:56
Copy link
Contributor

@krlmlr krlmlr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if we bump pre-major and then pre-minor?

Comment on lines 59 to 62
if (which %in% c("patch", "minor", "major", "dev")) {
suppressMessages(desc$bump_version(which), classes = "descMessage")
return(desc)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should do this ourselves, because we want to error:

  • in "dev", when dev >= 9999
  • in "patch", when patch >= 99
  • in "minor", when minor >= 99

version_components <- get_version_components(version)

if (which %in% c("patch", "minor", "major", "dev")) {
version_components[["dev"]] <- switch(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found it easier to follow to use switch once per component (and to still separate the "usual" cases from pre-minor and pre-major).

@maelle maelle requested a review from krlmlr September 5, 2022 11:59
Copy link
Contributor

@krlmlr krlmlr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I just realized we might want another option: "next", moving from pre-minor to minor and from pre-major to major, and to patch otherwise. Would be the default option to pre_release() . We can do it here or open a new issue.

Do we need more tests for error behavior, e.g. pre-minor after pre-minor, pre-minor after pre-major, and other exotic cases?

R/update-version.R Show resolved Hide resolved
R/update-version.R Outdated Show resolved Hide resolved
tests/testthat/test-update-version.R Show resolved Hide resolved
@maelle maelle mentioned this pull request Sep 5, 2022
maelle and others added 3 commits September 5, 2022 14:15
Co-authored-by: Kirill Müller <krlmlr@users.noreply.github.com>
@maelle
Copy link
Member Author

maelle commented Sep 5, 2022

I'd also add more tests when tackling the "next" issue.

@maelle
Copy link
Member Author

maelle commented Sep 5, 2022

And at some points the docs will need a diagram.

@maelle maelle requested a review from krlmlr September 5, 2022 12:26
Copy link
Contributor

@krlmlr krlmlr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Expert nitpicking here, no clear preference.

Comment on lines +151 to +153
dev = dev
)
new_version <- paste(version_components[!is.na(version_components)], collapse = ".")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
dev = dev
)
new_version <- paste(version_components[!is.na(version_components)], collapse = ".")
dev = if (!is.na(dev)) dev
)
new_version <- paste(version_components, collapse = ".")

@krlmlr krlmlr merged commit fb4f097 into main Sep 5, 2022
@krlmlr krlmlr deleted the preminor branch September 5, 2022 12:30
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

new modes for bump_version()
2 participants