Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-08-31 15:11:07 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-08-31 15:11:07 +0300
commita9ae162270049d3a183024e0b1f1626dbe14e847 (patch)
tree55af4c538b50ca5a094ad37885c69bc1295668b4 /lib/gitlab/zentao
parentb46d41d54b05eab84bb9653c111124b67f573dd8 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/zentao')
-rw-r--r--lib/gitlab/zentao/client.rb73
1 files changed, 73 insertions, 0 deletions
diff --git a/lib/gitlab/zentao/client.rb b/lib/gitlab/zentao/client.rb
new file mode 100644
index 00000000000..bdfa4b3a308
--- /dev/null
+++ b/lib/gitlab/zentao/client.rb
@@ -0,0 +1,73 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Zentao
+ class Client
+ Error = Class.new(StandardError)
+ ConfigError = Class.new(Error)
+
+ attr_reader :integration
+
+ def initialize(integration)
+ raise ConfigError, 'Please check your integration configuration.' unless integration
+
+ @integration = integration
+ end
+
+ def ping
+ response = fetch_product(zentao_product_xid)
+
+ active = response.fetch('deleted') == '0' rescue false
+
+ if active
+ { success: true }
+ else
+ { success: false, message: 'Not Found' }
+ end
+ end
+
+ def fetch_product(product_id)
+ get("products/#{product_id}")
+ end
+
+ def fetch_issues(params = {})
+ get("products/#{zentao_product_xid}/issues",
+ params.reverse_merge(page: 1, limit: 20))
+ end
+
+ def fetch_issue(issue_id)
+ get("issues/#{issue_id}")
+ end
+
+ private
+
+ def get(path, params = {})
+ options = { headers: headers, query: params }
+ response = Gitlab::HTTP.get(url(path), options)
+
+ return {} unless response.success?
+
+ Gitlab::Json.parse(response.body)
+ rescue JSON::ParserError
+ {}
+ end
+
+ def url(path)
+ host = integration.api_url.presence || integration.url
+
+ URI.join(host, '/api.php/v1/', path)
+ end
+
+ def headers
+ {
+ 'Content-Type': 'application/json',
+ 'Token': integration.api_token
+ }
+ end
+
+ def zentao_product_xid
+ integration.zentao_product_xid
+ end
+ end
+ end
+end