gergich 2.1.5 → 2.2.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 +4 -4
- data/lib/gergich/cli/gergich.rb +2 -1
- data/lib/gergich/cli/master_bouncer.rb +15 -4
- data/lib/gergich.rb +18 -5
- data/lib/logging.rb +26 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d16295d82fb11923e2cb49cb0656420e3235d4a08cc573e34436ec32a341870
|
4
|
+
data.tar.gz: 2019c58f7af8b708787e27c05f6a41c99e927128d9288461b913fd90f129461c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f99d44011d1358420564a0ffc7b2846c1ddd536e41f183c1e2da9a330e0a690bb25dc2110c5b5d4bae00bf6d5ffc166652229012dfa817047fd6d909e838f93
|
7
|
+
data.tar.gz: ed476739a4a99eafba3362a38c439cca37a08130ef81818e1537abe3112189a15b905eb636c9cb3f3fb628a10d7681427e48ce835c8e97e4cbdd81410f795bec
|
data/lib/gergich/cli/gergich.rb
CHANGED
@@ -9,6 +9,9 @@ MASTER_BOUNCER_REVIEW_LABEL = ENV.fetch("GERGICH_REVIEW_LABEL", "Code-Review")
|
|
9
9
|
require_relative "../../gergich"
|
10
10
|
|
11
11
|
PROJECT = ENV["GERRIT_PROJECT"] || error("no GERRIT_PROJECT set")
|
12
|
+
# on Jenkins GERRIT_MAIN_BRANCH env var will default to empty string if not set
|
13
|
+
MAIN_BRANCH = ENV["GERRIT_MAIN_BRANCH"].nil? || ENV["GERRIT_MAIN_BRANCH"].empty? ? "master" :
|
14
|
+
ENV["GERRIT_MAIN_BRANCH"]
|
12
15
|
# TODO: time-based thresholds
|
13
16
|
WARN_DISTANCE = ENV.fetch("MASTER_BOUNCER_WARN_DISTANCE", 50).to_i
|
14
17
|
ERROR_DISTANCE = ENV.fetch("MASTER_BOUNCER_ERROR_DISTANCE", 100).to_i
|
@@ -17,7 +20,7 @@ def potentially_mergeable_changes
|
|
17
20
|
url = "/changes/?q=status:open+" \
|
18
21
|
"p:#{PROJECT}+" \
|
19
22
|
"label:Verified=1+" \
|
20
|
-
"branch
|
23
|
+
"branch:#{MAIN_BRANCH}" \
|
21
24
|
"&o=CURRENT_REVISION"
|
22
25
|
changes = Gergich::API.get(url)
|
23
26
|
changes.reject { |c| c["subject"] =~ /\Awip($|\W)/i }
|
@@ -27,8 +30,8 @@ def maybe_bounce_commit!(commit)
|
|
27
30
|
draft = Gergich::Draft.new(commit)
|
28
31
|
draft.reset!
|
29
32
|
|
30
|
-
distance = Gergich.git("rev-list origin
|
31
|
-
detail = "#{distance} commits behind
|
33
|
+
distance = Gergich.git("rev-list origin/#{MAIN_BRANCH} ^#{commit.ref} --count").to_i
|
34
|
+
detail = "#{distance} commits behind #{MAIN_BRANCH}"
|
32
35
|
|
33
36
|
score = 0
|
34
37
|
message = nil
|
@@ -84,10 +87,18 @@ commands["check"] = {
|
|
84
87
|
commands["check_all"] = {
|
85
88
|
summary: "Check the age of all potentially mergeable changes",
|
86
89
|
action: -> {
|
87
|
-
Gergich.git("fetch")
|
88
90
|
gerrit_host = ENV["GERRIT_HOST"] || error("No GERRIT_HOST set")
|
91
|
+
Gergich.git("fetch")
|
89
92
|
|
90
93
|
changes = potentially_mergeable_changes
|
94
|
+
# if changes is empty or nil, we don't need to iterate over it
|
95
|
+
# log that we're skipping, and return
|
96
|
+
if changes.nil? || changes.empty?
|
97
|
+
Logging.logger.info "No changes to check"
|
98
|
+
return
|
99
|
+
end
|
100
|
+
Logging.logger.info "Checking #{changes.size} changes"
|
101
|
+
|
91
102
|
next if ENV["DRY_RUN"]
|
92
103
|
|
93
104
|
changes.each do |change|
|
data/lib/gergich.rb
CHANGED
@@ -4,6 +4,8 @@ require "erb"
|
|
4
4
|
require "json"
|
5
5
|
require "fileutils"
|
6
6
|
require "base64"
|
7
|
+
require "open3"
|
8
|
+
require_relative "logging"
|
7
9
|
|
8
10
|
GERGICH_REVIEW_LABEL = ENV.fetch("GERGICH_REVIEW_LABEL", "Code-Review")
|
9
11
|
GERGICH_USER = ENV.fetch("GERGICH_USER", "gergich")
|
@@ -12,24 +14,35 @@ GERGICH_GIT_PATH = ENV.fetch("GERGICH_GIT_PATH", ".")
|
|
12
14
|
GergichError = Class.new(StandardError)
|
13
15
|
|
14
16
|
module Gergich
|
17
|
+
include Logging
|
15
18
|
def self.use_git?
|
16
|
-
|
17
|
-
system "git rev-parse --show-toplevel >/dev/null 2>&1"
|
18
|
-
end
|
19
|
+
!git("rev-parse --show-toplevel").nil?
|
19
20
|
end
|
20
21
|
|
21
22
|
def self.git(args)
|
22
23
|
Dir.chdir(GERGICH_GIT_PATH) do
|
23
|
-
|
24
|
+
raise(GergichError, "git not installed") unless system("which git > /dev/null 2>&1")
|
25
|
+
|
26
|
+
output, error, status = Open3.capture3("git #{args}")
|
27
|
+
if status.success?
|
28
|
+
Logging.logger.debug "git #{args}: #{output}"
|
29
|
+
output
|
30
|
+
else
|
31
|
+
Logging.logger.warn "Output: #{output}"
|
32
|
+
Logging.logger.warn "git #{args} failed: #{error}"
|
33
|
+
nil
|
34
|
+
end
|
24
35
|
end
|
25
36
|
end
|
26
37
|
|
27
38
|
class Commit
|
39
|
+
include Logging
|
28
40
|
attr_reader :ref
|
29
41
|
|
30
42
|
def initialize(ref = ENV.fetch("GERRIT_PATCHSET_REVISION", "HEAD"), revision_number = nil)
|
31
43
|
@ref = ref
|
32
44
|
@revision_number = revision_number
|
45
|
+
logger.debug "Commit initialized with ref: #{ref}"
|
33
46
|
end
|
34
47
|
|
35
48
|
def info
|
@@ -89,7 +102,7 @@ module Gergich
|
|
89
102
|
class Review
|
90
103
|
attr_reader :commit, :draft
|
91
104
|
|
92
|
-
def initialize(commit = Commit.new, draft = Draft.new)
|
105
|
+
def initialize(commit = Commit.new, draft = Draft.new(commit))
|
93
106
|
@commit = commit
|
94
107
|
@draft = draft
|
95
108
|
end
|
data/lib/logging.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: false
|
2
|
+
|
3
|
+
require "logger"
|
4
|
+
|
5
|
+
module Logging
|
6
|
+
def logger
|
7
|
+
Logging.logger
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.logger
|
11
|
+
@logger ||= Logger.new($stdout)
|
12
|
+
@logger.formatter = proc do |severity, datetime, _progname, msg|
|
13
|
+
datefmt = datetime.strftime("%Y-%m-%d %H:%M:%S")
|
14
|
+
# ensure that there is only one newline at the end of the message
|
15
|
+
"#{severity} [#{datefmt}]: #{msg}\n".gsub!(/\n+/, "\n")
|
16
|
+
end
|
17
|
+
@logger
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.log_level
|
21
|
+
# default to only showing errors
|
22
|
+
ENV.fetch("RUBY_LOG_LEVEL", "ERROR")
|
23
|
+
end
|
24
|
+
|
25
|
+
logger.level = log_level
|
26
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gergich
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Jensen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-06-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -169,6 +169,7 @@ files:
|
|
169
169
|
- lib/gergich/cli.rb
|
170
170
|
- lib/gergich/cli/gergich.rb
|
171
171
|
- lib/gergich/cli/master_bouncer.rb
|
172
|
+
- lib/logging.rb
|
172
173
|
homepage: https://github.com/instructure/gergich
|
173
174
|
licenses:
|
174
175
|
- MIT
|
@@ -188,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
188
189
|
- !ruby/object:Gem::Version
|
189
190
|
version: '0'
|
190
191
|
requirements: []
|
191
|
-
rubygems_version: 3.
|
192
|
+
rubygems_version: 3.3.26
|
192
193
|
signing_key:
|
193
194
|
specification_version: 4
|
194
195
|
summary: Command-line tool for adding Gerrit comments
|