mongoid 8.0.11 → 8.1.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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +3 -3
- data/README.md +3 -3
- data/Rakefile +17 -66
- data/lib/config/locales/en.yml +46 -14
- data/lib/mongoid/association/accessors.rb +3 -7
- data/lib/mongoid/association/builders.rb +1 -1
- data/lib/mongoid/association/eager_loadable.rb +0 -3
- data/lib/mongoid/association/embedded/batchable.rb +2 -2
- data/lib/mongoid/association/embedded/embedded_in/buildable.rb +2 -2
- data/lib/mongoid/association/embedded/embedded_in/proxy.rb +2 -1
- data/lib/mongoid/association/embedded/embeds_many/buildable.rb +3 -2
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +6 -6
- data/lib/mongoid/association/embedded/embeds_one/buildable.rb +1 -1
- data/lib/mongoid/association/embedded/embeds_one/proxy.rb +2 -2
- data/lib/mongoid/association/macros.rb +0 -6
- data/lib/mongoid/association/nested/one.rb +40 -2
- data/lib/mongoid/association/proxy.rb +1 -1
- data/lib/mongoid/association/referenced/counter_cache.rb +2 -2
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +1 -1
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +6 -23
- data/lib/mongoid/association/referenced/has_many/proxy.rb +3 -3
- data/lib/mongoid/association/reflections.rb +2 -2
- data/lib/mongoid/atomic.rb +7 -16
- data/lib/mongoid/attributes/dynamic.rb +1 -1
- data/lib/mongoid/attributes/nested.rb +2 -2
- data/lib/mongoid/attributes/processing.rb +5 -29
- data/lib/mongoid/attributes/projector.rb +1 -1
- data/lib/mongoid/attributes/readonly.rb +1 -1
- data/lib/mongoid/attributes.rb +8 -2
- data/lib/mongoid/changeable.rb +107 -5
- data/lib/mongoid/clients/storage_options.rb +2 -5
- data/lib/mongoid/clients/validators/storage.rb +1 -13
- data/lib/mongoid/collection_configurable.rb +58 -0
- data/lib/mongoid/composable.rb +2 -0
- data/lib/mongoid/config/defaults.rb +60 -0
- data/lib/mongoid/config/options.rb +0 -3
- data/lib/mongoid/config/validators/async_query_executor.rb +24 -0
- data/lib/mongoid/config/validators.rb +1 -0
- data/lib/mongoid/config.rb +88 -27
- data/lib/mongoid/contextual/atomic.rb +1 -1
- data/lib/mongoid/contextual/memory.rb +233 -33
- data/lib/mongoid/contextual/mongo/documents_loader.rb +177 -0
- data/lib/mongoid/contextual/mongo.rb +370 -133
- data/lib/mongoid/contextual/none.rb +162 -7
- data/lib/mongoid/contextual.rb +12 -0
- data/lib/mongoid/criteria/findable.rb +2 -2
- data/lib/mongoid/criteria/includable.rb +4 -3
- data/lib/mongoid/criteria/queryable/extensions/numeric.rb +1 -15
- data/lib/mongoid/criteria/queryable/key.rb +1 -1
- data/lib/mongoid/criteria/queryable/mergeable.rb +1 -1
- data/lib/mongoid/criteria/queryable/optional.rb +8 -8
- data/lib/mongoid/criteria/queryable/selectable.rb +43 -12
- data/lib/mongoid/criteria/queryable/selector.rb +1 -1
- data/lib/mongoid/criteria/queryable/storable.rb +1 -1
- data/lib/mongoid/criteria.rb +6 -5
- data/lib/mongoid/deprecable.rb +1 -2
- data/lib/mongoid/deprecation.rb +3 -3
- data/lib/mongoid/document.rb +1 -8
- data/lib/mongoid/errors/create_collection_failure.rb +33 -0
- data/lib/mongoid/errors/drop_collection_failure.rb +27 -0
- data/lib/mongoid/errors/immutable_attribute.rb +26 -0
- data/lib/mongoid/errors/invalid_async_query_executor.rb +25 -0
- data/lib/mongoid/errors/invalid_global_executor_concurrency.rb +22 -0
- data/lib/mongoid/errors/invalid_storage_parent.rb +2 -0
- data/lib/mongoid/errors.rb +4 -1
- data/lib/mongoid/extensions/hash.rb +2 -24
- data/lib/mongoid/extensions/object.rb +2 -2
- data/lib/mongoid/extensions/time.rb +2 -0
- data/lib/mongoid/fields/localized.rb +10 -0
- data/lib/mongoid/fields/standard.rb +10 -0
- data/lib/mongoid/fields.rb +59 -35
- data/lib/mongoid/findable.rb +27 -3
- data/lib/mongoid/interceptable.rb +6 -116
- data/lib/mongoid/matcher/eq_impl.rb +1 -1
- data/lib/mongoid/matcher/type.rb +1 -1
- data/lib/mongoid/persistable/creatable.rb +1 -0
- data/lib/mongoid/persistable/deletable.rb +1 -1
- data/lib/mongoid/persistable/savable.rb +13 -1
- data/lib/mongoid/persistable/unsettable.rb +2 -2
- data/lib/mongoid/persistable/updatable.rb +51 -1
- data/lib/mongoid/persistable/upsertable.rb +20 -1
- data/lib/mongoid/persistable.rb +3 -0
- data/lib/mongoid/query_cache.rb +5 -1
- data/lib/mongoid/railties/database.rake +7 -2
- data/lib/mongoid/reloadable.rb +5 -3
- data/lib/mongoid/stateful.rb +22 -1
- data/lib/mongoid/tasks/database.rake +12 -0
- data/lib/mongoid/tasks/database.rb +20 -0
- data/lib/mongoid/timestamps/created.rb +1 -8
- data/lib/mongoid/traversable.rb +0 -12
- data/lib/mongoid/utils.rb +22 -0
- data/lib/mongoid/validatable/associated.rb +17 -98
- data/lib/mongoid/validatable/macros.rb +5 -20
- data/lib/mongoid/validatable.rb +4 -10
- data/lib/mongoid/version.rb +1 -5
- data/lib/mongoid/warnings.rb +17 -1
- data/lib/mongoid.rb +16 -3
- data/spec/integration/app_spec.rb +2 -12
- data/spec/integration/associations/embeds_one_spec.rb +5 -25
- data/spec/integration/associations/has_and_belongs_to_many_spec.rb +0 -40
- data/spec/integration/callbacks_spec.rb +99 -12
- data/spec/integration/discriminator_key_spec.rb +4 -5
- data/spec/integration/i18n_fallbacks_spec.rb +3 -2
- data/spec/mongoid/association/eager_spec.rb +2 -24
- data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +27 -0
- data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +20 -25
- data/spec/mongoid/association/embedded/embeds_many_models.rb +1 -0
- data/spec/mongoid/association/embedded/embeds_many_query_spec.rb +0 -4
- data/spec/mongoid/association/embedded/embeds_one/proxy_spec.rb +15 -2
- data/spec/mongoid/association/referenced/belongs_to_spec.rb +2 -18
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +42 -55
- data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +9 -50
- data/spec/mongoid/association/syncable_spec.rb +1 -1
- data/spec/mongoid/attributes_spec.rb +3 -33
- data/spec/mongoid/changeable_spec.rb +299 -24
- data/spec/mongoid/clients_spec.rb +122 -13
- data/spec/mongoid/collection_configurable_spec.rb +158 -0
- data/spec/mongoid/config/defaults_spec.rb +160 -0
- data/spec/mongoid/config_spec.rb +154 -27
- data/spec/mongoid/contextual/memory_spec.rb +332 -76
- data/spec/mongoid/contextual/mongo/documents_loader_spec.rb +187 -0
- data/spec/mongoid/contextual/mongo_spec.rb +1009 -125
- data/spec/mongoid/contextual/none_spec.rb +49 -2
- data/spec/mongoid/copyable_spec.rb +2 -10
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +4 -10
- data/spec/mongoid/criteria/queryable/options_spec.rb +1 -1
- data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +419 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +1 -1
- data/spec/mongoid/criteria/queryable/selector_spec.rb +3 -76
- data/spec/mongoid/criteria/queryable/storable_spec.rb +0 -72
- data/spec/mongoid/criteria_projection_spec.rb +1 -4
- data/spec/mongoid/criteria_spec.rb +5 -9
- data/spec/mongoid/document_spec.rb +0 -27
- data/spec/mongoid/errors/readonly_document_spec.rb +2 -2
- data/spec/mongoid/extensions/hash_spec.rb +3 -3
- data/spec/mongoid/extensions/time_spec.rb +8 -43
- data/spec/mongoid/extensions/time_with_zone_spec.rb +7 -52
- data/spec/mongoid/fields/localized_spec.rb +46 -28
- data/spec/mongoid/fields_spec.rb +136 -77
- data/spec/mongoid/findable_spec.rb +391 -34
- data/spec/mongoid/indexable_spec.rb +16 -10
- data/spec/mongoid/interceptable_spec.rb +153 -442
- data/spec/mongoid/interceptable_spec_models.rb +111 -51
- data/spec/mongoid/persistable/deletable_spec.rb +26 -6
- data/spec/mongoid/persistable/destroyable_spec.rb +26 -6
- data/spec/mongoid/persistable/incrementable_spec.rb +37 -0
- data/spec/mongoid/persistable/logical_spec.rb +37 -0
- data/spec/mongoid/persistable/poppable_spec.rb +36 -0
- data/spec/mongoid/persistable/pullable_spec.rb +72 -0
- data/spec/mongoid/persistable/pushable_spec.rb +72 -0
- data/spec/mongoid/persistable/renamable_spec.rb +36 -0
- data/spec/mongoid/persistable/savable_spec.rb +96 -0
- data/spec/mongoid/persistable/settable_spec.rb +37 -0
- data/spec/mongoid/persistable/unsettable_spec.rb +36 -0
- data/spec/mongoid/persistable/updatable_spec.rb +20 -28
- data/spec/mongoid/persistable/upsertable_spec.rb +80 -6
- data/spec/mongoid/persistence_context_spec.rb +7 -57
- data/spec/mongoid/query_cache_spec.rb +56 -61
- data/spec/mongoid/reloadable_spec.rb +24 -28
- data/spec/mongoid/scopable_spec.rb +70 -0
- data/spec/mongoid/serializable_spec.rb +23 -44
- data/spec/mongoid/stateful_spec.rb +122 -8
- data/spec/mongoid/tasks/database_rake_spec.rb +74 -0
- data/spec/mongoid/tasks/database_spec.rb +127 -0
- data/spec/mongoid/timestamps/created_spec.rb +0 -23
- data/spec/mongoid/timestamps_spec.rb +9 -11
- data/spec/mongoid/touchable_spec.rb +277 -5
- data/spec/mongoid/touchable_spec_models.rb +3 -1
- data/spec/mongoid/traversable_spec.rb +9 -24
- data/spec/mongoid/validatable/associated_spec.rb +34 -27
- data/spec/mongoid/validatable/numericality_spec.rb +0 -16
- data/spec/mongoid/validatable/uniqueness_spec.rb +2 -3
- data/spec/mongoid_spec.rb +36 -10
- data/spec/shared/lib/mrss/docker_runner.rb +1 -1
- data/spec/shared/lib/mrss/server_version_registry.rb +1 -1
- data/spec/shared/share/Dockerfile.erb +85 -15
- data/spec/shared/shlib/distro.sh +0 -10
- data/spec/shared/shlib/server.sh +26 -33
- data/spec/shared/shlib/set_env.sh +68 -9
- data/spec/spec_helper.rb +5 -0
- data/spec/support/expectations.rb +17 -20
- data/spec/support/immutable_ids.rb +118 -0
- data/spec/support/macros.rb +47 -15
- data/spec/support/models/artist.rb +0 -1
- data/spec/support/models/band.rb +1 -0
- data/spec/support/models/building.rb +2 -0
- data/spec/support/models/name.rb +0 -10
- data/spec/support/models/person.rb +0 -1
- data/spec/support/models/product.rb +1 -0
- data.tar.gz.sig +0 -0
- metadata +715 -660
- metadata.gz.sig +2 -0
- data/lib/mongoid/validatable/numericality.rb +0 -19
- data/spec/mongoid/criteria/queryable/extensions/bignum_spec.rb +0 -60
- data/spec/mongoid/criteria/queryable/extensions/fixnum_spec.rb +0 -60
- data/spec/shared/lib/mrss/release/candidate.rb +0 -281
- data/spec/shared/lib/mrss/release/product_data.rb +0 -144
- data/spec/shared/lib/tasks/candidate.rake +0 -64
- data/spec/support/models/purse.rb +0 -9
metadata.gz.sig
ADDED
@@ -0,0 +1,2 @@
|
|
1
|
+
W�5�8ZK�zg�����פ=�ղ"p��_NJ���Ga�*�ֳ�n�)�$��r��'ĒSl��� ����%����OD)ʍ�6�������l]�nc�=�[E�u�f�$F̌sBP�������h7�H�m�2^©��//}�[Ƶ=�.�����Y���ղ���m.��g���9��S�&e%6&��-s-Oƥ�@+V�ku���`o��!3ڗ����hY;Q;N���� �6�44��KgS9 �S9���G�U���S��+h6���(1\BvcԓT%��hUm.J��Z��d��x?���3Xm/fG8.�EP OX��
|
2
|
+
��q�i�=[�o�� !�b�8��#?EoT"�'YS0"u�A��>�1�K'���
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Mongoid
|
4
|
-
module Validatable
|
5
|
-
# A specialization of the ActiveModel numericality validator, which adds
|
6
|
-
# logic to recognize and accept BSON::Decimal128 as a number.
|
7
|
-
class NumericalityValidator < ActiveModel::Validations::NumericalityValidator
|
8
|
-
private
|
9
|
-
|
10
|
-
# Ensure that BSON::Decimal128 is treated as a BigDecimal during the
|
11
|
-
# validation step.
|
12
|
-
def prepare_value_for_validation(value, record, attr_name)
|
13
|
-
result = super
|
14
|
-
|
15
|
-
result.is_a?(BSON::Decimal128) ? result.to_big_decimal : result
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
describe Bignum do
|
6
|
-
|
7
|
-
describe ".evolve" do
|
8
|
-
|
9
|
-
context "when provided a string" do
|
10
|
-
|
11
|
-
context "when the string is a number" do
|
12
|
-
|
13
|
-
context "when the string is an bignum" do
|
14
|
-
|
15
|
-
it "returns an bignum" do
|
16
|
-
expect(described_class.evolve("1")).to eq(1)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context "when the string is a float" do
|
21
|
-
|
22
|
-
it "converts it to a float" do
|
23
|
-
expect(described_class.evolve("2.23")).to eq(2.23)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context "when the string is not a number" do
|
29
|
-
|
30
|
-
it "returns the string" do
|
31
|
-
expect(described_class.evolve("testing")).to eq("testing")
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context "when provided a number" do
|
38
|
-
|
39
|
-
context "when the number is an bignum" do
|
40
|
-
|
41
|
-
it "returns an bignum" do
|
42
|
-
expect(described_class.evolve(1)).to eq(1)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context "when the number is a float" do
|
47
|
-
|
48
|
-
it "returns the float" do
|
49
|
-
expect(described_class.evolve(2.23)).to eq(2.23)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
context "when provided nil" do
|
55
|
-
|
56
|
-
it "returns nil" do
|
57
|
-
expect(described_class.evolve(nil)).to be_nil
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
describe Fixnum do
|
6
|
-
|
7
|
-
describe ".evolve" do
|
8
|
-
|
9
|
-
context "when provided a string" do
|
10
|
-
|
11
|
-
context "when the string is a number" do
|
12
|
-
|
13
|
-
context "when the string is an fixnum" do
|
14
|
-
|
15
|
-
it "returns an fixnum" do
|
16
|
-
expect(described_class.evolve("1")).to eq(1)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context "when the string is a float" do
|
21
|
-
|
22
|
-
it "converts it to a float" do
|
23
|
-
expect(described_class.evolve("2.23")).to eq(2.23)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context "when the string is not a number" do
|
29
|
-
|
30
|
-
it "returns the string" do
|
31
|
-
expect(described_class.evolve("testing")).to eq("testing")
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context "when provided a number" do
|
38
|
-
|
39
|
-
context "when the number is an fixnum" do
|
40
|
-
|
41
|
-
it "returns an fixnum" do
|
42
|
-
expect(described_class.evolve(1)).to eq(1)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context "when the number is a float" do
|
47
|
-
|
48
|
-
it "returns the float" do
|
49
|
-
expect(described_class.evolve(2.23)).to eq(2.23)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
context "when provided nil" do
|
55
|
-
|
56
|
-
it "returns nil" do
|
57
|
-
expect(described_class.evolve(nil)).to be_nil
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
@@ -1,281 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'json'
|
4
|
-
|
5
|
-
require_relative 'product_data'
|
6
|
-
|
7
|
-
module Mrss
|
8
|
-
module Release
|
9
|
-
class Candidate
|
10
|
-
# Release note section titles, by pr type
|
11
|
-
SECTION_TITLE = {
|
12
|
-
bcbreak: "Breaking Changes",
|
13
|
-
feature: "New Features",
|
14
|
-
bug: "Bug Fixes",
|
15
|
-
}.freeze
|
16
|
-
|
17
|
-
# GitHub labels
|
18
|
-
BCBREAK = 'bcbreak'
|
19
|
-
FEATURE = 'feature'
|
20
|
-
BUG = 'bug'
|
21
|
-
PATCH = 'patch'
|
22
|
-
|
23
|
-
def self.instance
|
24
|
-
@instance ||= new
|
25
|
-
|
26
|
-
yield @instance if block_given?
|
27
|
-
|
28
|
-
@instance
|
29
|
-
end
|
30
|
-
|
31
|
-
def product
|
32
|
-
@product ||= ProductData.new
|
33
|
-
end
|
34
|
-
|
35
|
-
def bump_version
|
36
|
-
product.bump_version(release_type)
|
37
|
-
end
|
38
|
-
|
39
|
-
def bump_version!
|
40
|
-
product.bump_version!(release_type)
|
41
|
-
end
|
42
|
-
|
43
|
-
def branch_name
|
44
|
-
@branch_name ||= "rc-#{product.version}"
|
45
|
-
end
|
46
|
-
|
47
|
-
# return a string of commit names since the last release
|
48
|
-
def pending_changes
|
49
|
-
@changes ||= begin
|
50
|
-
range = product.tag_exists? ? "#{product.tag_name}.." : ""
|
51
|
-
`git log --pretty=format:"%s" #{range}`
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
# return a list of PR numbers since the last release
|
56
|
-
def pending_pr_numbers
|
57
|
-
@pending_pr_numbers ||= pending_changes.
|
58
|
-
lines.
|
59
|
-
map { |line| line.match(/\(#(\d+)\)$/).then { |m| m && m[1] } }.
|
60
|
-
compact.
|
61
|
-
sort.reverse
|
62
|
-
end
|
63
|
-
|
64
|
-
# return a JSON string of PR data
|
65
|
-
def pending_pr_dump
|
66
|
-
@pending_pr_dump ||= `gh pr list --state all --limit 256 --json number,title,labels,url,body --jq 'map(select([.number] | inside([#{pending_pr_numbers.join(',')}]))) | sort_by(.number)'`
|
67
|
-
end
|
68
|
-
|
69
|
-
# return a list of PR data since the last release
|
70
|
-
def pending_prs
|
71
|
-
@pending_prs ||= JSON.parse(pending_pr_dump)
|
72
|
-
end
|
73
|
-
|
74
|
-
# return a list of pending prs with additional attributes (summary,
|
75
|
-
# short title, jira issue number).
|
76
|
-
def decorated_prs
|
77
|
-
@decorated_prs ||= pending_prs.map do |pr|
|
78
|
-
jira_issue, pr_title = split_pr_title(pr)
|
79
|
-
summary = extract_summary(pr)
|
80
|
-
type = pr_type(pr)
|
81
|
-
type_code = pr_type_code(type)
|
82
|
-
patch_flag = pr_patch_flag?(pr)
|
83
|
-
|
84
|
-
pr.merge('jira' => jira_issue,
|
85
|
-
'short-title' => pr_title,
|
86
|
-
'summary' => summary,
|
87
|
-
'type' => type,
|
88
|
-
'type-code' => type_code,
|
89
|
-
'patch' => patch_flag)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
# return a hash of decorated prs grouped by :bcbreak, :feature, or :bug
|
94
|
-
def prs_by_type
|
95
|
-
@prs_by_type ||= decorated_prs.group_by { |pr| pr['type'] }
|
96
|
-
end
|
97
|
-
|
98
|
-
# returns 'major', 'minor', or 'patch', depending on the presence of
|
99
|
-
# (respectively) :bcbreak, :feature, or :bug labels.
|
100
|
-
#
|
101
|
-
# If the RELEASE environment variable is set, its value will be used
|
102
|
-
# directly, ignoring whatever PR labels might exist.
|
103
|
-
def release_type
|
104
|
-
@release_type ||= if ENV['RELEASE']
|
105
|
-
ENV['RELEASE']
|
106
|
-
elsif prs_by_type[:bcbreak]
|
107
|
-
'major'
|
108
|
-
elsif prs_by_type[:feature] && prs_by_type[:feature].any? { |pr| !pr['patch'] }
|
109
|
-
'minor'
|
110
|
-
else
|
111
|
-
'patch'
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
# returns the generated release notes as a string
|
116
|
-
def release_notes
|
117
|
-
@release_notes ||= release_notes_intro +
|
118
|
-
%i[ bcbreak feature bug ].
|
119
|
-
flat_map { |type| release_notes_for_type(type) }.join("\n")
|
120
|
-
end
|
121
|
-
|
122
|
-
private
|
123
|
-
|
124
|
-
# returns an array of strings, each string representing a single line
|
125
|
-
# in the release notes for the PR's of the given type.
|
126
|
-
def release_notes_for_type(type)
|
127
|
-
return [] unless prs_by_type[type]
|
128
|
-
|
129
|
-
[].tap do |lines|
|
130
|
-
lines << "\# #{SECTION_TITLE[type]}"
|
131
|
-
lines << ''
|
132
|
-
|
133
|
-
prs = prs_by_type[type]
|
134
|
-
summarized, unsummarized = prs.partition { |pr| pr['summary'] }
|
135
|
-
|
136
|
-
summarized.each do |pr|
|
137
|
-
header = [ '### ' ]
|
138
|
-
header << "[#{pr['jira']}](#{jira_url(pr['jira'])}) " if pr['jira']
|
139
|
-
header << "#{pr['short-title']} ([PR](#{pr['url']}))"
|
140
|
-
lines << header.join
|
141
|
-
lines << ''
|
142
|
-
lines << pr['summary']
|
143
|
-
lines << ''
|
144
|
-
end
|
145
|
-
|
146
|
-
if summarized.any? && unsummarized.any?
|
147
|
-
lines << ''
|
148
|
-
lines << [ '### Other ', SECTION_TITLE[type] ].join
|
149
|
-
lines << ''
|
150
|
-
end
|
151
|
-
|
152
|
-
unsummarized.each do |pr|
|
153
|
-
line = [ '* ' ]
|
154
|
-
line << "[#{pr['jira']}](#{jira_url(pr['jira'])}) " if pr['jira']
|
155
|
-
line << "#{pr['short-title']} ([PR](#{pr['url']}))"
|
156
|
-
|
157
|
-
lines << line.join
|
158
|
-
end
|
159
|
-
|
160
|
-
lines << ''
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
# returns the URL of for the given jira issue
|
165
|
-
def jira_url(issue)
|
166
|
-
"https://jira.mongodb.org/browse/#{issue}"
|
167
|
-
end
|
168
|
-
|
169
|
-
# assumes a pr title in the format of "JIRA-1234 PR Title (#1234)",
|
170
|
-
# returns a tuple of [ jira-issue, title ], where jira-issue may be
|
171
|
-
# blank (if no jira issue is in the title).
|
172
|
-
def split_pr_title(pr)
|
173
|
-
title = pr['title'].gsub(/\(#\d+\)/, '').strip
|
174
|
-
|
175
|
-
if title =~ /^(\w+-\d+) (.*)$/
|
176
|
-
[ $1, $2 ]
|
177
|
-
else
|
178
|
-
[ nil, title ]
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
# extracts the summary section from the pr and returns it (or returns nil
|
183
|
-
# if no summary section is detected)
|
184
|
-
def extract_summary(pr)
|
185
|
-
summary = []
|
186
|
-
accumulating = false
|
187
|
-
level = nil
|
188
|
-
|
189
|
-
pr['body'].lines.each do |line|
|
190
|
-
# a header of any level titled "summary" will begin the summary
|
191
|
-
if !accumulating && line =~ /^(\#+)\s+summary\s+$/i
|
192
|
-
accumulating = true
|
193
|
-
level = $1.length
|
194
|
-
|
195
|
-
# a header of any level less than or equal to the summary header's
|
196
|
-
# level will end the summary
|
197
|
-
elsif accumulating && line =~ /^\#{1,#{level}}\s+/
|
198
|
-
break
|
199
|
-
|
200
|
-
# otherwise, the line is part of the summary
|
201
|
-
elsif accumulating
|
202
|
-
summary << line
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
summary.any? ? summary.join.strip : nil
|
207
|
-
end
|
208
|
-
|
209
|
-
# Returns a symbol (:bcbreak, :feature, or :bug) that identifies the
|
210
|
-
# type of this PR that would most strongly influence what type of release
|
211
|
-
# it requires.
|
212
|
-
def pr_type(pr)
|
213
|
-
if pr['labels'].any? { |l| l['name'] == BCBREAK }
|
214
|
-
:bcbreak
|
215
|
-
elsif pr['labels'].any? { |l| l['name'] == FEATURE }
|
216
|
-
:feature
|
217
|
-
elsif pr['labels'].any? { |l| l['name'] == BUG }
|
218
|
-
:bug
|
219
|
-
else
|
220
|
-
nil
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
# `true` if the `patch` label is applied to the PR. This is used to
|
225
|
-
# indicate that a "feature" PR should be treated as a patch, for
|
226
|
-
# determining the release type only.
|
227
|
-
def pr_patch_flag?(pr)
|
228
|
-
pr['labels'].any? { |l| l['name'] == PATCH }
|
229
|
-
end
|
230
|
-
|
231
|
-
def pr_type_code(type)
|
232
|
-
case type
|
233
|
-
when :bcbreak then 'x'
|
234
|
-
when :feature then 'f'
|
235
|
-
when :bug then 'b'
|
236
|
-
else '?'
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
def series
|
241
|
-
major, minor, = product.version_parts
|
242
|
-
|
243
|
-
case release_type
|
244
|
-
when 'minor' then
|
245
|
-
"#{major}.x"
|
246
|
-
when 'patch' then
|
247
|
-
"#{major}.#{minor}.x"
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
|
-
# Return a string containing the markdown-formatted intro block for
|
252
|
-
# the release notes of this candidate.
|
253
|
-
def release_notes_intro
|
254
|
-
release_description = case release_type
|
255
|
-
when 'major' then 'major release'
|
256
|
-
when 'minor' then "minor release in the #{series} series"
|
257
|
-
when 'patch' then "patch release in the #{series} series"
|
258
|
-
end
|
259
|
-
|
260
|
-
<<~INTRO
|
261
|
-
The MongoDB Ruby team is pleased to announce version #{product.version} of the `#{product.package}` gem - #{product.description}. This is a new #{release_description} of #{product.name}.
|
262
|
-
|
263
|
-
Install this release using [RubyGems](https://rubygems.org/) via the command line as follows:
|
264
|
-
|
265
|
-
~~~
|
266
|
-
gem install -v #{product.version} #{product.package}
|
267
|
-
~~~
|
268
|
-
|
269
|
-
Or simply add it to your `Gemfile`:
|
270
|
-
|
271
|
-
~~~
|
272
|
-
gem '#{product.package}', '#{product.version}'
|
273
|
-
~~~
|
274
|
-
|
275
|
-
Have any feedback? Click on through to MongoDB's JIRA and [open a new ticket](#{product.jira_project_url}) to let us know what's on your mind 🧠.
|
276
|
-
|
277
|
-
INTRO
|
278
|
-
end
|
279
|
-
end
|
280
|
-
end
|
281
|
-
end
|
@@ -1,144 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'yaml'
|
4
|
-
|
5
|
-
module Mrss
|
6
|
-
module Release
|
7
|
-
class ProductData
|
8
|
-
FILE_PATH = 'product.yml'
|
9
|
-
|
10
|
-
def self.init!
|
11
|
-
if File.exist?(FILE_PATH)
|
12
|
-
raise "#{FILE_PATH} already exists; refusing to overwrite it"
|
13
|
-
end
|
14
|
-
|
15
|
-
initial_data = {
|
16
|
-
'name' => 'Product Name',
|
17
|
-
'description' => 'a very short description of the product',
|
18
|
-
'package' => 'product_package',
|
19
|
-
'jira' => 'https://url.to.jira/project',
|
20
|
-
'version' => { 'number' => '1.0.0',
|
21
|
-
'file' => 'path/to/version.rb' }
|
22
|
-
}
|
23
|
-
|
24
|
-
File.write(FILE_PATH, initial_data.to_yaml)
|
25
|
-
end
|
26
|
-
|
27
|
-
def initialize
|
28
|
-
@hash = YAML.load_file(FILE_PATH)
|
29
|
-
end
|
30
|
-
|
31
|
-
def save_product_file!
|
32
|
-
File.write(FILE_PATH, @hash.to_yaml)
|
33
|
-
end
|
34
|
-
|
35
|
-
def rewrite_version_file!
|
36
|
-
version_module = File.read(version_file)
|
37
|
-
new_module = version_module.
|
38
|
-
sub(/^(\s*)(VERSION\s*=\s*).*$/) { "#{$1}#{$2}#{quoted_version}" }
|
39
|
-
File.write(version_file, new_module)
|
40
|
-
end
|
41
|
-
|
42
|
-
def version
|
43
|
-
@hash['version']['number']
|
44
|
-
end
|
45
|
-
|
46
|
-
def quoted_version
|
47
|
-
if version.include?("'")
|
48
|
-
version.inspect
|
49
|
-
else
|
50
|
-
"'#{version}'"
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def version=(number)
|
55
|
-
@hash['version']['number'] = number
|
56
|
-
end
|
57
|
-
|
58
|
-
# returns an array of [ major, minor, patch, suffix ].
|
59
|
-
#
|
60
|
-
# each element will be returned as a String.
|
61
|
-
def version_parts
|
62
|
-
version.split(/\./, 4)
|
63
|
-
end
|
64
|
-
|
65
|
-
# bump the version according to the given release type:
|
66
|
-
#
|
67
|
-
# 'major' -> increment major component, zero the others
|
68
|
-
# 'minor' -> increment minor component, zero the patch
|
69
|
-
# 'patch' -> increment the patch component
|
70
|
-
def bump_version(release)
|
71
|
-
major, minor, patch, suffix = version_parts
|
72
|
-
|
73
|
-
case release
|
74
|
-
when 'major' then
|
75
|
-
major = major.to_i + 1
|
76
|
-
minor = patch = 0
|
77
|
-
when 'minor'
|
78
|
-
minor = minor.to_i + 1
|
79
|
-
patch = 0
|
80
|
-
when 'patch'
|
81
|
-
patch = patch.to_i + 1
|
82
|
-
else
|
83
|
-
raise ArgumentError, "invalid release type: #{release.inspect}"
|
84
|
-
end
|
85
|
-
|
86
|
-
self.version = [ major, minor, patch ].join('.')
|
87
|
-
end
|
88
|
-
|
89
|
-
# Invokes `#bump_version`, and then saves the new version to the
|
90
|
-
# product.yml file and to the version.rb file.
|
91
|
-
def bump_version!(release)
|
92
|
-
bump_version(release)
|
93
|
-
save_product_file!
|
94
|
-
rewrite_version_file!
|
95
|
-
end
|
96
|
-
|
97
|
-
def version_file
|
98
|
-
@hash['version']['file']
|
99
|
-
end
|
100
|
-
|
101
|
-
def name
|
102
|
-
@hash['name']
|
103
|
-
end
|
104
|
-
|
105
|
-
# The description is intended to be used in places where it can be
|
106
|
-
# appended to the end of a sentence, e.g.
|
107
|
-
#
|
108
|
-
# "We just released #{product.name} - #{product.description}!"
|
109
|
-
#
|
110
|
-
# Markdown formatting is allowed (even expected).
|
111
|
-
def description
|
112
|
-
@hash['description']
|
113
|
-
end
|
114
|
-
|
115
|
-
def package
|
116
|
-
@hash['package']
|
117
|
-
end
|
118
|
-
|
119
|
-
def jira_project_url
|
120
|
-
@hash['jira']
|
121
|
-
end
|
122
|
-
|
123
|
-
def tag_name
|
124
|
-
"v#{version}"
|
125
|
-
end
|
126
|
-
|
127
|
-
def tag_exists?(tag = tag_name)
|
128
|
-
`git tag -l #{tag}`.strip == tag
|
129
|
-
end
|
130
|
-
|
131
|
-
def branch_exists?(branch)
|
132
|
-
`git branch -l #{branch}`.strip == branch
|
133
|
-
end
|
134
|
-
|
135
|
-
def base_branch
|
136
|
-
@base_branch ||= begin
|
137
|
-
major, minor, = version_parts
|
138
|
-
branch = "#{major}.#{minor}-stable"
|
139
|
-
branch_exists?(branch) ? branch : 'master'
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
@@ -1,64 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../mrss/release/candidate'
|
4
|
-
|
5
|
-
namespace :candidate do
|
6
|
-
desc 'Initialize a new product.yml file'
|
7
|
-
task :init do
|
8
|
-
Mrss::Release::ProductData.init!
|
9
|
-
puts "product.yml file created"
|
10
|
-
end
|
11
|
-
|
12
|
-
desc 'Print the release notes for the next candidate release'
|
13
|
-
task :preview do
|
14
|
-
Mrss::Release::Candidate.instance do |candidate|
|
15
|
-
# load the pending changes before bumping the version, since it
|
16
|
-
# depends on the value of the current version.
|
17
|
-
candidate.pending_changes
|
18
|
-
candidate.bump_version
|
19
|
-
puts candidate.release_notes
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
desc 'List the pull requests to be included in the next release'
|
24
|
-
task :prs do
|
25
|
-
Mrss::Release::Candidate.instance.decorated_prs.each do |pr|
|
26
|
-
print "\##{pr['number']}[#{pr['type-code']}] "
|
27
|
-
print "#{pr['jira']} " if pr['jira']
|
28
|
-
puts pr['short-title']
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
desc 'Create a new branch and pull request for the candidate'
|
33
|
-
task create: :check_branch_status do
|
34
|
-
Mrss::Release::Candidate.instance do |candidate|
|
35
|
-
origin = `git config get remote.origin.url`
|
36
|
-
match = origin.match(/:(.*?)\//) or raise "origin url is not in expected format: #{origin.inspect}"
|
37
|
-
user = match[1]
|
38
|
-
|
39
|
-
puts 'gathering candidate info and bumping version...'
|
40
|
-
candidate.bump_version!
|
41
|
-
|
42
|
-
puts 'writing release notes to /tmp/pr-body.md...'
|
43
|
-
File.write('/tmp/pr-body.md', candidate.release_notes)
|
44
|
-
|
45
|
-
sh 'git', 'checkout', '-b', candidate.branch_name
|
46
|
-
sh 'git', 'commit', '-am', "Bump version to #{candidate.product.version}"
|
47
|
-
sh 'git', 'push', 'origin', candidate.branch_name
|
48
|
-
|
49
|
-
sh 'gh', 'pr', 'create',
|
50
|
-
'--head', "#{user}:#{candidate.branch_name}",
|
51
|
-
'--base', candidate.product.base_branch,
|
52
|
-
'--title', "Release candidate for #{candidate.product.version}",
|
53
|
-
'--label', 'release-candidate',
|
54
|
-
'--body-file', '/tmp/pr-body.md'
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
# Ensures the current branch is up-to-date with no uncommitted changes
|
59
|
-
task :check_branch_status do
|
60
|
-
sh 'git pull >/dev/null', verbose: false
|
61
|
-
changes = `git status --short --untracked-files=no`.strip
|
62
|
-
abort "There are uncommitted changes. Commit (or revert) the changes and try again." if changes.length > 0
|
63
|
-
end
|
64
|
-
end
|