milestoner 11.1.0 → 12.0.2

Sign up to get free protection for your applications and to get access to all the features.
metadata.gz.sig CHANGED
Binary file
@@ -1,120 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "thor"
4
- require "thor/actions"
5
- require "runcom"
6
-
7
- module Milestoner
8
- # The Command Line Interface (CLI) for the gem.
9
- class CLI < Thor
10
- include Thor::Actions
11
-
12
- package_name Identity::VERSION_LABEL
13
-
14
- def self.configuration
15
- Runcom::Config.new "#{Identity::NAME}/configuration.yml",
16
- defaults: {
17
- git_commit_prefixes: %w[Fixed Added Updated Removed Refactored],
18
- git_tag_sign: false
19
- }
20
- end
21
-
22
- def initialize args = [], options = {}, config = {}
23
- super args, options, config
24
- @configuration = self.class.configuration
25
- @tagger = Tagger.new commit_prefixes: @configuration.to_h[:git_commit_prefixes]
26
- @pusher = Pusher.new
27
- @publisher = Publisher.new tagger: tagger, pusher: pusher
28
- rescue Runcom::Errors::Base => error
29
- abort error.message
30
- end
31
-
32
- desc "-C, [--commits]", "Show commits for next milestone."
33
- map %w[-C --commits] => :commits
34
- def commits
35
- tagger.commit_list.each { |commit| say commit }
36
- rescue StandardError => error
37
- say_status :error, error.message, :red
38
- end
39
-
40
- desc "-t, [--tag=VERSION]", "Tag local repository with new version."
41
- map %w[-t --tag] => :tag
42
- method_option :sign,
43
- aliases: "-s",
44
- desc: "Sign tag with GPG key.",
45
- type: :boolean,
46
- default: false
47
- def tag version
48
- tagger.create version, sign: sign_tag?(options[:sign])
49
- say "Repository tagged: #{version}."
50
- rescue StandardError => error
51
- say_status :error, error.message, :red
52
- end
53
-
54
- desc "-p, [--push=VERSION]", "Push local tag to remote repository."
55
- map %w[-p --push] => :push
56
- def push version
57
- pusher.push version
58
- say_status :info, "Tags pushed to remote repository.", :green
59
- rescue StandardError => error
60
- say_status :error, error.message, :red
61
- end
62
-
63
- desc "-P, [--publish=VERSION]", "Tag and push milestone to remote repository."
64
- map %w[-P --publish] => :publish
65
- method_option :sign,
66
- aliases: "-s",
67
- desc: "Sign tag with GPG key.",
68
- type: :boolean,
69
- default: false
70
- def publish version
71
- publisher.publish version, sign: sign_tag?(options[:sign])
72
- say_status :info, "Repository tagged and pushed: #{version}.", :green
73
- say_status :info, "Milestone published!", :green
74
- rescue StandardError => error
75
- say_status :error, error.message, :red
76
- end
77
-
78
- desc "-c, [--config]", "Manage gem configuration."
79
- map %w[-c --config] => :config
80
- method_option :edit,
81
- aliases: "-e",
82
- desc: "Edit gem configuration.",
83
- type: :boolean,
84
- default: false
85
- method_option :info,
86
- aliases: "-i",
87
- desc: "Print gem configuration.",
88
- type: :boolean,
89
- default: false
90
- def config
91
- path = configuration.current
92
-
93
- if options.edit? then `#{ENV["EDITOR"]} #{path}`
94
- elsif options.info?
95
- path ? say(path) : say("Configuration doesn't exist.")
96
- else help :config
97
- end
98
- end
99
-
100
- desc "-v, [--version]", "Show gem version."
101
- map %w[-v --version] => :version
102
- def version
103
- say Identity::VERSION_LABEL
104
- end
105
-
106
- desc "-h, [--help=COMMAND]", "Show this message or get help for a command."
107
- map %w[-h --help] => :help
108
- def help task = nil
109
- say and super
110
- end
111
-
112
- private
113
-
114
- attr_reader :configuration, :tagger, :pusher, :publisher
115
-
116
- def sign_tag? sign
117
- sign | configuration.to_h[:git_tag_sign]
118
- end
119
- end
120
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "forwardable"
4
-
5
- module Milestoner
6
- # Wraps the Git Kit Commit for presentation purposes.
7
- class Commit
8
- extend Forwardable
9
-
10
- delegate [*GitPlus::Commit.members, :fixup?, :squash?] => :source
11
-
12
- def initialize source
13
- @source = source
14
- end
15
-
16
- def subject_author delimiter: " - "
17
- "#{subject}#{delimiter}#{author_name}"
18
- end
19
-
20
- private
21
-
22
- attr_reader :source
23
- end
24
- end
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Milestoner
4
- module Errors
5
- # The base class for all Milestoner related errors.
6
- class Base < StandardError
7
- def initialize message = "Invalid Milestoner action."
8
- super message
9
- end
10
- end
11
- end
12
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Milestoner
4
- module Errors
5
- # Raised for duplicate tags.
6
- class DuplicateTag < Base
7
- end
8
- end
9
- end
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Milestoner
4
- module Errors
5
- # Raised for projects not initialized as Git repositories.
6
- class Git < Base
7
- def initialize message = "Invalid Git repository."
8
- super message
9
- end
10
- end
11
- end
12
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Milestoner
4
- # Handles the tagging and pushing of a milestone to a remote repository.
5
- class Publisher
6
- def initialize tagger: Tagger.new, pusher: Pusher.new
7
- @tagger = tagger
8
- @pusher = pusher
9
- end
10
-
11
- # :reek:BooleanParameter
12
- def publish version, sign: false
13
- tagger.create version, sign: sign
14
- pusher.push version
15
- end
16
-
17
- private
18
-
19
- attr_reader :tagger, :pusher
20
- end
21
- end
@@ -1,34 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Milestoner
4
- # Handles publishing of Git tags to remote repository.
5
- class Pusher
6
- def initialize repository: GitPlus::Repository.new
7
- @repository = repository
8
- end
9
-
10
- def push version
11
- version = Versionaire::Version version
12
-
13
- fail Errors::Git, "Remote repository not configured." unless repository.config_origin?
14
- fail Errors::Git, "Remote tag exists: #{version}." if tag_exists? version
15
- return if push_tags
16
-
17
- fail Errors::Git, "Tags could not be pushed to remote repository."
18
- end
19
-
20
- private
21
-
22
- attr_reader :repository, :version
23
-
24
- def tag_exists? version
25
- repository.tag_remote? version
26
- end
27
-
28
- def push_tags
29
- repository.tag_push.then do |_stdout, stderr, status|
30
- status.success? && stderr.match?(/[new tag]/)
31
- end
32
- end
33
- end
34
- end
@@ -1,88 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "thor"
4
- require "versionaire"
5
-
6
- module Milestoner
7
- # Handles the tagging of a project repository.
8
- # :reek:TooManyInstanceVariables
9
- class Tagger
10
- attr_reader :commit_prefixes
11
-
12
- def initialize commit_prefixes: [], repository: GitPlus::Repository.new, presenter: Commit
13
- @commit_prefixes = commit_prefixes
14
- @repository = repository
15
- @presenter = presenter
16
- @shell = Thor::Shell::Color.new
17
- end
18
-
19
- def commit_prefix_regex
20
- commit_prefixes.empty? ? Regexp.new("") : Regexp.union(commit_prefixes)
21
- end
22
-
23
- def commits
24
- groups = build_commit_prefix_groups
25
- group_by_commit_prefix groups
26
- groups.each_value { |commits| commits.sort_by!(&:subject) }
27
- groups.values.flatten.uniq(&:subject)
28
- end
29
-
30
- def commit_list
31
- commits.map { |source| presenter.new source }
32
- .map { |commit| "- #{commit.subject_author}" }
33
- end
34
-
35
- # :reek:BooleanParameter
36
- # :reek:ControlParameter
37
- # :reek:TooManyStatements
38
- def create version, sign: false
39
- version = Versionaire::Version version
40
- fail Errors::Git, "Unable to tag without commits." if repository.commits.empty?
41
- return if exists? version
42
-
43
- content = message version
44
- sign ? repository.tag_sign(version, content) : repository.tag_unsign(version, content)
45
- end
46
-
47
- private
48
-
49
- attr_reader :repository, :presenter, :shell
50
-
51
- def saved_commits
52
- repository.commits
53
- end
54
-
55
- def tagged_commits
56
- repository.commits "#{repository.tag_last}..HEAD"
57
- end
58
-
59
- def computed_commits
60
- (repository.tagged? ? tagged_commits : saved_commits)
61
- end
62
-
63
- def build_commit_prefix_groups
64
- commit_prefixes.map
65
- .with_object({}) { |prefix, group| group.merge! prefix => [] }
66
- .merge! "Other" => []
67
- end
68
-
69
- def group_by_commit_prefix groups = {}
70
- computed_commits.each do |commit|
71
- prefix = commit.subject[commit_prefix_regex]
72
- key = groups.key?(prefix) ? prefix : "Other"
73
- groups[key] << commit
74
- end
75
- end
76
-
77
- def message version
78
- %(Version #{version}\n\n#{commit_list.join "\n"}\n\n)
79
- end
80
-
81
- def exists? version
82
- return false unless repository.tag_local? version
83
-
84
- shell.say_status :warn, "Local tag exists: #{version}. Skipped.", :yellow
85
- true
86
- end
87
- end
88
- end