captive-release 0.16.2 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b8e9173ce70fddbcdb2396933256c39ff04a92bf10d6c8700ef60973719e4219
4
- data.tar.gz: c9d2f0905a0064ddd920122c3772ee1f0486c246230f5d6eccb08b376a8220fc
3
+ metadata.gz: 738c0d7d62daeac44f226af30cd8302da632fee9594333d987506aaf693ad4df
4
+ data.tar.gz: c2ca4738b0ec50e08ed89bb266b802d23910c5475911e5974c93f1dbf31bd9ec
5
5
  SHA512:
6
- metadata.gz: d4fd5159885998ca8f9cddc485ea63bc4b6091883d7e44bd03c2b2b16167e0778c6c4c5557480f956a7551f93ac5c0c98354c7b4d4c5c54c009cb4685d142798
7
- data.tar.gz: fb9985934097f181c116a21b82f5ae8b27eec355f157e5ff462bf74baf9d45ee97c1bd18bfd4d581feedcde3b520822a2181e53e183db53e02830c8b8ec0b571
6
+ metadata.gz: 803d40e8e76c908d9a90603610e60419b55102cb06cb44c22834d62e60066d285f2ff3c9d96a51f7481febe32ba35330144c105363cf5cc7847c104944525919
7
+ data.tar.gz: 323f968489ed58d7dd12d58ae44249223a1c6ed3e5ec5bd4478c28730dbb204507f2aca0d1585c2f02c5ea4c48d2709cfa994079018831b3f0a8be5a0557cde3
@@ -13,8 +13,7 @@ module CaptiveRelease
13
13
  @keys = keys
14
14
  end
15
15
 
16
- def call(libelles)
17
- rang = 0
16
+ def call(libelles, rang = 0)
18
17
  loop do
19
18
  draw(libelles, rang)
20
19
  touche = @keys.read
@@ -13,7 +13,7 @@ module CaptiveRelease
13
13
  def call(framework, workflow_par_defaut)
14
14
  titre = "\n#{@terminal.bold(Messages.t(:framework_detected, framework: framework))} " \
15
15
  "#{Messages.t(:configure_build)}"
16
- return nil unless Menu.new(terminal: @terminal).choose(titre, Messages.t(:yes) => true, Messages.t(:no) => false)
16
+ return nil unless Menu.new(terminal: @terminal).choose(titre, { Messages.t(:yes) => true, Messages.t(:no) => false })
17
17
 
18
18
  BuildConfig.new(build_workflow: workflow(workflow_par_defaut))
19
19
  end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CaptiveRelease
4
+ # Alerte quand la release part d'une autre branche que la principale : le tag désignerait
5
+ # un commit que la branche principale ne contient pas.
6
+ #
7
+ # Cette unité change quand la politique de branche change, ReleasePreconditions quand les
8
+ # conditions bloquantes changent.
9
+ class DefaultBranchGuard
10
+ def initialize(terminal:)
11
+ @terminal = terminal
12
+ end
13
+
14
+ def verifier!
15
+ courante = GitCommands.current_branch
16
+ principale = GitCommands.default_branch
17
+ return if courante == principale
18
+
19
+ @terminal.say Messages.t(:not_on_default_branch, branch: courante, default: principale)
20
+ exit 1 unless Messages.yes?(@terminal.ask(Messages.t(:continue_anyway)))
21
+ end
22
+ end
23
+ end
@@ -21,6 +21,13 @@ module CaptiveRelease
21
21
  Shell.capture_lines("git log --pretty=%s #{Shell.escape(tag)}..HEAD")
22
22
  end
23
23
 
24
+ def self.repository? = Shell.run?("git rev-parse --is-inside-work-tree >/dev/null 2>&1")
25
+
26
+ # La branche par défaut du remote ; sans origin/HEAD connu, main par convention.
27
+ def self.default_branch
28
+ Shell.capture("git symbolic-ref --short refs/remotes/origin/HEAD 2>/dev/null")[%r{\Aorigin/(.+)}, 1] || "main"
29
+ end
30
+
24
31
  def self.current_branch
25
32
  branche = Shell.capture("git rev-parse --abbrev-ref HEAD 2>/dev/null")
26
33
  branche.empty? ? "main" : branche
@@ -79,6 +79,8 @@ en:
79
79
  workflow_not_found: |-
80
80
  Workflow %{workflow} not found on %{repo}.
81
81
  Add .github/workflows/%{workflow} to the default branch, or fix build_workflow in the configuration.
82
+ not_a_git_repository: Not a git repository. Run captive-release from inside a repository.
83
+ not_on_default_branch: "⚠️ You are on branch %{branch}, not on the default branch %{default}."
82
84
  dirty_tree: The working tree is not clean.
83
85
  dirty_tree_hint: Commit or stash your changes before releasing.
84
86
  current_version: 'Current version: %{version}'
@@ -79,6 +79,8 @@ fr:
79
79
  workflow_not_found: |-
80
80
  Workflow %{workflow} introuvable sur %{repo}.
81
81
  Ajoutez .github/workflows/%{workflow} sur la branche par défaut, ou corrigez build_workflow dans la configuration.
82
+ not_a_git_repository: Pas de dépôt git ici. Lancez captive-release depuis un dépôt.
83
+ not_on_default_branch: "⚠️ Vous êtes sur la branche %{branch}, pas sur la branche principale %{default}."
82
84
  dirty_tree: L'arbre de travail n'est pas propre.
83
85
  dirty_tree_hint: Commitez ou remisez vos modifications avant de releaser.
84
86
  current_version: 'Version actuelle : %{version}'
@@ -13,10 +13,11 @@ module CaptiveRelease
13
13
  end
14
14
 
15
15
  # entries : un Hash {libellé affiché => valeur rendue}, dans l'ordre d'affichage.
16
- def choose(title, entries)
16
+ def choose(title, entries, default: 0)
17
17
  @terminal.say "#{title}\n"
18
18
  libelles = entries.keys
19
- entries.values[@keys.interactive? ? ArrowSelect.new(terminal: @terminal, keys: @keys).call(libelles) : numbered(libelles)]
19
+ rang = @keys.interactive? ? ArrowSelect.new(terminal: @terminal, keys: @keys).call(libelles, default) : numbered(libelles)
20
+ entries.values[rang]
20
21
  end
21
22
 
22
23
  private
@@ -13,14 +13,8 @@ module CaptiveRelease
13
13
  end
14
14
 
15
15
  def run(bump_arg, confirmation:)
16
- ReleasePreconditions.new(terminal: @terminal).verifier!
17
- courante = @config.current_version
18
- suggestion = ReleaseOverview.new(terminal: @terminal).call(courante)
19
-
20
- prochaine = VersionChoice.new(terminal: @terminal).call(courante, bump_arg)
21
- PrereleaseGuard.new(terminal: @terminal).verifier!(prochaine, @config.version_files)
22
- ReleaseConfirmation.new(terminal: @terminal).verifier!(suggestion, courante, prochaine) if confirmation
23
-
16
+ prochaine = ReleaseVersionDecision.new(terminal: @terminal, version_files: @config.version_files)
17
+ .call(@config.current_version, bump_arg, confirmation: confirmation)
24
18
  VersionFilesWriting.new(terminal: @terminal).call(prochaine, @config.version_files)
25
19
  GitRelease.new(terminal: @terminal, token_provider: @token_provider).call(prochaine, chemins_a_commiter)
26
20
  publication.call(prochaine)
@@ -14,11 +14,21 @@ module CaptiveRelease
14
14
  end
15
15
 
16
16
  def verifier!
17
+ verifier_depot!
17
18
  return unless GitCommands.dirty?
18
19
 
19
20
  @terminal.say @terminal.error(Messages.t(:dirty_tree))
20
21
  @terminal.say "#{Messages.t(:dirty_tree_hint)}\n"
21
22
  exit 1
22
23
  end
24
+
25
+ private
26
+
27
+ def verifier_depot!
28
+ return if GitCommands.repository?
29
+
30
+ @terminal.say @terminal.error(Messages.t(:not_a_git_repository))
31
+ exit 1
32
+ end
23
33
  end
24
34
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CaptiveRelease
4
+ # Décider vers quelle version on part : préconditions, choix, garde-fous, confirmation.
5
+ #
6
+ # Cette unité change quand la manière de choisir ou de valider la version change,
7
+ # ReleaseCommand quand les étapes qui appliquent cette version changent.
8
+ class ReleaseVersionDecision
9
+ def initialize(terminal:, version_files:)
10
+ @terminal = terminal
11
+ @version_files = version_files
12
+ end
13
+
14
+ def call(courante, bump_arg, confirmation:)
15
+ ReleasePreconditions.new(terminal: @terminal).verifier!
16
+ DefaultBranchGuard.new(terminal: @terminal).verifier! if confirmation
17
+ suggestion = ReleaseOverview.new(terminal: @terminal).call(courante)
18
+ prochaine = VersionChoice.new(terminal: @terminal).call(courante, bump_arg, suggestion)
19
+ PrereleaseGuard.new(terminal: @terminal).verifier!(prochaine, @version_files)
20
+ ReleaseConfirmation.new(terminal: @terminal).verifier!(suggestion, courante, prochaine) if confirmation
21
+ prochaine
22
+ end
23
+ end
24
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CaptiveRelease
4
- VERSION = "0.16.2"
4
+ VERSION = "0.17.0"
5
5
  end
@@ -14,8 +14,8 @@ module CaptiveRelease
14
14
  @terminal = terminal
15
15
  end
16
16
 
17
- def call(current, bump_arg)
18
- bump_arg ? resolve(current, bump_arg) : ask(current)
17
+ def call(current, bump_arg, suggestion = nil)
18
+ bump_arg ? resolve(current, bump_arg) : ask(current, suggestion)
19
19
  end
20
20
 
21
21
  private
@@ -26,8 +26,11 @@ module CaptiveRelease
26
26
  refuse(Messages.t(:invalid_bump_type, type: type))
27
27
  end
28
28
 
29
- def ask(current)
30
- choisi = Menu.new(terminal: @terminal).choose(Messages.t(:choose_release_type), candidates_for(current))
29
+ # Le curseur part sur le bump suggéré par les commits, s'il fait partie des candidats.
30
+ def ask(current, suggestion)
31
+ candidats = candidates_for(current)
32
+ defaut = candidats.values.index { |version| version == VersionBumper.bump(current, suggestion) } if suggestion
33
+ choisi = Menu.new(terminal: @terminal).choose(Messages.t(:choose_release_type), candidats, default: defaut || 0)
31
34
  choisi == CUSTOM ? type_it : choisi
32
35
  end
33
36
 
@@ -24,6 +24,7 @@ require_relative "captive_release/bump_suggestion"
24
24
  require_relative "captive_release/version_severity"
25
25
  require_relative "captive_release/bump_safety_net"
26
26
  require_relative "captive_release/prerelease_guard"
27
+ require_relative "captive_release/default_branch_guard"
27
28
  require_relative "captive_release/github_repo"
28
29
  require_relative "captive_release/github_http"
29
30
  require_relative "captive_release/github_api"
@@ -56,6 +57,7 @@ require_relative "captive_release/version_files_writing"
56
57
  require_relative "captive_release/release_preconditions"
57
58
  require_relative "captive_release/release_overview"
58
59
  require_relative "captive_release/release_confirmation"
60
+ require_relative "captive_release/release_version_decision"
59
61
  require_relative "captive_release/release_command"
60
62
  require_relative "captive_release/update_check"
61
63
  require_relative "captive_release/help"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: captive-release
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.2
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Captive Studio
@@ -35,6 +35,7 @@ files:
35
35
  - lib/captive_release/config_file.rb
36
36
  - lib/captive_release/config_loader.rb
37
37
  - lib/captive_release/config_writer.rb
38
+ - lib/captive_release/default_branch_guard.rb
38
39
  - lib/captive_release/direct_commits.rb
39
40
  - lib/captive_release/exclusion_input.rb
40
41
  - lib/captive_release/framework_detector.rb
@@ -69,6 +70,7 @@ files:
69
70
  - lib/captive_release/release_preconditions.rb
70
71
  - lib/captive_release/release_publication.rb
71
72
  - lib/captive_release/release_pull_request.rb
73
+ - lib/captive_release/release_version_decision.rb
72
74
  - lib/captive_release/repo_files.rb
73
75
  - lib/captive_release/ruby_gems_version.rb
74
76
  - lib/captive_release/semver.rb