browser_review_gate 0.5.1 → 0.5.2
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 +10 -0
- data/README.md +2 -0
- 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 +19 -8
- 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: 294c10fc153a1a94639ddca7782e91c71571251286996f68f5134c2c3715ac82
|
|
4
|
+
data.tar.gz: 8f28eef0a92edbb82eb30177227ed453ac036013844f850ffe2909ec78921acb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 12aa9c2d7b5e4dac088ea242d121fac94c19ad2f1587eee44ee579a3d3025709fa7fe3fecbe7f8695b22dd4fe998d27e07cfa203b5586e7f6591759ea62833fa
|
|
7
|
+
data.tar.gz: 0b5e89bb53695756ecd1c1a3fe81f1354538a01264d005e637a7361ccc0a7f3e3cb30dbea9f0ff5b6298038c28be6e04958444a04a51d57146d05f8e8b04f0fd
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.2
|
|
4
|
+
|
|
5
|
+
- A waiver is visible: the gate writes one PR comment saying who waived the run and that later pushes
|
|
6
|
+
do not hold review, and removes it with the label.
|
|
7
|
+
- A waived PR is not assessed: a new commit no longer drops `browser-verified`, posts "Browser run
|
|
8
|
+
needed" or pings the author, and in `ci` mode calls no model.
|
|
9
|
+
- Removing a gate label triggers the workflow (`unlabeled`), so taking a waiver back puts review on
|
|
10
|
+
hold at once. Re-run `browser-review-gate install` to update the workflow.
|
|
11
|
+
- `doctor` fails when the waiver label does not exist and prints the `gh label create` command.
|
|
12
|
+
|
|
3
13
|
## 0.5.1
|
|
4
14
|
|
|
5
15
|
- 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.
|
|
@@ -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 = "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.
|
|
@@ -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.2
|
|
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
|