apadmi_grout 2.6.0 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: af094b716e2764d75b2f0729c40c82e2bb2ffe13f2775a2e2d6480540c471922
4
- data.tar.gz: 7ab7d36c4e120a348ee74e2e67386fd1f497d40c5bb684951777edef79caf5c8
3
+ metadata.gz: c359c320e340ceb70fd0b212f657bb858958fa8fb5ef6037dca5891fc50a90f6
4
+ data.tar.gz: f4d9eaf0b6fec2ede3829844314fbafc25c4f2a378185e4656f562f58e08b09f
5
5
  SHA512:
6
- metadata.gz: 586a0f1eaf5d0ca433ad18a9c09965da229459bd172a217e04d1ee74a82cfc349cd7841093b40b29f8762bbf37310f3a0a423731bfd1ded2e55697f32663c0a5
7
- data.tar.gz: f77fb691459927030db6f936f5768aa69fd72b5906c23f044bc8e885a6a7084a9bd20c723a5736008a0f42800d955ffd935e8200200bb8ea9c6ec882bcd92e2f
6
+ metadata.gz: 669edb4b69e604ba1a4cde88bb8b46bf073c26765dcb3f819dc55f2fcc118008fde3bfac3e0c343e85a338fcbdeda2f1f57246c2db065565921f40e209dcaf3e
7
+ data.tar.gz: 81eef18800723d403d6ecf016b87486253d06b4b1f15725189752afea71a6dce4dd7b79d62a945a5382f3486be3709089b9d04c6608c9df2632059d36e31b958
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Core Changelog
2
2
 
3
+ ## [2.7.0] - 2024-09-24
4
+ * Add utility for checking for unmerged release branches before deployments
5
+
6
+ ## [2.6.1] - 2024-01-09
7
+ * Fix: missing blank? method because ActiveSupport requires you to load the extensions explicitly from 7.1
8
+
3
9
  ## [2.6.0] - 2023-09-20
4
10
  * Add option to expand ADO tickets with additional information
5
11
  * Add ability to assign users to ADO tickets
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "semantic" # We'll use this gem for semantic versioning comparison
4
+
5
+ module Apadmi
6
+ module Grout
7
+ # Checks that all releases before this one are ancestors in the commit
8
+ # history to ensure that any unmerged fixes don't get missed
9
+ class CheckUnfinishedReleasesAction
10
+ # @param [Apadmi::Grout::GitUtils]
11
+ # @param [Apadmi::Grout::DefaultLogger] // or your own logger!
12
+ def initialize(git_utils, logger)
13
+ @git_utils = git_utils
14
+ @logger = logger
15
+ end
16
+
17
+ # Runs the action.
18
+ # @param current_version [String] The version of this release.
19
+ # @param suppress_error_versions [Array<String>] Errors from unmerged versions in this list will be suppressed
20
+ def run(current_version, suppress_error_versions)
21
+ @git_utils.fetch_all
22
+
23
+ @logger.message("Checking for unmerged versions")
24
+ @logger.message("Suppressing checks for versions: #{suppress_error_versions}") if suppress_error_versions
25
+ this_version = Semantic::Version.new current_version
26
+ versions = extract_non_ancestor_versions
27
+ suppressed = suppress_error_versions.map do |version|
28
+ Semantic::Version.new version
29
+ end
30
+
31
+ # Only older versions should cause errors since features in newer
32
+ # versions have legitimate reasons not to be in this release
33
+ versions.select do |version|
34
+ version < this_version && !suppressed.include?(version)
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def extract_non_ancestor_versions
41
+ refs = @git_utils.list_tags(
42
+ "--no-merged"
43
+ ) + @git_utils.branch(
44
+ " --list '*release*' '*hotfix*' --all --no-merged"
45
+ ).split("\n")
46
+
47
+ version_strings = refs.map do |ref|
48
+ match = ref.match(/.*(\d+\.\d+\.\d.*)/)
49
+ match[1] if match
50
+ end.compact
51
+ @logger.message("Found versions to compare #{version_strings}")
52
+ version_strings.map do |version_string|
53
+ Semantic::Version.new version_string
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -27,7 +27,7 @@ module Apadmi
27
27
  )
28
28
  network_service = Apadmi::Grout::NetworkService.init_for_basic_auth(username, token, base_url)
29
29
  jira_board_service = Apadmi::Grout::JiraBoardService.new(username, token, base_url, context_path, project, network_service)
30
- git_utils = Apadmi::Grout::GitUtils
30
+ git_utils = Apadmi::Grout::GitUtils.new
31
31
  issues_from_changelog_action = Apadmi::Grout::IssuesFromChangelogAction.new(jira_board_service, "#{project}-", logger)
32
32
 
33
33
  DependencyInjector.new(
@@ -53,7 +53,7 @@ module Apadmi
53
53
  ticket_prefix = "#"
54
54
  network_service = Apadmi::Grout::NetworkService.init_for_basic_auth("", personal_access_token, base_url)
55
55
  ado_board_service = Apadmi::Grout::AdoBoardService.new(network_service, ado_config, logger)
56
- git_utils = Apadmi::Grout::GitUtils
56
+ git_utils = Apadmi::Grout::GitUtils.new
57
57
  issues_from_changelog_action = Apadmi::Grout::IssuesFromChangelogAction.new(ado_board_service, ticket_prefix, logger)
58
58
 
59
59
  DependencyInjector.new(
@@ -10,7 +10,7 @@ module Apadmi
10
10
 
11
11
  BitriseBuild = Struct.new(:triggered_at, :slug, :status, :commit_hash) do
12
12
  def finished_with_success
13
- STATUS_SUCCESS == status
13
+ status == STATUS_SUCCESS
14
14
  end
15
15
  end
16
16
 
@@ -18,7 +18,7 @@ module Apadmi
18
18
 
19
19
  TriggeredBitriseBuild = Struct.new(:build_number, :build_slug, :build_url, :message, :service, :slug, :status, :triggered_workflow) do
20
20
  def finished_with_success
21
- STATUS_SUCCESS == status
21
+ status == STATUS_SUCCESS
22
22
  end
23
23
 
24
24
  def self.from_json(json)
@@ -6,60 +6,129 @@ module Apadmi
6
6
  module Grout
7
7
  # Generic Git related utils
8
8
  class GitUtils
9
+ def initialize(repo_path = nil)
10
+ @repo_path_arg = repo_path.nil? ? "" : " -C #{repo_path} "
11
+ end
12
+
13
+ # rubocop:disable Style/ClassVars:
14
+ @@default = Apadmi::Grout::GitUtils.new(nil)
15
+ # rubocop:enable Style/ClassVars:
16
+
9
17
  # Gets the root of the Git repo we're in
10
18
  # @return [String] The full path for the root of this Git repo
11
- def self.git_root
12
- stdout, stderr, status = Open3.capture3("git rev-parse --show-toplevel")
19
+ def git_root
20
+ stdout, stderr, status = Open3.capture3("git #{@repo_path_arg} rev-parse --show-toplevel")
13
21
  raise "Failed to get git root: #{stderr}" unless status.success?
14
22
 
15
23
  stdout.strip
16
24
  end
17
25
 
26
+ def self.git_root
27
+ @@default.git_root
28
+ end
29
+
30
+ # Returns all the tags in the repo
31
+ # @return [String[]] The tags
32
+ def list_tags(args = "")
33
+ stdout, stderr, status = Open3.capture3("git #{@repo_path_arg} tag --list #{args}")
34
+ raise "Failed to list tags: #{stderr}" unless status.success?
35
+
36
+ stdout.strip.split("\n")
37
+ end
38
+
39
+ # Returns all the tags in the repo
40
+ # @return [String[]] The tags
41
+ def self.list_tags(args = "")
42
+ @@default.list_tags(args)
43
+ end
44
+
45
+ # Runs git branch command with given args
46
+ def branch(args = "")
47
+ stdout, stderr, status = Open3.capture3("git #{@repo_path_arg} branch #{args}")
48
+ raise "Failed to run branch: #{stderr}" unless status.success?
49
+
50
+ stdout.strip
51
+ end
52
+
53
+ # Runs git branch command with given args
54
+ def self.branch(args = "")
55
+ @@default.branch(args)
56
+ end
57
+
18
58
  # Gets the commit hash of the current HEAD
19
- def self.commit_hash
20
- stdout, stderr, status = Open3.capture3("git rev-parse HEAD")
59
+ def commit_hash
60
+ stdout, stderr, status = Open3.capture3("git #{@repo_path_arg} rev-parse HEAD")
21
61
  raise "Failed to get hash: #{stderr}" unless status.success?
22
62
 
23
63
  stdout.strip
24
64
  end
25
65
 
66
+ # Gets the commit hash of the current HEAD
67
+ def self.commit_hash
68
+ @@default.commit_hash
69
+ end
70
+
26
71
  # Gets the number of commits accessible from HEAD treating the history as a graph.
27
72
  # See more details here: https://git-scm.com/docs/git-rev-list
28
73
  # @return [String] The number of commits
29
- def self.number_of_commits
30
- stdout, stderr, status = Open3.capture3("git rev-list HEAD --count")
74
+ def number_of_commits
75
+ stdout, stderr, status = Open3.capture3("git #{@repo_path_arg} rev-list HEAD --count")
31
76
  raise "Failed to get commit number: #{stderr}" unless status.success?
32
77
 
33
78
  stdout.strip
34
79
  end
35
80
 
81
+ # Gets the number of commits accessible from HEAD treating the history as a graph.
82
+ # See more details here: https://git-scm.com/docs/git-rev-list
83
+ # @return [String] The number of commits
84
+ def self.number_of_commits
85
+ @@default.number_of_commits
86
+ end
87
+
36
88
  # Runs a git fetch all
37
- def self.fetch_all
38
- stdout, stderr, status = Open3.capture3("git fetch --all")
89
+ def fetch_all
90
+ stdout, stderr, status = Open3.capture3("git #{@repo_path_arg} fetch --all")
39
91
  raise "Failed to fetch #{stderr}" unless status.success?
40
92
 
41
93
  stdout.strip
42
94
  end
43
95
 
96
+ # Runs a git fetch all
97
+ def self.fetch_all
98
+ @@default.fetch_all
99
+ end
100
+
44
101
  # Gets all the merges accessible from the current HEAD which matches at least one of the given grep conditions
45
102
  # @param grep_conditions [Array<String>] values to be passed in as grep cases (https://git-scm.com/docs/git-log)
46
- def self.merge_changelog(grep_conditions)
47
- command = "git log HEAD --merges --format=%s#{grep_conditions.map { |c| " --grep #{c}" }.join(" ")}"
103
+ def merge_changelog(grep_conditions)
104
+ command = "git #{@repo_path_arg} log HEAD --merges --format=%s#{grep_conditions.map { |c| " --grep #{c}" }.join(" ")}"
48
105
  stdout, stderr, status = Open3.capture3(command)
49
106
  raise "Failed to get changelog: #{stderr}" unless status.success?
50
107
 
51
108
  stdout
52
109
  end
53
110
 
111
+ # Gets all the merges accessible from the current HEAD which matches at least one of the given grep conditions
112
+ # @param grep_conditions [Array<String>] values to be passed in as grep cases (https://git-scm.com/docs/git-log)
113
+ def self.merge_changelog(grep_conditions)
114
+ @@default.merge_changelog(grep_conditions)
115
+ end
116
+
54
117
  # Gets all the merges that are NOT accessible from HEAD which matches at least one of the given grep conditions
55
118
  # @param grep_conditions [Array<String>] values to be passed in as grep cases (https://git-scm.com/docs/git-log)
56
- def self.invert_changelog(grep_conditions)
57
- command = "git log --all ^HEAD --merges --format=%s#{grep_conditions.map { |c| " --grep #{c}" }.join(" ")}"
119
+ def invert_changelog(grep_conditions)
120
+ command = "git #{@repo_path_arg} log --all ^HEAD --merges --format=%s#{grep_conditions.map { |c| " --grep #{c}" }.join(" ")}"
58
121
  stdout, stderr, status = Open3.capture3(command)
59
122
  raise "Failed to get changelog: #{stderr}" unless status.success?
60
123
 
61
124
  stdout
62
125
  end
126
+
127
+ # Gets all the merges that are NOT accessible from HEAD which matches at least one of the given grep conditions
128
+ # @param grep_conditions [Array<String>] values to be passed in as grep cases (https://git-scm.com/docs/git-log)
129
+ def self.invert_changelog(grep_conditions)
130
+ @@default.invert_changelog(grep_conditions)
131
+ end
63
132
  end
64
133
  end
65
134
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Apadmi
4
4
  module Grout
5
- VERSION = "2.6.0"
5
+ VERSION = "2.7.0"
6
6
  end
7
7
  end
data/lib/apadmi_grout.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "active_support/core_ext/object/blank"
4
+
3
5
  Dir[File.expand_path("apadmi/grout/**/*.rb", File.dirname(__FILE__))].sort.each do |current|
4
6
  require current
5
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apadmi_grout
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.0
4
+ version: 2.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Apadmi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-20 00:00:00.000000000 Z
11
+ date: 2024-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: semantic
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.5.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.5.0
55
69
  description: Apadmi build tool utils for use through Fastlane on Android and iOS.
56
70
  email:
57
71
  - samdc@apadmi.com
@@ -63,6 +77,7 @@ files:
63
77
  - CODE_OF_CONDUCT.md
64
78
  - LICENSE
65
79
  - README.md
80
+ - lib/apadmi/grout/actions/check_unfinished_releases_action.rb
66
81
  - lib/apadmi/grout/actions/find_tickets_to_move_action/find_tickets_to_move_action.rb
67
82
  - lib/apadmi/grout/actions/find_tickets_to_move_action/find_tickets_to_move_ado_action.rb
68
83
  - lib/apadmi/grout/actions/find_tickets_to_move_action/find_tickets_to_move_jira_action.rb
@@ -105,7 +120,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
105
120
  requirements:
106
121
  - - ">="
107
122
  - !ruby/object:Gem::Version
108
- version: 2.7.6
123
+ version: 3.0.0
109
124
  required_rubygems_version: !ruby/object:Gem::Requirement
110
125
  requirements:
111
126
  - - ">="