Class: Fastlane::Actions::JiraCommentUpdateAction
- Inherits:
-
Action
- Object
- Action
- Fastlane::Actions::JiraCommentUpdateAction
- Defined in:
- lib/fastlane/plugin/jira_update/actions/jira_comment_update_action.rb
Documentation collapse
- .authors ⇒ Object
- .available_options ⇒ Object
- .category ⇒ Object
- .description ⇒ Object
- .details ⇒ Object
- .example_code ⇒ Object
- .is_supported?(platform) ⇒ Boolean
- .return_type ⇒ Object
- .return_value ⇒ Object
Class Method Summary collapse
Class Method Details
.authors ⇒ Object
141 142 143 |
# File 'lib/fastlane/plugin/jira_update/actions/jira_comment_update_action.rb', line 141 def self. ["Flop Butylkin"] end |
.available_options ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/fastlane/plugin/jira_update/actions/jira_comment_update_action.rb', line 94 def self. [ FastlaneCore::ConfigItem.new(key: :url, env_name: "FL_JIRA_SITE", description: "URL for Jira instance", verify_block: proc do |value| UI.user_error!("No url for Jira given") if value.to_s.length == 0 end), FastlaneCore::ConfigItem.new(key: :username, env_name: "FL_JIRA_USERNAME", description: "Username for Jira instance", verify_block: proc do |value| UI.user_error!("No username") if value.to_s.length == 0 end), FastlaneCore::ConfigItem.new(key: :password, env_name: "FL_JIRA_PASSWORD", description: "Password or api token for Jira", sensitive: true, verify_block: proc do |value| UI.user_error!("No password") if value.to_s.length == 0 end), FastlaneCore::ConfigItem.new(key: :ticket, env_name: "FL_JIRA_TICKET", description: "Jira ticket id", type: String, optional: true, default_value: nil), FastlaneCore::ConfigItem.new(key: :comment_search, description: "Jira comment text to find", type: String, optional: true, default_value: nil), FastlaneCore::ConfigItem.new(key: :comment_text, description: "Jira comment text to add", type: String, default_value: "comment"), FastlaneCore::ConfigItem.new(key: :fail_if_not_found, description: "Fail if Issue or comment not found", type: Boolean, default_value: false), FastlaneCore::ConfigItem.new(key: :update_comment, description: "Update comment if found otherwise will delete and add new comment", type: Boolean, default_value: false) ] end |
.category ⇒ Object
164 165 166 |
# File 'lib/fastlane/plugin/jira_update/actions/jira_comment_update_action.rb', line 164 def self.category :misc end |
.description ⇒ Object
78 79 80 |
# File 'lib/fastlane/plugin/jira_update/actions/jira_comment_update_action.rb', line 78 def self.description "Jira ticket comment replace action" end |
.details ⇒ Object
82 83 84 |
# File 'lib/fastlane/plugin/jira_update/actions/jira_comment_update_action.rb', line 82 def self.details "Replace Jira ticket comment" end |
.example_code ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/fastlane/plugin/jira_update/actions/jira_comment_update_action.rb', line 149 def self.example_code [ ' gym slack(message: "Done") jira_comment_update( ticket: "APP-132", search: "Test comment", comment: "Test comment updated", update_comment: true ) ' ] end |
.is_supported?(platform) ⇒ Boolean
145 146 147 |
# File 'lib/fastlane/plugin/jira_update/actions/jira_comment_update_action.rb', line 145 def self.is_supported?(platform) true end |
.return_type ⇒ Object
90 91 92 |
# File 'lib/fastlane/plugin/jira_update/actions/jira_comment_update_action.rb', line 90 def self.return_type :hash end |
.return_value ⇒ Object
86 87 88 |
# File 'lib/fastlane/plugin/jira_update/actions/jira_comment_update_action.rb', line 86 def self.return_value "Hash where keys are Jira ticket IDs and values results of the action" end |
.run(params) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/fastlane/plugin/jira_update/actions/jira_comment_update_action.rb', line 4 def self.run(params) Actions.verify_gem!('jira-ruby') require 'jira-ruby' client = JIRA::Client.new( username: params[:username], password: params[:password], site: params[:url], context_path: '', auth_type: :basic ) ticket = params[:ticket] search = params[:comment_search] username = params[:username] comment = params[:comment_text] update_comment = params[:update_comment] || false fail_if_not_found = params[:fail_if_not_found] || false UI.("JIRA ticket to update: '#{ticket}'") begin issue = client.Issue.find(ticket) UI.("JIRA ticket: '#{issue.id}'") if search # search comment UI.("Searching for comment: '#{search}'") comment_obj = issue.comments.find { |comment| comment.body.include?(search) && comment.['displayName'] == username } UI.error!("Comment not found") if fail_if_not_found && !comment_obj UI.("Comment found: '#{comment_obj.body}'") if comment_obj if comment_obj && update_comment comment_obj.save({ 'body' => comment }) UI.("Comment updated: '#{comment_obj.body}'") elsif comment_obj comment_obj.delete UI.("Comment deleted: '#{comment_obj.body}'") end if !update_comment new_comment = issue.comments.build new_comment.save({ 'body' => comment }) UI.("Comment added: '#{new_comment.body}'") end else UI.("No search provided, will add new comment") new_comment = issue.comments.build new_comment.save({ 'body' => comment }) UI.("Comment added: '#{new_comment.body}'") end rescue StandardError => e UI.important("Failed to fetch issue #{ticket}: #{e.}") UI.error!("Failed to fetch issue #{ticket}: #{e.}") if fail_if_not_found result = "Ticket not found" end UI.success("JIRA ticket updated: '#{issue.id}'") return issue end |