apadmi_grout 1.1.0 → 1.2.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: f779ff10f50f15d2ce74311339c8407ae32eec3bcc8fb49f0ab3a85d8a0cbdc7
4
- data.tar.gz: e0f9034584fdcafb95355ade65f64ccdd7e82acc2e07d62a5bd61129e3fc5464
3
+ metadata.gz: 9a8f0b024bb98a0372b85755e14bc753370328418273d6e0d07aba74f664bb9a
4
+ data.tar.gz: '04286d3e985378d78f1dec57c220f1a4a5ec35d90ccf4a407d3dde66f75f9a6d'
5
5
  SHA512:
6
- metadata.gz: 10b206d1d56814b6288bf0db35259c02c81baf0c3554de6286627498c0d65ee6f8808fafcd5908038be9a196ae264952180fc4988ca15b4023dd03a1380c98be
7
- data.tar.gz: ecbf93eb1f3bd3141a54949568edc1196ad6b7aaf7348f89f93e9fb46bf76aa424504cf2a5bc5d9effd78f811543322980c65a7e83231cdb283ca492aec53fc8
6
+ metadata.gz: 2c9d6d5fce5da1ffaa1ab71a7f54e4bba85a3f4fda470b0613049a2169ca9466d180b655c3129561e9046fe3d0a4041b85c2cf25d70dfd8ac7f521b70a6d5113
7
+ data.tar.gz: 13b59090e27577e87f7a52ef9dbcc085db1af1b0575a20e98642669155b0652e0e91976a4943f027e33c25d325fe0aa205afa481d761b7a944f5aebf3bf4138a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Core Changelog
2
2
 
3
+ ## [1.2.0] - 2022-05-17
4
+ * Filter out issues missing from git changelogs when finding tickets to move.
5
+
3
6
  ## [1.1.0] - 2022-05-12
4
7
  * Support allowing tickets that aren't assigned to a sprint to be moved.
5
8
  * Created utilities for getting the git root and number of commits
@@ -15,10 +15,11 @@ module Apadmi
15
15
  def initialize(username, token, base_url, context_path, project, logger)
16
16
  @jira_wrapper = Apadmi::Grout::JiraWrapper.new(username, token, base_url, context_path, project)
17
17
 
18
+ git_utils = Apadmi::Grout::GitUtils
18
19
  @move_jira_tickets_action = Apadmi::Grout::MoveJiraTicketsAction.new(@jira_wrapper, logger)
19
- @find_tickets_to_move_action = Apadmi::Grout::FindTicketsToMoveAction.new(@jira_wrapper, logger)
20
- @generate_release_notes_action = Apadmi::Grout::GenerateReleaseNotesAction.new(base_url)
21
20
  @issues_from_changelog_action = Apadmi::Grout::IssuesFromChangelogAction.new(@jira_wrapper, logger)
21
+ @find_tickets_to_move_action = Apadmi::Grout::FindTicketsToMoveAction.new(@jira_wrapper, git_utils, issues_from_changelog_action, logger)
22
+ @generate_release_notes_action = Apadmi::Grout::GenerateReleaseNotesAction.new(base_url)
22
23
  end
23
24
  end
24
25
  end
@@ -2,14 +2,26 @@
2
2
 
3
3
  module Apadmi
4
4
  module Grout
5
+ module PrStatus
6
+ MERGED = 1
7
+ UNMERGED_BUT_INCLUDED = 2
8
+ UN_INCLUDED = 3
9
+ end
10
+
11
+ # ATTENTION: Any changes to the logic here should be reflected in the docs (find-tickets.md)
12
+
5
13
  # Finds and returns a list of all the issues that are ready to be moved
6
14
  # Any tickets found that have the given status but *don't* appear ready to be moved will
7
15
  # be flagged.
8
16
  class FindTicketsToMoveAction
9
17
  # @param [Apadmi::Grout::JiraWrapper]
18
+ # @param [Apadmi::Grout::GitUtils]
19
+ # @param [Apadmi::Grout::IssuesFromChangelogAction]
10
20
  # @param [Apadmi::Grout::DefaultLogger] // or your own logger!
11
- def initialize(jira_wrapper, logger)
21
+ def initialize(jira_wrapper, git_utils, issues_from_chnglg, logger)
12
22
  @jira_wrapper = jira_wrapper
23
+ @git_utils = git_utils
24
+ @issues_from_changelog_action = issues_from_chnglg
13
25
  @logger = logger
14
26
  end
15
27
 
@@ -30,50 +42,73 @@ module Apadmi
30
42
  options ||= Apadmi::Grout::FindTicketsOptions.new(include_no_sprint_tickets: false)
31
43
 
32
44
  issues = @jira_wrapper.search_unblocked_issues(
33
- component,
34
- status,
35
- [],
45
+ component, status, [],
36
46
  allow_no_sprint: options.include_no_sprint_tickets
37
47
  ).reject do |issue|
38
48
  excluded_ticket_keys.include? issue.key
39
49
  end
40
50
 
41
- @logger.message("Found issues to consider #{issues.map(&:key).join(", ")}")
51
+ issue_keys = issues.map(&:key)
52
+ @logger.message("Found issues to consider #{issue_keys.join(", ")}")
53
+
54
+ # Get the issues in the git changelog, filtered for the issues being considered
55
+ changelog_ids = @issues_from_changelog_action.issue_ids_from_changelog(
56
+ @git_utils.merge_changelog(issue_keys)
57
+ )
58
+
42
59
  final_list = issues.filter do |issue|
43
60
  # Decide whether to include this ticket based on PRs
44
- process_prs(issue, custom_flag_messages)
61
+ status = process_prs(issue, custom_flag_messages)
62
+ decide_should_include(issue, status, changelog_ids)
45
63
  end
64
+
46
65
  @logger.message("Final list: #{final_list.map(&:key).join(", ")}")
47
66
  final_list
48
67
  end
49
68
 
50
69
  private
51
70
 
71
+ # @param issue [JIRA::Resource::Issue]
72
+ # @param pr_status [Int] status of whether or not we can move
73
+ # @param changelog_ids [Array<String>] the ticket ids pulled from git
74
+ def decide_should_include(issue, pr_status, changelog_ids)
75
+ # For merged PRs, check if the ticket appears in the changelog.
76
+ # If it doesn't then it's likely it was merged AFTER this release build was triggered and shouldn't be moved
77
+ # by this build
78
+ if pr_status == PrStatus::MERGED
79
+ is_in_changelog = changelog_ids.include?(issue.key)
80
+ @logger.message("NOTE: Not including #{issue.key} since it's not in the git changelog.") unless is_in_changelog
81
+ return is_in_changelog
82
+ end
83
+
84
+ pr_status != PrStatus::UN_INCLUDED
85
+ end
86
+
52
87
  # @param issue [JIRA::Resource::Issue]
53
88
  # @param custom_flag_messages [FlagMessages]
54
- # @return [Boolean] whether or not this ticket can be moved
89
+ # @return [Int] status of whether or not we can move
55
90
  def process_prs(issue, custom_flag_messages)
56
91
  prs = @jira_wrapper.get_ticket_prs(issue)
57
92
 
58
93
  if prs.empty?
59
94
  @logger.message("#{issue.key} has no PRs. Flagging it: STILL MOVABLE")
60
95
  @jira_wrapper.flag_ticket(issue.key, custom_flag_messages.no_prs_flag_msg)
61
- return true
96
+ return PrStatus::UNMERGED_BUT_INCLUDED
62
97
  elsif prs.all?(&:open)
63
98
  @logger.message("#{issue.key} has only open PRs. Flagging it: NOT MOVABLE")
64
99
  @jira_wrapper.flag_ticket(issue.key, custom_flag_messages.open_prs_flag_msg)
65
- return false
100
+ return PrStatus::UN_INCLUDED
66
101
  elsif prs.all?(&:declined)
67
102
  @logger.message("#{issue.key} has only declined PRs. Flagging it: NOT MOVABLE")
68
103
  @jira_wrapper.flag_ticket(issue.key, custom_flag_messages.declined_prs_flag_msg)
69
- return false
104
+ return PrStatus::UN_INCLUDED
70
105
  elsif prs.none?(&:merged)
71
106
  @logger.message("#{issue.key} has no merged PRs. Flagging it: NOT MOVABLE")
72
107
  @jira_wrapper.flag_ticket(issue.key, custom_flag_messages.no_merged_prs_flag_msg)
73
- return false
108
+ return PrStatus::UN_INCLUDED
74
109
  end
75
110
 
76
- true # At least one merged PR, so it's included
111
+ PrStatus::MERGED # At least one merged PR
77
112
  end
78
113
  end
79
114
  end
@@ -13,7 +13,8 @@ module Apadmi
13
13
  # @return [Apadmi::Grout::FlagMessages]
14
14
  def self.default(status)
15
15
  FlagMessages.new(
16
- "REASON FOR FLAG: Check this ticket - it was put in #{status} but has no PRs connected to it. CI still moved it",
16
+ "REASON FOR FLAG: Check this ticket - it was put in #{status} but has no PRs connected to it. CI still moved it. " \
17
+ "(WARNING: this may cause the `fix_versions` to be incorrect)",
17
18
  "REASON FOR FLAG: Check this ticket - it was put in #{status} but has no MERGED PRs and at least one OPEN PR",
18
19
  "REASON FOR FLAG: Check this ticket - it was put in #{status} but has only DECLINED PRs",
19
20
  "REASON FOR FLAG: Check this ticket - it was put in #{status} but has no MERGED PRs"
@@ -20,8 +20,6 @@ module Apadmi
20
20
  @jira_wrapper.find_issues_by_keys(ids)
21
21
  end
22
22
 
23
- private
24
-
25
23
  # @param changelog [String] raw git changelog
26
24
  # @return [Array<String>] list of issue ids from changelog
27
25
  def issue_ids_from_changelog(changelog)
@@ -24,6 +24,16 @@ module Apadmi
24
24
 
25
25
  stdout.strip
26
26
  end
27
+
28
+ # Gets all the merges accessible from the current HEAD which matches at least one of the given grep conditions
29
+ # @param grep_conditions [Array<String>] values to be passed in as grep cases (https://git-scm.com/docs/git-log)
30
+ def self.merge_changelog(grep_conditions)
31
+ command = "git log HEAD --merges --format=%s#{grep_conditions.map { |c| " --grep #{c}" }.join(" ")}"
32
+ stdout, stderr, = Open3.capture3(command)
33
+ raise "Failed to get changelog: #{stderr}" unless stderr.strip.empty?
34
+
35
+ stdout
36
+ end
27
37
  end
28
38
  end
29
39
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Apadmi
4
4
  module Grout
5
- VERSION = "1.1.0"
5
+ VERSION = "1.2.0"
6
6
  end
7
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: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
- - Sam
7
+ - Apadmi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-12 00:00:00.000000000 Z
11
+ date: 2022-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday