allure-report-publisher 0.1.1 → 0.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: 9bb81eada76c7024e4a570187d02e2383677552daef81b14e1e1457ca2fbc6be
4
- data.tar.gz: 27db25caad167473b073a6057f82981d648889d800c3fddb879c3c046d5dc951
3
+ metadata.gz: 4b5ab2c7fe9d71734c9f57324a411d2dfb3034a63152e75a3827f3629375371b
4
+ data.tar.gz: 56296208184a82b42bfb04c7132788e6b4f924be16c4059a4e03e6782f9f54f2
5
5
  SHA512:
6
- metadata.gz: 5b3d2e2a7faa93ad323cb24ea892aeb3601c904e30c4fdadaf78732bd903945c7ba2e488440bb5a1d834e0ec62a1616c83aea48e697596edd02d271fcf8d0719
7
- data.tar.gz: 400d890b0e1b315d1aab1a246482a31849a38c3a78b231310ffc285b5fd14d677ee3b3badfcf098f9f15d982091f7d85dac6642f5e6b0d0bd2f7e1b5f1509510
6
+ metadata.gz: 60889df0f7995284adc34651a042f90f29a0a32f93895636b991205eafc078f696dd9f0117f28e3d85b111bf0d7fe84c4daa5a89f95a5cf4a295547a20c9c8b9
7
+ data.tar.gz: 0a5c6206ed052dd912b57e524190209993d5e58435a5ce4a28d3a1117fd4bc1191b6ae23d441ab2ec98588518bb18bba7aa9b3a9a2b6ed6fdd6c42480d0614ec
data/README.md CHANGED
@@ -31,7 +31,7 @@ docker pull andrcuns/allure-report-publisher:latest
31
31
 
32
32
  allure-report-publisher will automatically detect if used in CI environment and add relevant executor info and history
33
33
 
34
- - `Allure report link`: requires `GITHUB_AUTH_TOKEN` or `GITLAB_AUTH_TOKEN` in order to update pull request description with link to latest report
34
+ - `--update-pr=(comment|description)`: requires `GITHUB_AUTH_TOKEN` or `GITLAB_AUTH_TOKEN` in order to update pull request with links to allure reports
35
35
 
36
36
  ```shell
37
37
  $ (allure-report-publisher|docker run --rm andrcuns/allure-report-publisher:latest) upload --help
@@ -13,7 +13,6 @@ module Publisher
13
13
  # Base class for CI executor info
14
14
  #
15
15
  class Provider
16
- DESCRIPTION_PATTERN = /<!-- allure -->[\s\S]+<!-- allurestop -->/.freeze
17
16
  ALLURE_JOB_NAME = "ALLURE_JOB_NAME".freeze
18
17
 
19
18
  def initialize(report_url:, update_pr:)
@@ -82,20 +81,20 @@ module Publisher
82
81
  raise("Not implemented!")
83
82
  end
84
83
 
85
- # Commit SHA url
84
+ # Build name
86
85
  #
87
86
  # @return [String]
88
- def sha_url
87
+ def build_name
89
88
  raise("Not implemented!")
90
89
  end
91
- # :nocov:
92
90
 
93
- # Add report url as comment
91
+ # Commit SHA url
94
92
  #
95
- # @return [Boolean]
96
- def comment?
97
- update_pr == "comment"
93
+ # @return [String]
94
+ def sha_url
95
+ raise("Not implemented!")
98
96
  end
97
+ # :nocov:
99
98
 
100
99
  # CI run id
101
100
  #
@@ -104,70 +103,18 @@ module Publisher
104
103
  self.class.run_id
105
104
  end
106
105
 
107
- # Check if PR already has report urls
106
+ # Add report url as comment
108
107
  #
109
108
  # @return [Boolean]
110
- def reported?
111
- @reported ||= pr_description.match?(DESCRIPTION_PATTERN)
112
- end
113
-
114
- # Full PR description
115
- #
116
- # @return [String]
117
- def updated_pr_description
118
- reported? ? existing_pr_description : initial_pr_descripion
119
- end
120
-
121
- # Updated PR description
122
- #
123
- # @return [String]
124
- def existing_pr_description
125
- pr_description.gsub(DESCRIPTION_PATTERN, pr_body).strip
126
- end
127
-
128
- # Initial PR description
129
- #
130
- # @return [String]
131
- def initial_pr_descripion
132
- "#{pr_description}\n\n#{pr_body}".strip
133
- end
134
-
135
- # Heading for report urls
136
- #
137
- # @return [String]
138
- def heading
139
- @heading ||= <<~HEADING.strip
140
- # Allure report
141
- `allure-report-publisher` generated allure report for #{sha_url}!
142
- HEADING
143
- end
144
-
145
- # Allure report url pr description
146
- #
147
- # @return [String]
148
- def pr_body
149
- @pr_body ||= <<~DESC
150
- <!-- allure -->
151
- ---
152
- #{heading}
153
-
154
- #{job_entry}
155
- <!-- allurestop -->
156
- DESC
157
- end
158
-
159
- # Allure report url comment body
160
- #
161
- # @return [String]
162
- def comment_body
163
- @comment_body ||= pr_body.gsub("---\n", "")
109
+ def comment?
110
+ update_pr == "comment"
164
111
  end
165
112
 
166
- # Single job report URL entry
113
+ # Report urls section creator
167
114
  #
168
- # @return [String]
169
- def job_entry
170
- @job_entry ||= "**#{build_name}**: 📝 [allure report](#{report_url})"
115
+ # @return [ReportUrls]
116
+ def report_urls
117
+ @report_urls ||= UrlSectionBuilder.new(report_url: report_url, build_name: build_name, sha_url: sha_url)
171
118
  end
172
119
  end
173
120
  end
@@ -58,16 +58,16 @@ module Publisher
58
58
  #
59
59
  # @return [void]
60
60
  def update_pr_description
61
- client.update_pull_request(repository, pr_id, body: updated_pr_description)
61
+ client.update_pull_request(repository, pr_id, body: report_urls.updated_pr_description(pr_description))
62
62
  end
63
63
 
64
64
  # Add comment with report url
65
65
  #
66
66
  # @return [void]
67
67
  def add_comment
68
- return client.add_comment(repository, pr_id, comment_body) unless comment
68
+ return client.add_comment(repository, pr_id, report_urls.comment_body) unless comment
69
69
 
70
- client.update_comment(repository, comment[:id], comment_body)
70
+ client.update_comment(repository, comment[:id], report_urls.comment_body(comment[:body]))
71
71
  end
72
72
 
73
73
  # Existing comment with allure urls
@@ -75,7 +75,7 @@ module Publisher
75
75
  # @return [Sawyer::Resource]
76
76
  def comment
77
77
  @comment ||= client.issue_comments(repository, pr_id).detect do |comment|
78
- comment[:body].match?(DESCRIPTION_PATTERN)
78
+ UrlSectionBuilder.match?(comment[:body])
79
79
  end
80
80
  end
81
81
 
@@ -48,16 +48,16 @@ module Publisher
48
48
  #
49
49
  # @return [void]
50
50
  def update_pr_description
51
- client.update_merge_request(project, mr_iid, description: updated_pr_description)
51
+ client.update_merge_request(project, mr_iid, description: report_urls.updated_pr_description(pr_description))
52
52
  end
53
53
 
54
54
  # Add comment with report url
55
55
  #
56
56
  # @return [void]
57
57
  def add_comment
58
- return client.create_merge_request_comment(project, mr_iid, comment_body) unless comment
58
+ return client.create_merge_request_comment(project, mr_iid, report_urls.comment_body) unless comment
59
59
 
60
- client.edit_merge_request_note(project, mr_iid, comment.id, comment_body)
60
+ client.edit_merge_request_note(project, mr_iid, comment.id, report_urls.comment_body(comment.body))
61
61
  end
62
62
 
63
63
  # Existing comment with allure urls
@@ -65,7 +65,7 @@ module Publisher
65
65
  # @return [Gitlab::ObjectifiedHash]
66
66
  def comment
67
67
  client.merge_request_comments(project, mr_iid).auto_paginate.detect do |comment|
68
- comment.body.match?(DESCRIPTION_PATTERN)
68
+ UrlSectionBuilder.match?(comment.body)
69
69
  end
70
70
  end
71
71
 
@@ -0,0 +1,97 @@
1
+ module Publisher
2
+ module Providers
3
+ # Urls section builder
4
+ #
5
+ class UrlSectionBuilder
6
+ DESCRIPTION_PATTERN = /<!-- allure -->[\s\S]+<!-- allurestop -->/.freeze
7
+ JOBS_PATTERN = /<!-- jobs -->\n([\s\S]+)\n<!-- jobs -->/.freeze
8
+
9
+ def initialize(report_url:, build_name:, sha_url:)
10
+ @report_url = report_url
11
+ @build_name = build_name
12
+ @sha_url = sha_url
13
+ end
14
+
15
+ # Matches url section pattern
16
+ #
17
+ # @param [String] urls_block
18
+ # @return [Boolean]
19
+ def self.match?(urls_block)
20
+ urls_block.match?(DESCRIPTION_PATTERN)
21
+ end
22
+
23
+ # Get urls for PR update
24
+ #
25
+ # @param [String] pr
26
+ # @return [String]
27
+ def updated_pr_description(pr_description)
28
+ return "#{pr_description}\n\n#{body}" unless pr_description.match?(DESCRIPTION_PATTERN)
29
+
30
+ job_entries = jobs_section(pr_description)
31
+ pr_description.gsub(DESCRIPTION_PATTERN, body(job_entries))
32
+ end
33
+
34
+ # Allure report url comment
35
+ #
36
+ # @return [String]
37
+ def comment_body(pr_comment = nil)
38
+ return body.gsub("---\n", "") unless pr_comment
39
+
40
+ job_entries = jobs_section(pr_comment)
41
+ body(job_entries).gsub("---\n", "")
42
+ end
43
+
44
+ attr_reader :report_url, :build_name, :sha_url
45
+
46
+ private
47
+
48
+ # Allure report url pr description
49
+ #
50
+ # @return [String]
51
+ def body(job_entries = "**#{build_name}**: 📝 [allure report](#{report_url})")
52
+ @body ||= <<~BODY.strip
53
+ <!-- allure -->
54
+ ---
55
+ #{heading}
56
+
57
+ <!-- jobs -->
58
+ #{job_entries}
59
+ <!-- jobs -->
60
+ <!-- allurestop -->
61
+ BODY
62
+ end
63
+
64
+ # Url section heading
65
+ #
66
+ # @return [String]
67
+ def heading
68
+ @heading ||= "# Allure report\n`allure-report-publisher` generated allure report for #{sha_url}!"
69
+ end
70
+
71
+ # Return updated jobs section
72
+ #
73
+ # @param [String] urls
74
+ # @return [String]
75
+ def jobs_section(urls_block)
76
+ jobs = urls_block.match(JOBS_PATTERN)[1]
77
+ return jobs.gsub(job_entry_pattern, job_entry) if jobs.match?(job_entry_pattern)
78
+
79
+ "#{jobs}\n#{job_entry}"
80
+ end
81
+
82
+ # Single job report URL entry
83
+ #
84
+ # @return [String]
85
+ def job_entry
86
+ @job_entry ||= "**#{build_name}**: 📝 [allure report](#{report_url})"
87
+ end
88
+
89
+ # Job entry pattern
90
+ #
91
+ # @return [RegExp]
92
+ def job_entry_pattern
93
+ @job_entry_pattern ||= /^\*\*#{build_name}\*\*:.*\[allure report\]\(.*\)$/
94
+ end
95
+ end
96
+ end
97
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Publisher
4
- VERSION = "0.1.1"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: allure-report-publisher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrejs Cunskis
@@ -166,6 +166,7 @@ files:
166
166
  - lib/allure_report_publisher/lib/providers/_provider.rb
167
167
  - lib/allure_report_publisher/lib/providers/github.rb
168
168
  - lib/allure_report_publisher/lib/providers/gitlab.rb
169
+ - lib/allure_report_publisher/lib/providers/url_section_builder.rb
169
170
  - lib/allure_report_publisher/lib/report_generator.rb
170
171
  - lib/allure_report_publisher/lib/uploaders/_uploader.rb
171
172
  - lib/allure_report_publisher/lib/uploaders/gcs.rb