summaryrefslogtreecommitdiff
path: root/qa/qa/resource/events
diff options
context:
space:
mode:
Diffstat (limited to 'qa/qa/resource/events')
-rw-r--r--qa/qa/resource/events/base.rb37
-rw-r--r--qa/qa/resource/events/project.rb25
2 files changed, 62 insertions, 0 deletions
diff --git a/qa/qa/resource/events/base.rb b/qa/qa/resource/events/base.rb
new file mode 100644
index 00000000000..b50b620b143
--- /dev/null
+++ b/qa/qa/resource/events/base.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+
+module QA
+ module Resource
+ module Events
+ MAX_WAIT = 10
+
+ EventNotFoundError = Class.new(RuntimeError)
+
+ module Base
+ def events(action: nil)
+ path = [api_get_events]
+ path << "?action=#{CGI.escape(action)}" if action
+ parse_body(api_get_from("#{path.join}"))
+ end
+
+ private
+
+ def api_get_events
+ "#{api_get_path}/events"
+ end
+
+ def wait_for_event
+ event_found = QA::Support::Waiter.wait(max: max_wait) do
+ yield
+ end
+
+ raise EventNotFoundError, "Timed out waiting for event" unless event_found
+ end
+
+ def max_wait
+ MAX_WAIT
+ end
+ end
+ end
+ end
+end
diff --git a/qa/qa/resource/events/project.rb b/qa/qa/resource/events/project.rb
new file mode 100644
index 00000000000..99c78254f42
--- /dev/null
+++ b/qa/qa/resource/events/project.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+module QA
+ module Resource
+ module Events
+ module Project
+ include Events::Base
+
+ def wait_for_push(commit_message)
+ QA::Runtime::Logger.debug(%Q[#{self.class.name} - wait_for_push with commit message "#{commit_message}"])
+ wait_for_event do
+ events(action: 'pushed').any? { |event| event.dig(:push_data, :commit_title) == commit_message }
+ end
+ end
+
+ def wait_for_push_new_branch(branch_name = "master")
+ QA::Runtime::Logger.debug(%Q[#{self.class.name} - wait_for_push_new_branch with branch_name "#{branch_name}"])
+ wait_for_event do
+ events(action: 'pushed').any? { |event| event.dig(:push_data, :ref) == branch_name }
+ end
+ end
+ end
+ end
+ end
+end