upfluence-utils 0.11.0 → 0.11.1

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: 4b2b841f2316f1af620920943ae85e2e885ae8dcfeb78b262dd4499d56166087
4
- data.tar.gz: 54d9bcce6108662e99d265529874d7e81150a995a461e4a35f01be26eafb8cf0
3
+ metadata.gz: 34482caf62162c18d2dd1baccb5a6779d6842ada6fe2bd9ea93cb59f4a5dd023
4
+ data.tar.gz: 11d5ee4d37890bce173e6504c68717eb84b02b83e08dc7b49922876cea8b1be1
5
5
  SHA512:
6
- metadata.gz: 5b4b2f1319518137e8b7eee871902a2083d29e1d30e3978bf07a4a6faa2401caa5c7c3098c1d15e185a94fc2f6071d21360ac676deed27b0cb3c06760b5f99eb
7
- data.tar.gz: 3bc0090d731535354f87b1d432c8794b3b092ef7390d41ccbb195e23e20d7e6e43029aa3f539e14e7b40e66ba7e69eeb1541e55767ae5f5145e89da949c6e269
6
+ metadata.gz: 5783891f47a807fb2e330666f95e613959551c35f515988b3c565a9cb29f81b720adcb2bc2f80e1657e90d789d244546bcb05fb9157d1f17f85e94aab054c377
7
+ data.tar.gz: 6cc44d846140cbc7b5066d778ebce30944532c9b3e082ccbbb433741cc5ccacd945a5263fa29c94acb6a47f90a58e8a052888b9a7d6f7cfce7c9c6a69bc8fd97
@@ -1,28 +1,126 @@
1
+ require 'cgi'
2
+
1
3
  module Upfluence
2
4
  class Peer
5
+ class Version
6
+ class SemanticVersion
7
+ attr_reader :major, :minor, :patch, :suffix
8
+
9
+ def initialize(major:, minor:, patch:, suffix: nil)
10
+ @major = major
11
+ @minor = minor
12
+ @patch = patch
13
+ @suffix = suffix
14
+ end
15
+
16
+ def to_s
17
+ v = "v#{@major}.#{@minor}.#{@patch}"
18
+
19
+ v += "-#{@suffix}" if @suffix
20
+ v
21
+ end
22
+
23
+ class << self
24
+ def parse(version)
25
+ return nil unless version
26
+
27
+ v, suffix = version.split('-', 2)
28
+
29
+ vs = v.split('.')
30
+
31
+ return nil unless vs.count.eql? 3
32
+
33
+ SemanticVersion.new(
34
+ major: vs[0].delete_prefix('v').to_i,
35
+ minor: vs[1].to_i,
36
+ patch: vs[2].to_i,
37
+ suffix: suffix
38
+ )
39
+ end
40
+ end
41
+ end
42
+
43
+ class GitVersion
44
+ attr_reader :commit, :remote, :branch
45
+
46
+ def initialize(commit:, remote: nil, branch: nil)
47
+ @commit = commit
48
+ @remote = remote
49
+ @branch = branch
50
+ end
51
+
52
+ def to_s
53
+ "v0.0.0+git-#{@commit[0..6]}"
54
+ end
55
+ end
56
+
57
+ DEFAULT_VERSION = 'v0.0.0-dirty'.freeze
58
+
59
+ attr_reader :git, :semantic
60
+
61
+ def initialize(git, semantic)
62
+ @git = git
63
+ @semantic = semantic
64
+ end
65
+
66
+ def to_s
67
+ return @semantic.to_s if @semantic
68
+ return @git.to_s if @git
69
+
70
+ DEFAULT_VERSION
71
+ end
72
+ end
73
+
3
74
  attr_reader :environment, :authority, :instance_name, :project_name,
4
75
  :app_name
5
76
 
6
- def initialize(opts = {})
7
- @authority = opts[:authority] || 'local'
8
- @instance_name = opts[:instance_name] || 'unknown-server'
9
- @app_name = opts[:app_name] || 'unknown-name'
10
- @project_name = opts[:project_name] || 'unknown-app'
11
- @environment = opts[:environment] || 'development'
77
+ def initialize(authority:, instance_name:, app_name:, project_name:,
78
+ environment:, version: nil)
79
+ @authority = authority || 'local'
80
+ @instance_name = instance_name || 'unknown-server'
81
+ @app_name = app_name || 'unknown-app'
82
+ @project_name = project_name || 'unknown-app'
83
+ @environment = environment || 'development'
84
+ @version = version
12
85
  end
13
86
 
14
87
  def to_url
15
- "peer://#{@environment}@#{@authority}/#{@instance_name}"
88
+ query = {
89
+ 'app-name' => @app_name,
90
+ 'project-name' => @project_name,
91
+ 'git-version' => @version.git&.commit,
92
+ 'semantic-version' => @version.semantic&.to_s
93
+ }.compact.map { |k, v| "#{k}=#{CGI.escape(v)}" }.join('&')
94
+
95
+ "peer://#{@environment}@#{@authority}/#{@instance_name}?#{query}"
16
96
  end
17
97
 
18
98
  class << self
19
99
  def from_env
20
100
  Peer.new(
21
101
  authority: ENV['AUTHORITY'],
22
- instance_name: ENV['INSTANCE_NAME'],
102
+ instance_name: ENV['UNIT_NAME'],
23
103
  app_name: ENV['APP_NAME'],
24
104
  project_name: ENV['PROJECT_NAME'],
25
- environment: ENV['ENV']
105
+ environment: ENV['ENV'],
106
+ version: Version.new(
107
+ build_git_version,
108
+ Version::SemanticVersion.parse(ENV['VERSION'])
109
+ )
110
+ )
111
+ end
112
+
113
+ private
114
+
115
+ def build_git_version
116
+ commit = ENV['GIT_COMMIT']
117
+
118
+ return nil unless commit
119
+
120
+ Version::GitVersion.new(
121
+ commit: commit,
122
+ remote: ENV['GIT_REMOTE'],
123
+ branch: ENV['GIT_BRANCH']
26
124
  )
27
125
  end
28
126
  end
@@ -1,5 +1,5 @@
1
1
  module Upfluence
2
2
  module Utils
3
- VERSION = '0.11.0'.freeze
3
+ VERSION = '0.11.1'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: upfluence-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Upfluence
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-21 00:00:00.000000000 Z
11
+ date: 2022-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -234,7 +234,7 @@ dependencies:
234
234
  - - ">="
235
235
  - !ruby/object:Gem::Version
236
236
  version: '0'
237
- description:
237
+ description:
238
238
  email:
239
239
  - dev@upfluence.com
240
240
  executables: []
@@ -292,7 +292,7 @@ homepage: https://github.com/upfluence/rbutils
292
292
  licenses:
293
293
  - MIT
294
294
  metadata: {}
295
- post_install_message:
295
+ post_install_message:
296
296
  rdoc_options: []
297
297
  require_paths:
298
298
  - lib
@@ -307,8 +307,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
307
307
  - !ruby/object:Gem::Version
308
308
  version: '0'
309
309
  requirements: []
310
- rubygems_version: 3.1.4
311
- signing_key:
310
+ rubygems_version: 3.2.32
311
+ signing_key:
312
312
  specification_version: 4
313
313
  summary: Upfluence common utils for Ruby projects
314
314
  test_files: []