apadmi_grout 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 38dac1846b90f9d3ade4bec465d4a8518f3e469977dc1ac51fd02aa238037a99
4
+ data.tar.gz: e1eda0e1ab3dfa4ed76c19f1b629ee8fc0dd29f308c3090145557b3aa0e99cc2
5
+ SHA512:
6
+ metadata.gz: 03ad8c9bfdaafcb3fd25bfb8d4599a8889410bd3b28620ef91417cd43b1ac55599d74f5578cf6747eeb78a52e54f6acf65fed6661c6948e9ed849e0d584e920b
7
+ data.tar.gz: cac7a75e0e4991f4d5a20f714a293b627281d55f993c41a12a157d44c2f73e4b2ee4421f15855543418fb2ad72edea4573e2cee2d32e3c1ed1e561baed83f908
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # Fastlane Plugin Changelog
2
+
3
+ ## [Unreleased]
4
+
5
+ ## [0.1.0] - 2022-01-23
6
+
7
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at samdc@apadmi.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Apadmi Ltd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Apadmi::Grout
2
+
3
+ See documentation here: https://apadmi-grout.web.app/
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Apadmi
4
+ module Grout
5
+ # Convenience class for initializing and accessing the various actions
6
+ class DependencyInjector
7
+ attr_reader :move_jira_tickets_action, :find_tickets_to_move_action, :generate_release_notes_action, :issues_from_changelog_action
8
+
9
+ # @param [String] username
10
+ # @param [String] token
11
+ # @param [String] base_url
12
+ # @param [String] context_path
13
+ # @param [String] project
14
+ # @param [Logger] logger
15
+ def initialize(username, token, base_url, context_path, project, logger)
16
+ @jira_wrapper = Apadmi::Grout::JiraWrapper.new(username, token, base_url, context_path, project)
17
+
18
+ @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
+ @issues_from_changelog_action = Apadmi::Grout::IssuesFromChangelogAction.new(@jira_wrapper, logger)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Apadmi
4
+ module Grout
5
+ # Finds and returns a list of all the issues that are ready to be moved
6
+ # Any tickets found that have the given status but *don't* appear ready to be moved will
7
+ # be flagged.
8
+ class FindTicketsToMoveAction
9
+ # @param [Apadmi::Grout::JiraWrapper]
10
+ # @param [Apadmi::Grout::DefaultLogger] // or your own logger!
11
+ def initialize(jira_wrapper, logger)
12
+ @jira_wrapper = jira_wrapper
13
+ @logger = logger
14
+ end
15
+
16
+ # @param component [String] Only include tickets tagged with this component
17
+ # @param status [String] The status of tickets to be moved (Usually "Awaiting QA Release")
18
+ # @param excluded_ticket_keys [Array<String>] ticket keys to be excluded from consideration
19
+ # @param custom_flag_messages [FlagMessages]
20
+ # @return [Array<JIRA::Resource::Issue>] the issues ready to move
21
+ def run(
22
+ component,
23
+ status,
24
+ excluded_ticket_keys,
25
+ custom_flag_messages = FlagMessages.new(
26
+ "REASON FOR FLAG: Check this ticket - it was put in #{status} but has no PRs connected to it. CI still moved it",
27
+ "REASON FOR FLAG: Check this ticket - it was put in #{status} but has no MERGED PRs and at least one OPEN PR",
28
+ "REASON FOR FLAG: Check this ticket - it was put in #{status} but has only DECLINED PRs",
29
+ "REASON FOR FLAG: Check this ticket - it was put in #{status} but has no MERGED PRs"
30
+ )
31
+ )
32
+ issues = @jira_wrapper.search_unblocked_issues(component, status).reject do |issue|
33
+ puts issue.key
34
+ excluded_ticket_keys.include? issue.key
35
+ end
36
+
37
+ @logger.message("Found issues to consider #{issues.map(&:key).join(", ")}")
38
+ final_list = issues.filter do |issue|
39
+ # Decide whether to include this ticket based on PRs
40
+ process_prs(issue, custom_flag_messages)
41
+ end
42
+ @logger.message("Final list: #{final_list.map(&:key).join(", ")}")
43
+ final_list
44
+ end
45
+
46
+ private
47
+
48
+ # @param issue [JIRA::Resource::Issue]
49
+ # @param custom_flag_messages [FlagMessages]
50
+ # @return [Boolean] whether or not this ticket can be moved
51
+ def process_prs(issue, custom_flag_messages)
52
+ prs = @jira_wrapper.get_ticket_prs(issue)
53
+
54
+ if prs.empty?
55
+ @logger.message("#{issue.key} has no PRs. Flagging it: STILL MOVABLE")
56
+ @jira_wrapper.flag_ticket(issue.key, custom_flag_messages.no_prs_flag_msg)
57
+ return true
58
+ elsif prs.all?(&:open)
59
+ @logger.message("#{issue.key} has only open PRs. Flagging it: NOT MOVABLE")
60
+ @jira_wrapper.flag_ticket(issue.key, custom_flag_messages.open_prs_flag_msg)
61
+ return false
62
+ elsif prs.all?(&:declined)
63
+ @logger.message("#{issue.key} has only declined PRs. Flagging it: NOT MOVABLE")
64
+ @jira_wrapper.flag_ticket(issue.key, custom_flag_messages.declined_prs_flag_msg)
65
+ return false
66
+ elsif prs.none?(&:merged)
67
+ @logger.message("#{issue.key} has no merged PRs. Flagging it: NOT MOVABLE")
68
+ @jira_wrapper.flag_ticket(issue.key, custom_flag_messages.no_merged_prs_flag_msg)
69
+ return false
70
+ end
71
+
72
+ true # At least one merged PR, so it's included
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Apadmi
4
+ module Grout
5
+ # Moves all given jira tickets to a given status and assigns fix versions
6
+ class MoveJiraTicketsAction
7
+ # @param [Apadmi::Grout::JiraWrapper]
8
+ # @param [Apadmi::Grout::DefaultLogger] // or your own logger!
9
+ def initialize(jira_wrapper, logger)
10
+ @jira_wrapper = jira_wrapper
11
+ @logger = logger
12
+ end
13
+
14
+ # @param [Array<String>] version_strings
15
+ # @param [Array<JIRA::Resource::Issue>] issues
16
+ # @param [String] new_status
17
+ def run(version_strings, issues, new_status)
18
+ if issues.empty?
19
+ @logger.error("No issues found, aborting")
20
+ return
21
+ end
22
+
23
+ @logger.message("Creating versions #{version_strings}")
24
+ versions = create_or_get_versions(version_strings)
25
+
26
+ @logger.message("Transitioning issues: #{issues.map(&:key).join(", ")}")
27
+ issues.each { |issue| move_issue(issue, new_status, versions) }
28
+
29
+ @logger.success("Issues transitioned successfully :D")
30
+ end
31
+
32
+ # @param [Array<String>] version_strings
33
+ # @return [Array<JIRA::Resource::Version>]
34
+ def create_or_get_versions(version_strings)
35
+ all_versions = @jira_wrapper.all_versions
36
+ version_strings.map do |version|
37
+ existing_version = all_versions.find { |v| v.name == version }
38
+ if !existing_version.nil?
39
+ existing_version
40
+ else
41
+ date = Time.now.strftime("%Y-%m-%d")
42
+ @jira_wrapper.create_version(date, version)
43
+ end
44
+ end
45
+ end
46
+
47
+ # @param [JIRA::Resource::Issue] issue
48
+ # @param [String] new_status
49
+ # @param [Array<JIRA::Resource::Version>] versions
50
+ def move_issue(issue, new_status, versions)
51
+ @jira_wrapper.transition_issue(issue, new_status)
52
+ @jira_wrapper.assign_fixversions(issue.id, versions)
53
+ end
54
+
55
+ private :create_or_get_versions, :move_issue
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ FlagMessages = Struct.new(
4
+ :no_prs_flag_msg,
5
+ :open_prs_flag_msg,
6
+ :declined_prs_flag_msg,
7
+ :no_merged_prs_flag_msg
8
+ )
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Apadmi
4
+ module Grout
5
+ # Represents a pull request object derived from the Jira REST API response.
6
+ class PullRequest
7
+ # @return [String]
8
+ attr_reader :id
9
+ # @return [String]
10
+ attr_reader :name
11
+ # @return [bool]
12
+ attr_reader :merged
13
+ # @return [bool]
14
+ attr_reader :declined
15
+ # @return [bool]
16
+ attr_reader :open
17
+
18
+ # @param [String] id
19
+ # @param [String] name
20
+ # @param [bool] merged
21
+ # @param [bool] declined
22
+ def initialize(id, name, merged, declined)
23
+ @id = id
24
+ @name = name
25
+ @merged = merged
26
+ @declined = declined
27
+ @open = (!merged and !declined)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Apadmi
4
+ module Grout
5
+ # Represents a version object derived from the Jira REST API response.
6
+ class Version
7
+ attr_reader :self, :id, :description, :name, :archived, :released, :release_date, :overdue, :user_release_date, :project_id
8
+
9
+ def initialize(json)
10
+ @self = json["self"]
11
+ @id = json["id"]
12
+ @description = json["description"]
13
+ @name = json["name"]
14
+ @archived = json["archived"]
15
+ @released = json["released"]
16
+ @release_date = json["release_date"]
17
+ @overdue = json["overdue"]
18
+ @user_release_date = json["user_release_date"]
19
+ @project_id = json["project_id"]
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,261 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Build tools
4
+ require "jira-ruby"
5
+ require "faraday"
6
+
7
+ module Apadmi
8
+ module Grout
9
+ # Provides a layer of abstraction on top of the Jira api
10
+ class JiraWrapper
11
+ APPLICATION_JSON = "application/json"
12
+ CONTENT_TYPE = "Content-Type"
13
+ private_constant :CONTENT_TYPE, :APPLICATION_JSON
14
+
15
+ # @param [String] username
16
+ # @param [String] token
17
+ # @param [String] base_url
18
+ # @param [String] context_path
19
+ # @param [String] project
20
+ def initialize(username, token, base_url, context_path, project)
21
+ @options = {
22
+ username: username,
23
+ password: token,
24
+ site: base_url,
25
+ context_path: context_path,
26
+ auth_type: :basic
27
+ }
28
+ @project = project
29
+ @jira_client = JIRA::Client.new(@options)
30
+ end
31
+
32
+ # @return returns the ticket prefix for the given project
33
+ def issue_id_prefix
34
+ @project
35
+ end
36
+
37
+ # @param [String[]] keys
38
+ # @return [Array<JIRA::Resource::Issue>]
39
+ def find_issues_by_keys(keys)
40
+ return [] if keys.length <= 0
41
+
42
+ jql_search = "project = '#{@project}' AND issue IN (#{keys.join(", ")})"
43
+ @jira_client.Issue.jql(jql_search, { max_results: 1000 }).uniq
44
+ end
45
+
46
+ # @param [String] component
47
+ # @param [String] status
48
+ # @param [String[]] ticket_types
49
+ # @return [Array<JIRA::Resource::Issue>]
50
+ def search_unblocked_issues(component, status, ticket_types = [])
51
+ component_filter = (" AND component = '#{component}' " unless component.empty?) || ""
52
+ status_filter = (" AND status = '#{status}' " unless status.empty?) || ""
53
+ type_filter = ("AND (#{ticket_types.map { |type| "type = #{type}" }.join("OR ")})" unless ticket_types.empty?) || ""
54
+
55
+ jql_search = %{
56
+ project = '#{@project}'
57
+ #{status_filter} #{component_filter} #{type_filter}
58
+ AND sprint in openSprints() AND (labels not in(Blocked) or labels is EMPTY) AND Flagged is EMPTY
59
+ }
60
+
61
+ @jira_client.Issue.jql(jql_search, { max_results: 1000 }).uniq
62
+ end
63
+
64
+ # @param [String] key
65
+ # @param [String] comment
66
+ def flag_ticket(key, comment)
67
+ payload = "{\"flag\":true,\"issueKeys\":[\"#{key}\"],\"commentVisibility\":\"\",\"comment\":\"#{comment}\"}"
68
+ do_post("#{@options[:site]}/rest/greenhopper/1.0/xboard/issue/flag/flag.json", payload)
69
+ end
70
+
71
+ # @param [String] key
72
+ def un_flag_ticket(key)
73
+ payload = "{\"flag\":false,\"issueKeys\":[\"#{key}\"],\"commentVisibility\":\"\",\"comment\":\"Unflagged by CI\"}"
74
+ do_post("#{@options[:site]}/rest/greenhopper/1.0/xboard/issue/flag/flag.json", payload)
75
+ end
76
+
77
+ # @param [String] key
78
+ # @return bool
79
+ def flagged?(key)
80
+ jql_search = "project = '#{@project}' AND issue IN (#{key}) AND Flagged is not EMPTY"
81
+ response = @jira_client.Issue.jql(jql_search, { max_results: 1 }).uniq
82
+ response != []
83
+ end
84
+
85
+ # @param [String] key
86
+ # @param [String] comment
87
+ def add_comment(key, comment)
88
+ payload = "{\"issueKeys\":[\"#{key}\"],\"commentVisibility\":\"\",\"comment\":\"#{comment}\"}"
89
+ do_post("#{@options[:site]}/rest/greenhopper/1.0/xboard/issue/flag/flag.json", payload)
90
+ end
91
+
92
+ # @param [String] key
93
+ # @return [JIRA::Resource::Comment]
94
+ def get_top_comment(key)
95
+ jql_search = "project = '#{@project}' AND issue IN (#{key})"
96
+ response = @jira_client.Issue.jql(jql_search, { fields: ["comment"], max_results: 1000 }).uniq
97
+ comments = response[0].comments.reverse
98
+ !comments.empty? ? comments[0] : nil
99
+ end
100
+
101
+ # @param [String] key
102
+ # @param [String] comment_id
103
+ def remove_comment(key, comment_id)
104
+ do_delete("#{@options[:site]}/rest/api/2/issue/#{key}/comment/#{comment_id}")
105
+ end
106
+
107
+ # @param [String] component_key
108
+ # @return [Array<JIRA::Resource::Issue>]
109
+ def get_tickets_by_component(component_key)
110
+ jql_search = "project = '#{@project}' AND component IN ('#{component_key}')"
111
+ @jira_client.Issue.jql(jql_search, { max_results: 1000 }).uniq
112
+ end
113
+
114
+ # @param [String] key
115
+ def get_transitions(key)
116
+ issue = @jira_client.Issue.find(key)
117
+ @jira_client.Transition.all(issue: issue)
118
+ end
119
+
120
+ # @param [String] ticket
121
+ # @param [String] state_name
122
+ def transition_ticket(ticket, state_name)
123
+ issue = @jira_client.Issue.find(ticket)
124
+ transition_issue(issue, state_name)
125
+ end
126
+
127
+ # @param [JIRA::Resource::Issue] issue
128
+ # @param [String] state_name
129
+ def transition_issue(issue, state_name)
130
+ transitions = @jira_client.Transition.all(issue: issue)
131
+ transition = transitions.find { |elem| elem.name == state_name }
132
+
133
+ trans = issue.transitions.build
134
+ trans.save!("transition" => { "id" => transition.id })
135
+ end
136
+
137
+ # @param [String] key
138
+ def get_ticket_status(key)
139
+ issue = @jira_client.Issue.find(key)
140
+ issue.status
141
+ end
142
+
143
+ # @param [JIRA::Resource::Issue] issue
144
+ # @return [Array<PullRequest>]
145
+ def get_ticket_prs(issue)
146
+ response = do_get("#{@options[:site]}/rest/dev-status/latest/issue/details?issueId=#{issue.id}&applicationType=bitbucket&dataType=pullrequest")
147
+
148
+ return [] if JSON.parse(response.body)["detail"].empty?
149
+
150
+ JSON.parse(response.body)["detail"][0]["pullRequests"].map do |pr|
151
+ PullRequest.new(pr["id"], pr["name"], pr["status"].to_s == "MERGED", pr["status"].to_s == "DECLINED")
152
+ end
153
+ end
154
+
155
+ # @param [String] keys
156
+ # @param [String] component
157
+ # @return [Array<JIRA::Resource::Issue>]
158
+ def get_ticket_subtask(keys, component = nil)
159
+ jql_search = "project = '#{@project}' AND parent IN #{keys.to_s.gsub("[", "(").gsub("]", ")")}"\
160
+ + (component.nil? ? "" : " AND component IN ('#{component}')")
161
+ @jira_client.Issue.jql(jql_search, { max_results: 1000 }).uniq
162
+ end
163
+
164
+ # @param [String] release_date
165
+ # @param [String] name
166
+ # @return [JIRA::Resource::Version]
167
+ def create_version(release_date, name)
168
+ version = @jira_client.Version.build
169
+ version.save!({
170
+ "project": @project,
171
+ "name": name,
172
+ "releaseDate": release_date
173
+ })
174
+ version
175
+ end
176
+
177
+ # @param [int] version_id
178
+ # @param [int] move_version_id
179
+ def delete_version(version_id, move_version_id)
180
+ payload = "{\"moveFixIssuesTo\": #{move_version_id}, \"moveAffectedIssuesTo\": #{move_version_id}, "\
181
+ "\"customFieldReplacementList\": []}"
182
+ do_post("#{@options[:site]}/rest/api/2/version/#{version_id}/removeAndSwap", payload)
183
+ end
184
+
185
+ # @return [Array<JIRA::Resource::Version>]
186
+ def all_versions
187
+ @jira_client.Project.find(@project).versions
188
+ end
189
+
190
+ # @param [String] ticket
191
+ # @param [Array<JIRA::Resource::Version>] versions
192
+ def assign_fixversions(ticket, versions)
193
+ fixversions = versions.map { |v| "{\"id\": \"#{v.id}\"}" }.join(", ")
194
+ payload = "{\"fields\" : {\"fixVersions\": [#{fixversions}] }}"
195
+ do_put("#{@options[:site]}/rest/api/2/issue/#{ticket}", payload)
196
+ end
197
+
198
+ # @param [String] ticket
199
+ # @return [Array<Version>]
200
+ def get_ticket_fixversions(ticket)
201
+ response = do_get("#{@options[:site]}/rest/api/2/issue/#{ticket}")
202
+ JSON.parse(response.body)["fields"]["fixVersions"].map do |version|
203
+ Version.new(version)
204
+ end
205
+ end
206
+
207
+ # @param [Faraday::Response] response
208
+ def throw_if_error(response)
209
+ raise "Network call failed #{response.status} #{response.body}" unless (200..210).include?(response.status)
210
+ end
211
+
212
+ # @param [String] uri
213
+ # @return [Faraday::Response]
214
+ def do_get(uri)
215
+ conn = setup_con
216
+ response = conn.get(uri, CONTENT_TYPE => APPLICATION_JSON)
217
+ throw_if_error(response)
218
+ response
219
+ end
220
+
221
+ # @param [String] uri
222
+ # @param [String] payload
223
+ # @return [Faraday::Response]
224
+ def do_put(uri, payload)
225
+ conn = setup_con
226
+ response = conn.put(uri, payload, CONTENT_TYPE => APPLICATION_JSON)
227
+ throw_if_error(response)
228
+ response
229
+ end
230
+
231
+ # @param [String] uri
232
+ # @param [String] payload
233
+ # @return [Faraday::Response]
234
+ def do_post(uri, payload)
235
+ conn = setup_con
236
+ response = conn.post(uri, payload, CONTENT_TYPE => APPLICATION_JSON)
237
+ throw_if_error(response)
238
+ response
239
+ end
240
+
241
+ # @param [String] uri
242
+ # @return [Faraday::Response]
243
+ def do_delete(uri)
244
+ conn = setup_con
245
+ response = conn.delete(uri, CONTENT_TYPE => APPLICATION_JSON)
246
+ throw_if_error(response)
247
+ response
248
+ end
249
+
250
+ # @return [Faraday::Connection]
251
+ def setup_con
252
+ auth_str = "#{@options[:username]}:#{@options[:password]}"
253
+ conn = Faraday.new # create a new Connection with base URL
254
+ conn.headers["Authorization"] = "Basic #{Base64.strict_encode64(auth_str)}"
255
+ conn
256
+ end
257
+
258
+ private :setup_con, :do_delete, :do_get, :do_post, :do_put
259
+ end
260
+ end
261
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mustache"
4
+
5
+ module Apadmi
6
+ module Grout
7
+ # Finds and returns a list of all the issues who's ids exist in the given changelog
8
+ class GenerateReleaseNotesAction
9
+ # @param jira_base_url [String] Jira base url
10
+ def initialize(jira_base_url)
11
+ @jira_base_url = jira_base_url
12
+ end
13
+
14
+ # @param config [Apadmi::Grout::ReleaseNotesConfig]
15
+ def run(config)
16
+ base_url = "#{@jira_base_url}/browse/"
17
+
18
+ Mustache.render(
19
+ config.templates.document_template,
20
+ config: config,
21
+ rendered_moved_issues: render_classified_issues(config.templates.list_template, base_url, config.classified_moved_issues),
22
+ rendered_release_issues: render_classified_issues(config.templates.list_template, base_url, config.classified_release_issues)
23
+ ).strip
24
+ end
25
+
26
+ private
27
+
28
+ def render_classified_issues(template, base_url, classified_issues)
29
+ return if classified_issues.empty
30
+
31
+ Mustache.render(
32
+ template,
33
+ classified_issues: classified_issues,
34
+ base_url: base_url
35
+ )
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Apadmi
4
+ module Grout
5
+ # Finds and returns a list of all the issues who's ids exist in the given changelog
6
+ class IssuesFromChangelogAction
7
+ # @param [Apadmi::Grout::JiraWrapper]
8
+ # @param [Apadmi::Grout::DefaultLogger] // or your own logger!
9
+ def initialize(jira_wrapper, logger)
10
+ @jira_wrapper = jira_wrapper
11
+ @logger = logger
12
+ end
13
+
14
+ # @param changelog [String] raw git changelog
15
+ # @return [Array<JIRA::Resource::Issue>] list of issues from changelog
16
+ def run(changelog)
17
+ ids = issue_ids_from_changelog(changelog)
18
+
19
+ @logger.message("Found issue ids: #{ids.join(", ")}")
20
+ @jira_wrapper.find_issues_by_keys(ids)
21
+ end
22
+
23
+ private
24
+
25
+ # @param changelog [String] raw git changelog
26
+ # @return [Array<String>] list of issue ids from changelog
27
+ def issue_ids_from_changelog(changelog)
28
+ changelog.scan(/(#{@jira_wrapper.issue_id_prefix}-\d+)/).flatten.uniq
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Apadmi
4
+ module Grout
5
+ # @param tasks [Array<JIRA::Resource::Issue>]
6
+ # @param features [Array<JIRA::Resource::Issue>] aka stories
7
+ # @param improvements [Array<JIRA::Resource::Issue>]
8
+ # @param defects [Array<JIRA::Resource::Issue>] aka bugs
9
+ # @param others [Array<JIRA::Resource::Issue>] any other non-standard issue types
10
+ ClassifiedIssues = Struct.new(
11
+ :tasks,
12
+ :features,
13
+ :improvements,
14
+ :defects,
15
+ :others
16
+ ) do
17
+ # @return returns true if all categories are empty
18
+ def empty
19
+ tasks.empty? && features.empty? &&
20
+ improvements.empty? && defects.empty? && others.empty?
21
+ end
22
+ end
23
+
24
+ # @param title [String] The title of the document
25
+ # @param app_version [String] The app version pertaining to this release
26
+ # @param min_os_version [String] The min supported os version of this release
27
+ # @param date [String] Today's date
28
+ # @param moved_issues [Array<JIRA::Resource::Issue>] Issues moved to a new state by this build job
29
+ # @param release_issues [Array<JIRA::Resource::Issue>] Issues considered part of this release
30
+ # @param commit_hash [String] Commit hash from which release was built
31
+ # @param ci_build_number [String] CI build number which built the release
32
+ # @param ci_build_url [String] Link to CI build job
33
+ # @param templates [Apadmi::Grout::Templates] Mustache templates to use to generate the document
34
+ ReleaseNotesConfig = Struct.new(
35
+ :title,
36
+ :app_version,
37
+ :min_os_version,
38
+ :date,
39
+ :moved_issues,
40
+ :release_issues,
41
+ :commit_hash,
42
+ :ci_build_number,
43
+ :ci_build_url,
44
+ :templates
45
+ ) do
46
+ def classified_moved_issues
47
+ classify_issues(moved_issues)
48
+ end
49
+
50
+ def classified_release_issues
51
+ classify_issues(release_issues)
52
+ end
53
+
54
+ private
55
+
56
+ def classify_issues(issues)
57
+ ClassifiedIssues.new(
58
+ filter_issues_by_type(%w[Task], issues),
59
+ filter_issues_by_type(%w[Story Debt], issues),
60
+ filter_issues_by_type(%w[Improvement Rework], issues),
61
+ filter_issues_by_type(%w[Bug], issues),
62
+ issues - filter_issues_by_type(%w[Task Story Debt Improvement Rework Bug], issues)
63
+ )
64
+ end
65
+
66
+ # @param types [Array<String>] List of types to match on
67
+ # @param issues [Array<JIRA::Resource::Issue>]
68
+ # @return [Array<JIRA::Resource::Issue>]
69
+ def filter_issues_by_type(types, issues)
70
+ issues.find_all { |issue| types.include?(issue.issuetype.name) }
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Apadmi
4
+ module Grout
5
+ # Default baked in templates for generating release notes
6
+ class DefaultTemplates
7
+ def default_document_template
8
+ %{# {{config.title}}
9
+
10
+ ### Version
11
+ {{config.app_version}}
12
+ {{config.hello}}
13
+ ### Release date
14
+ {{config.date}}
15
+
16
+ ### Minimum Supported OS
17
+ {{config.min_os_version}}
18
+
19
+ ### Build Details
20
+ Commit Hash: {{config.commit_hash}}
21
+ [CI/CD build \#{{config.ci_build_number}}]({{config.ci_build_url}})
22
+
23
+ ## Jira Tickets Moved By This Build
24
+ {{ rendered_moved_issues }}
25
+ ## Jira Sprint Release notes
26
+ {{ rendered_release_issues }} }
27
+ end
28
+
29
+ def default_list_template
30
+ %{### New functionality
31
+ {{# classified_issues.features.first}}
32
+ {{# classified_issues.features}}
33
+ * [{{ key }} - {{ summary }}]({{ base_url }}{{ key }})
34
+ {{/ classified_issues.features}}
35
+
36
+ {{/ classified_issues.features.first}}
37
+ {{# classified_issues.improvements.first}}
38
+ ### Improvements
39
+ {{# classified_issues.improvements}}
40
+ * [{{ key }} - {{ summary }}]({{ base_url }}{{ key }})
41
+ {{/ classified_issues.improvements}}
42
+
43
+ {{/ classified_issues.improvements.first}}
44
+ {{# classified_issues.tasks.first}}
45
+ ### Completed Tasks
46
+ {{# classified_issues.tasks}}
47
+ * [{{ key }} - {{ summary }}]({{ base_url }}{{ key }})
48
+ {{/ classified_issues.tasks}}
49
+
50
+ {{/ classified_issues.tasks.first}}
51
+ {{# classified_issues.defects.first}}
52
+ ### Fixed defects
53
+ {{# classified_issues.defects}}
54
+ * [{{ key }} - {{ summary }}]({{ base_url }}{{ key }})
55
+ {{/ classified_issues.defects}}
56
+
57
+ {{/ classified_issues.defects.first}}
58
+ {{# classified_issues.others.first}}
59
+ ### Other issue types
60
+ {{# classified_issues.others}}
61
+ * [{{ key }} - {{ summary }}]({{ base_url }}{{ key }})
62
+ {{/ classified_issues.others}}
63
+
64
+ {{/ classified_issues.others.first}}}
65
+ end
66
+ end
67
+
68
+ # @param document_template [String] the template for the entire document
69
+ # @param list_template [String] the template for the repeated subsection listing issues
70
+ Templates = Struct.new(
71
+ :document_template,
72
+ :list_template
73
+ ) do
74
+ # @return returns the default hardcoded templates
75
+ def self.default
76
+ defaults = DefaultTemplates.new
77
+ Templates.new(defaults.default_document_template, defaults.default_list_template)
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Apadmi
4
+ module Grout
5
+ # A basic logger to be used in various places. To be replaced by version injected from fastlane in real use
6
+ class DefaultLogger
7
+ def error(msg)
8
+ puts "ERROR: #{msg}"
9
+ end
10
+
11
+ def success(msg)
12
+ puts "SUCCESS: #{msg}"
13
+ end
14
+
15
+ def message(msg)
16
+ puts "MESSAGE: #{msg}"
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Apadmi
4
+ module Grout
5
+ VERSION = "0.0.3"
6
+ end
7
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "apadmi/grout/version"
4
+ require_relative "apadmi/grout/di"
5
+
6
+ require_relative "apadmi/grout/release_notes/actions/issues_from_changelog_action"
7
+ require_relative "apadmi/grout/release_notes/actions/generate_release_notes_action"
8
+ require_relative "apadmi/grout/release_notes/models/release_notes_config"
9
+ require_relative "apadmi/grout/release_notes/models/release_notes_templates"
10
+
11
+ require_relative "apadmi/grout/jira/actions/move_jira_tickets_action"
12
+ require_relative "apadmi/grout/jira/actions/find_tickets_to_move_action"
13
+
14
+ require_relative "apadmi/grout/jira/wrapper/jira_wrapper"
15
+
16
+ require_relative "apadmi/grout/jira/models/pull_request"
17
+ require_relative "apadmi/grout/jira/models/version"
18
+ require_relative "apadmi/grout/jira/models/flag_messages"
19
+
20
+ require_relative "apadmi/grout/utils/logger"
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: apadmi_grout
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Sam
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-05-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: jira-ruby
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.2.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.2.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: mustache
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ description: Apadmi build tool utils for use through Fastlane on Android and iOS.
56
+ email:
57
+ - samdc@apadmi.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - CHANGELOG.md
63
+ - CODE_OF_CONDUCT.md
64
+ - LICENSE
65
+ - README.md
66
+ - lib/apadmi/grout/di.rb
67
+ - lib/apadmi/grout/jira/actions/find_tickets_to_move_action.rb
68
+ - lib/apadmi/grout/jira/actions/move_jira_tickets_action.rb
69
+ - lib/apadmi/grout/jira/models/flag_messages.rb
70
+ - lib/apadmi/grout/jira/models/pull_request.rb
71
+ - lib/apadmi/grout/jira/models/version.rb
72
+ - lib/apadmi/grout/jira/wrapper/jira_wrapper.rb
73
+ - lib/apadmi/grout/release_notes/actions/generate_release_notes_action.rb
74
+ - lib/apadmi/grout/release_notes/actions/issues_from_changelog_action.rb
75
+ - lib/apadmi/grout/release_notes/models/release_notes_config.rb
76
+ - lib/apadmi/grout/release_notes/models/release_notes_templates.rb
77
+ - lib/apadmi/grout/utils/logger.rb
78
+ - lib/apadmi/grout/version.rb
79
+ - lib/apadmi_grout.rb
80
+ homepage: https://bitbucket.org/apadmi/apadmi-grout-ruby/
81
+ licenses: []
82
+ metadata:
83
+ homepage_uri: https://bitbucket.org/apadmi/apadmi-grout-ruby/
84
+ documentation_uri: https://apadmi-grout.web.app/
85
+ source_code_uri: https://bitbucket.org/apadmi/apadmi-grout-ruby/
86
+ changelog_uri: https://bitbucket.org/apadmi/apadmi-grout-ruby/
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: 2.7.0
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubygems_version: 3.1.2
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: Apadmi build tool utils for use through Fastlane on Android and iOS.
106
+ test_files: []