fastlane-plugin-allure_zephyr 0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a25396053c7f6f8015b037196ddd86685dc5c3b7205db0d3e6a29c9e3a0ddb50
4
+ data.tar.gz: 6e19659ac3d9450aaf948ba6735e2f31fbd801606ba12723a011a46b5fae9ba7
5
+ SHA512:
6
+ metadata.gz: 4d0e8233821aa0f8b5704eb05da8baf1f4c817d5e6da19ed6716812a06b1a46d5affaeca285fc6cea79d362e3c9bd48dd4efc383b498945370f52e3237c75d23
7
+ data.tar.gz: 3ac38be85392f245493d388efb4c72ccb04941fcd89d5376e995d108d166482a8f16f569811fde05cacec9fb794d4d42a65ad67f342966d0aed77d0c0ad52a7f
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Nikita Ianenko <yanenko@hotmail.com>
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,48 @@
1
+ # allure_zephyr plugin
2
+
3
+ [![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-allure_zephyr)
4
+
5
+ ## Getting Started
6
+
7
+ This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-allure_zephyr`, add it to your project by running:
8
+
9
+ ```bash
10
+ fastlane add_plugin allure_zephyr
11
+ ```
12
+
13
+ ## About allure_zephyr
14
+
15
+ Publish Allure results to Zephyr
16
+
17
+ ## Example
18
+
19
+ Check out the [example `Fastfile`](fastlane/Fastfile) to see how to use this plugin. Try it by cloning the repo, running `fastlane install_plugins` and `bundle exec fastlane test`.
20
+
21
+ ## Run tests for this plugin
22
+
23
+ To run both the tests, and code style validation, run
24
+
25
+ ```
26
+ rake
27
+ ```
28
+
29
+ To automatically fix many of the styling issues, use
30
+ ```
31
+ rubocop -a
32
+ ```
33
+
34
+ ## Issues and Feedback
35
+
36
+ For any other issues and feedback about this plugin, please submit it to this repository.
37
+
38
+ ## Troubleshooting
39
+
40
+ If you have trouble using plugins, check out the [Plugins Troubleshooting](https://docs.fastlane.tools/plugins/plugins-troubleshooting/) guide.
41
+
42
+ ## Using _fastlane_ Plugins
43
+
44
+ For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://docs.fastlane.tools/plugins/create-plugin/).
45
+
46
+ ## About _fastlane_
47
+
48
+ _fastlane_ is the easiest way to automate beta deployments and releases for your iOS and Android apps. To learn more, check out [fastlane.tools](https://fastlane.tools).
@@ -0,0 +1,16 @@
1
+ require 'fastlane/plugin/allure_zephyr/version'
2
+
3
+ module Fastlane
4
+ module AllureZephyr
5
+ # Return all .rb files inside the "actions" and "helper" directory
6
+ def self.all_classes
7
+ Dir[File.expand_path('**/{actions,helper}/*.rb', File.dirname(__FILE__))]
8
+ end
9
+ end
10
+ end
11
+
12
+ # By default we want to import all available actions and helpers
13
+ # A plugin can contain any number of actions and plugins
14
+ Fastlane::AllureZephyr.all_classes.each do |current|
15
+ require current
16
+ end
@@ -0,0 +1,98 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/allure_zephyr_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ class AllureZephyrAction < Action
7
+ def self.run(params)
8
+ report_path = File.expand_path(params[:report_path])
9
+
10
+ helper = Helper::AllureZephyrHelper.new(
11
+ project: params[:project],
12
+ jira_api: params[:jira_api_url],
13
+ zephyr_api: params[:zephyr_api_url],
14
+ credentials: { username: params[:jira_username], password: params[:jira_password] },
15
+ report_path: report_path,
16
+ limit_by_project: params[:limit_by_project]
17
+ )
18
+ helper.execute_all(version: params[:version], cycle: params[:cycle])
19
+ end
20
+
21
+ def self.description
22
+ "Publish Allure results to Zephyr"
23
+ end
24
+
25
+ def self.authors
26
+ ["Nikita Ianenko"]
27
+ end
28
+
29
+ def self.return_value
30
+ # If your method provides a return value, you can describe here what it does
31
+ end
32
+
33
+ def self.details
34
+ # Optional:
35
+ "This plugin publishes test results from Allure to Zephyr, for those tests that have links included."
36
+ end
37
+
38
+ def self.available_options
39
+ [
40
+ FastlaneCore::ConfigItem.new(key: :report_path,
41
+ description: "Path to Allure report directory",
42
+ optional: false,
43
+ is_string: true,
44
+ type: String),
45
+ FastlaneCore::ConfigItem.new(key: :project,
46
+ description: "JIRA project ID",
47
+ optional: false,
48
+ is_string: true,
49
+ type: String),
50
+ FastlaneCore::ConfigItem.new(key: :jira_api_url,
51
+ description: "JIRA API URL (e.g. https://jira.example.com/rest/api/2)",
52
+ optional: false,
53
+ is_string: true,
54
+ type: String),
55
+ FastlaneCore::ConfigItem.new(key: :zephyr_api_url,
56
+ description: "Zephyr API URL (e.g. https://jira.example.com/rest/zapi/latest)",
57
+ optional: false,
58
+ is_string: true,
59
+ type: String),
60
+ FastlaneCore::ConfigItem.new(key: :jira_username,
61
+ description: "JIRA user name to log in",
62
+ optional: false,
63
+ is_string: true,
64
+ type: String),
65
+ FastlaneCore::ConfigItem.new(key: :jira_password,
66
+ description: "JIRA password to log in",
67
+ optional: false,
68
+ is_string: true,
69
+ type: String),
70
+ FastlaneCore::ConfigItem.new(key: :version,
71
+ description: "Version of the app that tests run against",
72
+ optional: false,
73
+ is_string: true,
74
+ type: String),
75
+ FastlaneCore::ConfigItem.new(key: :cycle,
76
+ description: "Test cycle name",
77
+ optional: false,
78
+ is_string: true,
79
+ type: String),
80
+ FastlaneCore::ConfigItem.new(key: :limit_by_project,
81
+ description: "Project name to limit links by. By default, all links are parsed, even if they belong to different JIRA projects",
82
+ optional: true,
83
+ is_string: true,
84
+ type: String,
85
+ default_value: nil),
86
+ ]
87
+ end
88
+
89
+ def self.is_supported?(platform)
90
+ # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
91
+ # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
92
+ #
93
+ # [:ios, :mac, :android].include?(platform)
94
+ true
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,175 @@
1
+ require 'fastlane_core/ui/ui'
2
+ require 'HTTParty'
3
+
4
+ module Fastlane
5
+ UI = FastlaneCore::UI unless Fastlane.const_defined?("UI")
6
+
7
+ module Helper
8
+ class AllureZephyrHelper
9
+ def initialize(project:, jira_api:, zephyr_api:, credentials:, report_path:, limit_by_project: nil)
10
+ @tests = Hash.new
11
+ @project = project
12
+ @jira_api = jira_api
13
+ @zephyr_api = zephyr_api
14
+ @credentials = credentials
15
+ get_all_statuses(report_path: report_path, limit_by_project: limit_by_project)
16
+ end
17
+
18
+ def get_all_statuses(report_path:, limit_by_project: nil)
19
+ UI.message("Getting statuses of all tests from '#{report_path}'...")
20
+ regex_status = /status": "(\w+)"/
21
+ regex_url = limit_by_project.nil? ? /url.*\/([\w\d\-]+)"/ : /url.*(#{limit_by_project}-\d+)/
22
+ pattern_links = "links"
23
+ pattern_links_end = "]"
24
+
25
+ path = "#{report_path}/data/test-cases"
26
+
27
+ Dir.each_child(path) do |file|
28
+ status = nil
29
+ links_found = nil
30
+
31
+ IO.foreach("#{path}/#{file}") do |line|
32
+ if status.nil?
33
+ status_match = line.match(regex_status)
34
+ status = status_match[1].to_sym unless status_match.nil?
35
+ elsif links_found.nil?
36
+ links_found = true if line.include?(pattern_links)
37
+ else
38
+ url_match = line.match(regex_url)
39
+ unless url_match.nil?
40
+ key = url_match[1]
41
+ @tests[key] = [status, nil] if @tests[key].nil? || (@tests[key][0] != status && @tests[key][0] == :passed)
42
+ break if line.include?(pattern_links_end)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ def execute_all(version:, cycle:)
50
+ statuses = Hash.new
51
+
52
+ version_id = get_version_id(version_name: version)
53
+ cycle_id = get_cycle_id(cycle_name: cycle, version_id: version_id) || create_cycle(cycle_name: cycle, version_id: version_id)
54
+
55
+ @tests.each do |ticket, value|
56
+ execution = create_execution(
57
+ ticket_number: ticket,
58
+ cycle_id: cycle_id,
59
+ version_id: version_id
60
+ )
61
+ @tests[ticket][1] = execution
62
+ statuses[value[0]] = [] if statuses[value[0]].nil?
63
+ statuses[value[0]] << execution
64
+ end
65
+
66
+ statuses.each do |status, executions|
67
+ case status
68
+ when :passed
69
+ status_code = 1
70
+ when :failed
71
+ status_code = 2
72
+ else
73
+ status_code = 5
74
+ end
75
+ UI.message("Setting execution status for all '#{status}' tests...")
76
+ execute(executions: executions, status: status_code)
77
+ end
78
+ end
79
+
80
+ def create_execution(ticket_number:, cycle_id:, version_id:)
81
+ UI.message("Creating execution for #{ticket_number}...")
82
+ path = "#{@zephyr_api}/execution"
83
+
84
+ ticket_id = get_ticket_id(ticket_number: ticket_number)
85
+ body = {
86
+ cycleId: cycle_id,
87
+ issueId: ticket_id,
88
+ projectId: @project,
89
+ versionId: version_id,
90
+ }
91
+
92
+ response = HTTParty.post(path, { basic_auth: @credentials, headers: { "Content-Type": "application/json" }, body: body.to_json })
93
+ UI.user_error!("Can't create execution for #{cycle_id} cycle. Expected code 200, got #{response.code}") unless response.code == 200
94
+ parsed = JSON.parse(response.body)
95
+
96
+ return parsed.keys[0]
97
+ end
98
+
99
+ def execute(executions:, status:)
100
+ path = "#{@zephyr_api}/execution/updateBulkStatus"
101
+
102
+ body = {
103
+ executions: executions,
104
+ status: status
105
+ }
106
+
107
+ response = HTTParty.put(path, { basic_auth: @credentials, headers: { "Content-Type": "application/json" }, body: body.to_json })
108
+ UI.user_error!("Can't create execution for #{cycle_id} cycle. Expected code 200, got #{response.code}") unless response.code == 200
109
+ end
110
+
111
+ def get_version_id(version_name:)
112
+ UI.message("Getting ID of version named '#{version_name}'...")
113
+ return -1 if version_name == "Unscheduled"
114
+
115
+ path = "#{@jira_api}/project/#{@project}/versions"
116
+
117
+ response = HTTParty.get(path, { basic_auth: @credentials })
118
+ UI.user_error!("Can't get versions of project #{@project}. Expected code 200, got #{response.code}") unless response.code == 200
119
+ parsed = JSON.parse(response.body)
120
+
121
+ parsed.each do |version|
122
+ return version["id"] if version["name"] == version_name
123
+ end
124
+
125
+ UI.user_error!("Version '#{version_name}' couldn't be found!")
126
+ end
127
+
128
+ def get_cycle_id(cycle_name:, version_id:)
129
+ UI.message("Checking if '#{cycle_name}' cycle already exists...")
130
+ path = "#{@zephyr_api}/cycle?projectId=#{@project}&versionId=#{version_id}"
131
+
132
+ response = HTTParty.get(path, { basic_auth: @credentials })
133
+ UI.user_error!("Can't get cycles of project #{@project} with version #{version_id}. Expected code 200, got #{response.code}") unless response.code == 200
134
+ parsed = JSON.parse(response.body)
135
+
136
+ parsed.each do |id, cycle|
137
+ next if id == "recordsCount"
138
+ return id if cycle["name"] == cycle_name
139
+ end
140
+
141
+ return nil
142
+ end
143
+
144
+ def create_cycle(cycle_name:, version_id:)
145
+ UI.message("Creating cycle '#{cycle_name}'...")
146
+ path = "#{@zephyr_api}/cycle"
147
+
148
+ today = Time.now.strftime("%e/%b/%y")
149
+ body = {
150
+ name: cycle_name,
151
+ projectId: @project,
152
+ versionId: version_id,
153
+ startDate: today,
154
+ endDate: today,
155
+ }
156
+
157
+ response = HTTParty.post(path, { basic_auth: @credentials, headers: { "Content-Type": "application/json" }, body: body.to_json })
158
+ UI.user_error!("Can't create cycle '#{cycle_name}'. Expected code 200, got #{response.code}") unless response.code == 200
159
+ parsed = JSON.parse(response.body)
160
+
161
+ return parsed["id"]
162
+ end
163
+
164
+ def get_ticket_id(ticket_number:)
165
+ path = "#{@jira_api}/issue/#{ticket_number}"
166
+
167
+ response = HTTParty.get(path, { basic_auth: @credentials })
168
+ UI.user_error!("Can't get ticket ID of '#{ticket_number}'. Expected code 200, got #{response.code}") unless response.code == 200
169
+ parsed = JSON.parse(response.body)
170
+
171
+ return parsed["id"]
172
+ end
173
+ end
174
+ end
175
+ end
@@ -0,0 +1,5 @@
1
+ module Fastlane
2
+ module AllureZephyr
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,174 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fastlane-plugin-allure_zephyr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nikita Ianenko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-05-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec_junit_formatter
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 0.49.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 0.49.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-require_tools
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: fastlane
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: 2.170.0
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: 2.170.0
139
+ description:
140
+ email: yanenko@hotmail.com
141
+ executables: []
142
+ extensions: []
143
+ extra_rdoc_files: []
144
+ files:
145
+ - LICENSE
146
+ - README.md
147
+ - lib/fastlane/plugin/allure_zephyr.rb
148
+ - lib/fastlane/plugin/allure_zephyr/actions/allure_zephyr_action.rb
149
+ - lib/fastlane/plugin/allure_zephyr/helper/allure_zephyr_helper.rb
150
+ - lib/fastlane/plugin/allure_zephyr/version.rb
151
+ homepage: https://github.com/sokecze/fastlane-plugin-allure_zephyr
152
+ licenses:
153
+ - MIT
154
+ metadata: {}
155
+ post_install_message:
156
+ rdoc_options: []
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ requirements: []
170
+ rubygems_version: 3.1.4
171
+ signing_key:
172
+ specification_version: 4
173
+ summary: Publish Allure results to Zephyr
174
+ test_files: []