browser_review_gate 0.5.1 → 0.5.3
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 +4 -4
- data/CHANGELOG.md +16 -0
- data/README.md +2 -0
- data/lib/browser_review_gate/assessment.rb +1 -1
- data/lib/browser_review_gate/assessor.rb +6 -0
- data/lib/browser_review_gate/doctor.rb +12 -0
- data/lib/browser_review_gate/gate.rb +20 -9
- data/lib/browser_review_gate/markdown.rb +5 -0
- data/lib/browser_review_gate/publisher.rb +3 -3
- data/lib/browser_review_gate/templates/workflow.yml.erb +3 -3
- data/lib/browser_review_gate/version.rb +1 -1
- data/lib/browser_review_gate/waiver.rb +17 -0
- data/lib/browser_review_gate.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fa41c3531805de8375cd86b4251457ed78e065eec4ca8e5a02f6adb2196d6dc2
|
|
4
|
+
data.tar.gz: d8459a362a7b71375a0c2d9ea12e7fb5a50b30883de73ddacb69c96825a761d9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7938e08099e7a40edb047df2957e51fd53d339662aa1ac20f9ba2c6a62ac979e1723986347b76f9646ddaa0364138306b4c72106a52beec40b07650e12203150
|
|
7
|
+
data.tar.gz: b4b2284f88a75f1d23accdd782501bc12b3e31ae71e787fa964a5c70bdb974c405d89da262aea8f9c60485be7e26924769bdfedaf9dab735f622e4b63579d505
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.3
|
|
4
|
+
|
|
5
|
+
- Every comment the gem writes opens with one line saying `browser_review_gate` wrote it: the
|
|
6
|
+
assessment, the published report, the paused-review notice and the waiver notice. A published
|
|
7
|
+
report is posted from the developer's account, so without it the comment read as theirs.
|
|
8
|
+
|
|
9
|
+
## 0.5.2
|
|
10
|
+
|
|
11
|
+
- A waiver is visible: the gate writes one PR comment saying who waived the run and that later pushes
|
|
12
|
+
do not hold review, and removes it with the label.
|
|
13
|
+
- A waived PR is not assessed: a new commit no longer drops `browser-verified`, posts "Browser run
|
|
14
|
+
needed" or pings the author, and in `ci` mode calls no model.
|
|
15
|
+
- Removing a gate label triggers the workflow (`unlabeled`), so taking a waiver back puts review on
|
|
16
|
+
hold at once. Re-run `browser-review-gate install` to update the workflow.
|
|
17
|
+
- `doctor` fails when the waiver label does not exist and prints the `gh label create` command.
|
|
18
|
+
|
|
3
19
|
## 0.5.1
|
|
4
20
|
|
|
5
21
|
- With `assessment: local` the installer writes the workflow without the model secrets: that mode
|
data/README.md
CHANGED
|
@@ -51,6 +51,8 @@ Then:
|
|
|
51
51
|
|
|
52
52
|
Later commits keep the verification unless they add a scenario no counting case covers; then only the new scenarios need to run (`scenarios.reuse_passing`).
|
|
53
53
|
|
|
54
|
+
When a run is not possible or no longer worth it, someone other than the author adds the `browser-verification-waived` label. Review proceeds, later pushes do not hold it, and one PR comment says who waived it; removing the label requires a run again. `browser-review-gate doctor` checks that the label exists, since GitHub creates a label only when the gate adds it.
|
|
55
|
+
|
|
54
56
|
## Two modes
|
|
55
57
|
|
|
56
58
|
`assessment` chooses who decides what a browser run must cover.
|
|
@@ -128,7 +128,7 @@ module BrowserReviewGate
|
|
|
128
128
|
# them to do something. `report` and `commits` give each scenario its status.
|
|
129
129
|
def markdown(verified:, command:, author: nil, report: nil, commits: nil)
|
|
130
130
|
payload = Marker.encode(JSON.generate(to_h))
|
|
131
|
-
[ "## Browser verification", "", summary(verified, command, author, report, commits), "",
|
|
131
|
+
[ Markdown::SIGNATURE, "", "## Browser verification", "", summary(verified, command, author, report, commits), "",
|
|
132
132
|
"Assessed commit `#{assessed_sha}`.", "", "<!-- browser-verification-assessment:#{payload} -->" ].join("\n")
|
|
133
133
|
end
|
|
134
134
|
|
|
@@ -43,7 +43,13 @@ module BrowserReviewGate
|
|
|
43
43
|
|
|
44
44
|
# Returns the assessment for the PR head. The model is asked when the head has no decision yet, or
|
|
45
45
|
# when a report it has not judged lacks some of its scenarios; the comment is refreshed either way.
|
|
46
|
+
# A waived PR is not assessed (nil): a new commit neither drops the label nor pings anyone.
|
|
46
47
|
def assess(number, pull_request: @github.pull_request(number), comments: @github.trusted_comments(number))
|
|
48
|
+
if (waived_by = Waiver.new(github: @github, config: @config).by(number, pull_request))
|
|
49
|
+
@log.puts "Browser verification waived by #{waived_by}; the PR is not assessed."
|
|
50
|
+
return
|
|
51
|
+
end
|
|
52
|
+
|
|
47
53
|
head_sha = pull_request.fetch("head").fetch("sha")
|
|
48
54
|
report = Report.latest(comments, config: @config)
|
|
49
55
|
commits = @github.pull_request_commits(number)
|
|
@@ -42,6 +42,7 @@ module BrowserReviewGate
|
|
|
42
42
|
browser_tools(config)
|
|
43
43
|
workflow(config) if config
|
|
44
44
|
required_check(config) if config && gh_ready
|
|
45
|
+
labels(config) if config && gh_ready
|
|
45
46
|
provider_secrets(config) if config && gh_ready
|
|
46
47
|
@checks
|
|
47
48
|
end
|
|
@@ -236,6 +237,17 @@ module BrowserReviewGate
|
|
|
236
237
|
add("required check", "SKIP", "could not be checked")
|
|
237
238
|
end
|
|
238
239
|
|
|
240
|
+
# The gate adds its own label, and GitHub creates it then; a waiver is added by a person, so its label must exist.
|
|
241
|
+
def labels(config)
|
|
242
|
+
github = @github || GitHub.new(shell: @shell)
|
|
243
|
+
names = run("gh", "api", "repos/#{github.repository}/labels", "--paginate", "--jq", ".[].name")
|
|
244
|
+
return add("labels", "SKIP", "repository labels could not be read") unless names
|
|
245
|
+
return add("labels", "PASS", "#{config.waiver_label} exists") if names.lines.map(&:strip).include?(config.waiver_label)
|
|
246
|
+
|
|
247
|
+
add("labels", "FAIL", "#{config.waiver_label} does not exist, so nobody can waive a run",
|
|
248
|
+
%(gh label create #{config.waiver_label} --description "Review may proceed without a browser run"))
|
|
249
|
+
end
|
|
250
|
+
|
|
239
251
|
def provider_secrets(config)
|
|
240
252
|
return add("model credentials", "SKIP", "not needed: assessment is local, CI calls no model") if config.local?
|
|
241
253
|
|
|
@@ -6,6 +6,7 @@ module BrowserReviewGate
|
|
|
6
6
|
# it is made; the people it named are remembered in one PR comment.
|
|
7
7
|
class Gate
|
|
8
8
|
PAUSED = /<!--\s*browser-review-gate:paused:([A-Za-z0-9_-]+)\s*-->/
|
|
9
|
+
WAIVED = /<!--\s*browser-review-gate:waived\s*-->/
|
|
9
10
|
|
|
10
11
|
def initialize(github:, config: Config.new, log: $stdout)
|
|
11
12
|
@github = github
|
|
@@ -21,8 +22,10 @@ module BrowserReviewGate
|
|
|
21
22
|
assessment = Assessment.latest(comments)
|
|
22
23
|
assessment = nil unless assessment&.for?(head_sha)
|
|
23
24
|
|
|
24
|
-
|
|
25
|
+
waived_by = Waiver.new(github: @github, config: @config).by(number, pull_request)
|
|
26
|
+
verdict, description = verdict(number, pull_request, comments, assessment, waived_by)
|
|
25
27
|
report_status(head_sha, verdict, description)
|
|
28
|
+
waiver_notice(number, comments, waived_by)
|
|
26
29
|
@log.puts description
|
|
27
30
|
if verdict == :open
|
|
28
31
|
restore_requests(number, pull_request, comments)
|
|
@@ -34,8 +37,7 @@ module BrowserReviewGate
|
|
|
34
37
|
|
|
35
38
|
private
|
|
36
39
|
|
|
37
|
-
def verdict(number, pull_request, comments, assessment)
|
|
38
|
-
waived_by = waiver(number, pull_request)
|
|
40
|
+
def verdict(number, pull_request, comments, assessment, waived_by)
|
|
39
41
|
return [ :open, "Browser verification waived by #{waived_by}." ] if waived_by
|
|
40
42
|
return [ :closed, "The browser-testing assessment for this commit is not available." ] unless assessment
|
|
41
43
|
return [ :open, "Browser verification is not needed." ] unless assessment.required?
|
|
@@ -56,12 +58,21 @@ module BrowserReviewGate
|
|
|
56
58
|
assessment.covered_by?(report, commits: @github.pull_request_commits(number), reuse_passing: @config.scenarios["reuse_passing"], fresh: fresh)
|
|
57
59
|
end
|
|
58
60
|
|
|
59
|
-
#
|
|
60
|
-
def
|
|
61
|
-
|
|
61
|
+
# One comment says who waived the run and that later pushes no longer hold review; it goes with the label.
|
|
62
|
+
def waiver_notice(number, comments, waived_by)
|
|
63
|
+
comment = comments.find { |item| item.dig("user", "login") == Assessment::AUTHOR && item["body"].to_s.match?(WAIVED) }
|
|
64
|
+
return comment && @github.delete_comment(comment.fetch("id")) unless waived_by
|
|
62
65
|
|
|
63
|
-
|
|
64
|
-
|
|
66
|
+
body = Markdown.signed("Browser verification waived by #{Markdown.escape(waived_by)}: review proceeds without a browser run. " \
|
|
67
|
+
"Later pushes do not hold review. Remove the `#{@config.waiver_label}` label to require a run again.\n\n" \
|
|
68
|
+
"<!-- browser-review-gate:waived -->")
|
|
69
|
+
if comment.nil?
|
|
70
|
+
@github.create_comment(number, body)
|
|
71
|
+
elsif comment["body"] != body
|
|
72
|
+
@github.update_comment(comment.fetch("id"), body)
|
|
73
|
+
end
|
|
74
|
+
rescue Error => error
|
|
75
|
+
@log.puts "The waiver comment was not updated: #{error.message.lines.first.to_s.strip}"
|
|
65
76
|
end
|
|
66
77
|
|
|
67
78
|
# A workflow installed before statuses were added has no permission to write them.
|
|
@@ -132,7 +143,7 @@ module BrowserReviewGate
|
|
|
132
143
|
end
|
|
133
144
|
|
|
134
145
|
def write_notice(number, comments, text, waiting)
|
|
135
|
-
body = "#{text}\n\n<!-- browser-review-gate:paused:#{Marker.encode(JSON.generate(waiting))} -->"
|
|
146
|
+
body = Markdown.signed("#{text}\n\n<!-- browser-review-gate:paused:#{Marker.encode(JSON.generate(waiting))} -->")
|
|
136
147
|
comment = notice_comment(comments)
|
|
137
148
|
if comment.nil?
|
|
138
149
|
@github.create_comment(number, body)
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
module BrowserReviewGate
|
|
2
2
|
module Markdown
|
|
3
|
+
# The first line of every comment the gem writes, so a reader knows a tool wrote it, not a person.
|
|
4
|
+
SIGNATURE = "<sub>🤖 Written by [browser_review_gate](https://github.com/Halvanhelv/browser_review_gate)</sub>"
|
|
5
|
+
|
|
6
|
+
def self.signed(text) = "#{SIGNATURE}\n\n#{text}"
|
|
7
|
+
|
|
3
8
|
# Comment text comes from a model or a report file, so it must not start markup or ping anyone.
|
|
4
9
|
# "@login " for each person, so a comment that needs them reaches their notifications. Bots and
|
|
5
10
|
# anything that is not a plain login get no mention.
|
|
@@ -151,10 +151,10 @@ module BrowserReviewGate
|
|
|
151
151
|
end
|
|
152
152
|
|
|
153
153
|
def body(report, complete, commits)
|
|
154
|
-
return report.markdown(commits: commits) if complete
|
|
154
|
+
return Markdown.signed(report.markdown(commits: commits)) if complete
|
|
155
155
|
|
|
156
|
-
[ "**Not verified.** Complete every required browser scenario and pass all reported cases before human review.",
|
|
157
|
-
"", report.markdown(commits: commits) ].join("\n")
|
|
156
|
+
Markdown.signed([ "**Not verified.** Complete every required browser scenario and pass all reported cases before human review.",
|
|
157
|
+
"", report.markdown(commits: commits) ].join("\n"))
|
|
158
158
|
end
|
|
159
159
|
|
|
160
160
|
# Only the author's own earlier report comment can be edited in place.
|
|
@@ -18,7 +18,7 @@ name: Browser review gate
|
|
|
18
18
|
|
|
19
19
|
on:
|
|
20
20
|
pull_request_target:
|
|
21
|
-
types: [opened, reopened, synchronize, ready_for_review, review_requested, labeled]
|
|
21
|
+
types: [opened, reopened, synchronize, ready_for_review, review_requested, labeled, unlabeled]
|
|
22
22
|
workflow_dispatch:
|
|
23
23
|
inputs:
|
|
24
24
|
pr_number:
|
|
@@ -39,10 +39,10 @@ concurrency:
|
|
|
39
39
|
jobs:
|
|
40
40
|
gate:
|
|
41
41
|
# A draft is assessed when it is marked ready, or when someone asks by hand (workflow_dispatch).
|
|
42
|
-
# Of all labels, only the two that open the gate matter: a published run and a waiver.
|
|
42
|
+
# Of all labels, only the two that open the gate matter, added or removed: a published run and a waiver.
|
|
43
43
|
if: >-
|
|
44
44
|
(github.event_name == 'workflow_dispatch' || !github.event.pull_request.draft) &&
|
|
45
|
-
(github.event.action
|
|
45
|
+
(!contains(fromJSON('["labeled","unlabeled"]'), github.event.action) ||
|
|
46
46
|
contains(fromJSON('<%= JSON.generate(gate_labels) %>'), github.event.label.name))
|
|
47
47
|
runs-on: ubuntu-latest
|
|
48
48
|
timeout-minutes: 10
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module BrowserReviewGate
|
|
2
|
+
# Who waived browser verification on a PR. A waiver counts only from someone other than the author,
|
|
3
|
+
# unless the project allows otherwise.
|
|
4
|
+
class Waiver
|
|
5
|
+
def initialize(github:, config:)
|
|
6
|
+
@github = github
|
|
7
|
+
@config = config
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def by(number, pull_request)
|
|
11
|
+
return unless pull_request.fetch("labels").any? { |label| label["name"] == @config.waiver_label }
|
|
12
|
+
|
|
13
|
+
actor = @github.label_actor(number, @config.waiver_label)
|
|
14
|
+
actor if actor && (@config.waiver_by_author || actor != pull_request.dig("user", "login"))
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
data/lib/browser_review_gate.rb
CHANGED
|
@@ -29,6 +29,7 @@ module BrowserReviewGate
|
|
|
29
29
|
autoload :TraceCheck, File.join(__dir__, "browser_review_gate/trace_check")
|
|
30
30
|
autoload :ZipReader, File.join(__dir__, "browser_review_gate/zip_reader")
|
|
31
31
|
autoload :Verify, File.join(__dir__, "browser_review_gate/verify")
|
|
32
|
+
autoload :Waiver, File.join(__dir__, "browser_review_gate/waiver")
|
|
32
33
|
autoload :Config, File.join(__dir__, "browser_review_gate/config")
|
|
33
34
|
autoload :Freshness, File.join(__dir__, "browser_review_gate/freshness")
|
|
34
35
|
autoload :Gate, File.join(__dir__, "browser_review_gate/gate")
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: browser_review_gate
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.
|
|
4
|
+
version: 0.5.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Islam Gagiev
|
|
@@ -72,6 +72,7 @@ files:
|
|
|
72
72
|
- lib/browser_review_gate/trace_check.rb
|
|
73
73
|
- lib/browser_review_gate/verify.rb
|
|
74
74
|
- lib/browser_review_gate/version.rb
|
|
75
|
+
- lib/browser_review_gate/waiver.rb
|
|
75
76
|
- lib/browser_review_gate/zip_reader.rb
|
|
76
77
|
- lib/generators/browser_review_gate/install/install_generator.rb
|
|
77
78
|
homepage: https://github.com/Halvanhelv/browser_review_gate
|