fastlane-plugin-youtrack 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c62ad905a10c11c2602bd5b4328c69535ec6d872a15724284a6bc53d5d4cb37
4
- data.tar.gz: 9928720ad336f1caedaecc4b7dc800cce720236af345bb94baa61925f2504aeb
3
+ metadata.gz: 63739100a15102a8154ce4b8a104229e05498267a3a8fb72bff732f3a9ca7fa4
4
+ data.tar.gz: 370c2da7869a2a25919e6af585f93fd2d33266e7d6e841cc66337f8977da39e0
5
5
  SHA512:
6
- metadata.gz: 954b0bc122be8a899fbbd422fb4ff85694e57e00334d937446c3b1e94b5b33a1415606c801f250f0aecb25334ef831c726b61b7f9f24e603acac354a1bcdd07d
7
- data.tar.gz: 9a307b74b7b82141c94f81bf8577ea137d2e16685028315b9ccdacd8a234c98de4b6835142fe08dbb510200745a9d5f4e6cdb4696d9b298ed3120e9e3acc548e
6
+ metadata.gz: fb43d2f3478621984dac2622c410488b469ea45401016b117c3b921bbc13cdaefb508f3ea98b898105ba42b23d74ab2e0bce146ef4d483825ac673cd5bdced69
7
+ data.tar.gz: 84f1a1264f078903a33c10c1b970acbd1dc6e77885f562af69a900a230a9406251763856b2606bf6576c2a60a786e195651a78c1c4575d1552e06439ee61d5e4
@@ -10,6 +10,7 @@ module Fastlane
10
10
  def self.run(params)
11
11
  issue_ids = params[:issue_ids]
12
12
  fields = params[:issue_fields]
13
+ custom_fields_names = params[:issue_custom_fields_names]
13
14
  base_url = params[:base_url]
14
15
  access_token = params[:access_token]
15
16
 
@@ -18,12 +19,46 @@ module Fastlane
18
19
  id: issue_id,
19
20
  url: "#{base_url}/issue/#{issue_id}"
20
21
  }
21
- result = Helper::YoutrackHelper.get_issue_info(issue_id, fields, base_url, access_token)
22
- return info unless result.success?
22
+
23
+ issue_info_result = Helper::YoutrackHelper.get_issue_info(
24
+ issue_id,
25
+ fields,
26
+ base_url,
27
+ access_token
28
+ )
29
+ return info unless issue_info_result.success?
23
30
 
24
31
  begin
25
- response_body = JSON.parse(result.body)
26
- fields.each { |field| info[field.to_sym] = response_body[field] }
32
+ issue_info_response_body = JSON.parse(issue_info_result.body)
33
+ fields.each { |field| info[field.to_sym] = issue_info_response_body[field] }
34
+ rescue JSON::ParserError => e
35
+ puts e
36
+ return info
37
+ end
38
+
39
+ issue_custom_fields_result = Helper::YoutrackHelper.get_issue_custom_fields(
40
+ issue_id,
41
+ base_url,
42
+ access_token
43
+ )
44
+
45
+ return info unless issue_custom_fields_result.success?
46
+
47
+ begin
48
+ issue_custom_fields_response_body = JSON.parse(issue_custom_fields_result.body)
49
+ custom_fields_names.each do |field_name|
50
+ custom_field = issue_custom_fields_response_body.find { |field|
51
+ field['name'] == field_name
52
+ }
53
+
54
+ next if custom_field.nil?
55
+
56
+ info[field_name.to_sym] = {
57
+ type: custom_field['$type'],
58
+ name: custom_field['name'],
59
+ value: custom_field['value']['name']
60
+ }
61
+ end
27
62
  rescue JSON::ParserError => e
28
63
  puts e
29
64
  return info
@@ -63,6 +98,13 @@ module Fastlane
63
98
  default_value: ['summary', 'description'],
64
99
  type: Array
65
100
  ),
101
+ FastlaneCore::ConfigItem.new(
102
+ key: :issue_custom_fields_names,
103
+ description: 'Array of names of neccessary custom fields of issue',
104
+ optional: true,
105
+ default_value: ['Kanban State', 'Stage'],
106
+ type: Array
107
+ ),
66
108
  FastlaneCore::ConfigItem.new(
67
109
  key: :base_url,
68
110
  env_name: 'YOUTRACK_BASE_URL',
@@ -109,4 +151,4 @@ module Fastlane
109
151
  end
110
152
  end
111
153
  end
112
- end
154
+ end
@@ -0,0 +1,109 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/youtrack_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ class YtSetIssueCustomFieldValueAction < Action
7
+ def self.run(params)
8
+ issue_id = params[:issue_id]
9
+ field = params[:field]
10
+ field_value = params[:field_value]
11
+ base_url = params[:base_url]
12
+ access_token = params[:access_token]
13
+
14
+ result = Helper::YoutrackHelper.set_custom_field_value(
15
+ issue_id,
16
+ field,
17
+ field_value,
18
+ base_url,
19
+ access_token
20
+ )
21
+ return {} unless result.success?
22
+
23
+ begin
24
+ response_body = JSON.parse(result.body)
25
+ rescue JSON::ParserError => e
26
+ puts e
27
+ end
28
+
29
+ response_body
30
+ rescue => ex
31
+ UI.error(ex)
32
+ UI.error('Failed')
33
+ end
34
+
35
+ def self.description
36
+ 'Set value for passed custom field name'
37
+ end
38
+
39
+ def self.details
40
+ ''
41
+ end
42
+
43
+ def self.available_options
44
+ [
45
+ FastlaneCore::ConfigItem.new(
46
+ key: :issue_id,
47
+ description: 'Identifier of issue',
48
+ optional: false,
49
+ type: String
50
+ ),
51
+ FastlaneCore::ConfigItem.new(
52
+ key: :field,
53
+ description: 'Custom field info',
54
+ optional: false,
55
+ type: Hash
56
+ ),
57
+ FastlaneCore::ConfigItem.new(
58
+ key: :field_value,
59
+ description: 'Value of custom field',
60
+ optional: false,
61
+ type: String
62
+ ),
63
+ FastlaneCore::ConfigItem.new(
64
+ key: :base_url,
65
+ env_name: 'YOUTRACK_BASE_URL',
66
+ description: 'Base YouTrack URL',
67
+ optional: false,
68
+ type: String
69
+ ),
70
+ FastlaneCore::ConfigItem.new(
71
+ key: :access_token,
72
+ env_name: 'YOUTRACK_API_TOKEN',
73
+ description: 'Access token for YouTrack API',
74
+ optional: false,
75
+ type: String
76
+ )
77
+ ]
78
+ end
79
+
80
+ def self.return_value
81
+ 'Nothing'
82
+ end
83
+
84
+ def self.authors
85
+ ['Semen Kologrivov']
86
+ end
87
+
88
+ def self.is_supported?(_)
89
+ true
90
+ end
91
+
92
+ def self.example_code
93
+ [
94
+ 'yt_set_issue_custom_field_value(issue_id: "ios_1234", field_name: "Foo", field_value: "Bar")'
95
+ ]
96
+ end
97
+
98
+ def self.output
99
+ [
100
+ []
101
+ ]
102
+ end
103
+
104
+ def self.return_type
105
+ :array
106
+ end
107
+ end
108
+ end
109
+ end
@@ -20,6 +20,17 @@ module Fastlane
20
20
  end
21
21
  end
22
22
 
23
+ def self.get_issue_custom_fields(issue_id, url, token)
24
+ Faraday.get("#{url}/api/issues/#{issue_id}/customFields") do |req|
25
+ req.params['fields'] = 'id,name,value(id,name)'
26
+
27
+ req.headers['Content-Type'] = 'application/json'
28
+ req.headers['Accept'] = 'application/json'
29
+ req.headers['Cache-Control'] = 'no-cache'
30
+ req.headers['Authorization'] = "Bearer #{token}"
31
+ end
32
+ end
33
+
23
34
  def self.comment_issue(issue_id, comment, url, token)
24
35
  Faraday.post("#{url}/api/issues/#{issue_id}/comments") do |req|
25
36
  body = {
@@ -33,6 +44,28 @@ module Fastlane
33
44
  req.headers['Authorization'] = "Bearer #{token}"
34
45
  end
35
46
  end
47
+
48
+ def self.set_custom_field_value(issue_id, field, field_value, url, token)
49
+ Faraday.post("#{url}/api/issues/#{issue_id}") do |req|
50
+ body = {
51
+ 'customFields' => [
52
+ {
53
+ 'name' => field[:name],
54
+ '$type' => field[:type],
55
+ 'value' => {
56
+ 'name' => field_value
57
+ }
58
+ }
59
+ ]
60
+ }
61
+ req.body = JSON.generate(body)
62
+
63
+ req.headers['Content-Type'] = 'application/json'
64
+ req.headers['Accept'] = 'application/json'
65
+ req.headers['Cache-Control'] = 'no-cache'
66
+ req.headers['Authorization'] = "Bearer #{token}"
67
+ end
68
+ end
36
69
  end
37
70
  end
38
71
  end
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module Youtrack
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-youtrack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Semen Kologrivov
@@ -147,6 +147,7 @@ files:
147
147
  - lib/fastlane/plugin/youtrack.rb
148
148
  - lib/fastlane/plugin/youtrack/actions/yt_comment_issue_action.rb
149
149
  - lib/fastlane/plugin/youtrack/actions/yt_issues_info_action.rb
150
+ - lib/fastlane/plugin/youtrack/actions/yt_set_issue_custom_field_value_action.rb
150
151
  - lib/fastlane/plugin/youtrack/helper/youtrack_helper.rb
151
152
  - lib/fastlane/plugin/youtrack/version.rb
152
153
  homepage: