Class: Fastlane::Actions::ReleaseJiraVersionAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/jira_versions/actions/release_jira_version.rb

Documentation collapse

Class Method Summary collapse

Class Method Details

.authorsObject



146
147
148
# File 'lib/fastlane/plugin/jira_versions/actions/release_jira_version.rb', line 146

def self.authors
  ["https://github.com/SandyChapman"]
end

.available_optionsObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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
# File 'lib/fastlane/plugin/jira_versions/actions/release_jira_version.rb', line 72

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :url,
                                env_name: "FL_RELEASE_JIRA_VERSION_SITE",
                                description: "URL for Jira instance",
                                type: String,
                                verify_block: proc do |value|
                                  UI.user_error!("No url for Jira given, pass using `url: 'url'`") unless value and !value.empty?
                                end),
    FastlaneCore::ConfigItem.new(key: :username,
                                 env_name: "FL_RELEASE_JIRA_VERSION_USERNAME",
                                 description: "Username for JIRA instance",
                                 type: String,
                                 verify_block: proc do |value|
                                   UI.user_error!("No username given, pass using `username: 'jira_user'`") unless value and !value.empty?
                                 end),
    FastlaneCore::ConfigItem.new(key: :password,
                                 env_name: "FL_RELEASE_JIRA_VERSION_PASSWORD",
                                 description: "Password for Jira",
                                 type: String,
                                 verify_block: proc do |value|
                                   UI.user_error!("No password given, pass using `password: 'T0PS3CR3T'`") unless value and !value.empty?
                                 end),
    FastlaneCore::ConfigItem.new(key: :project_name,
                                 env_name: "FL_RELEASE_JIRA_VERSION_PROJECT_NAME",
                                 description: "Project ID for the JIRA project. E.g. the short abbreviation in the JIRA ticket tags",
                                 type: String,
                                 optional: true,
                                 conflicting_options: [:project_id],
                                 conflict_block: proc do |value|
                                   UI.user_error!("You can't use 'project_name' and '#{project_id}' options in one run")
                                 end,
                                 verify_block: proc do |value|
                                   UI.user_error!("No Project ID given, pass using `project_id: 'PROJID'`") unless value and !value.empty?
                                 end),
    FastlaneCore::ConfigItem.new(key: :project_id,
                                 env_name: "FL_RELEASE_JIRA_VERSION_PROJECT_ID",
                                 description: "Project ID for the JIRA project. E.g. the short abbreviation in the JIRA ticket tags",
                                 type: String,
                                 optional: true,
                                 conflicting_options: [:project_name],
                                 conflict_block: proc do |value|
                                   UI.user_error!("You can't use 'project_id' and '#{project_name}' options in one run")
                                 end,
                                 verify_block: proc do |value|
                                   UI.user_error!("No Project ID given, pass using `project_id: 'PROJID'`") unless value and !value.empty?
                                 end),
    FastlaneCore::ConfigItem.new(key: :name,
                                 env_name: "FL_RELEASE_JIRA_VERSION_NAME",
                                 description: "The name of the version. E.g. 1.0.0",
                                 type: String,
                                 verify_block: proc do |value|
                                   UI.user_error!("No version name given, pass using `name: '1.0.0'`") unless value and !value.empty?
                                 end),
    FastlaneCore::ConfigItem.new(key: :release_date,
                                 env_name: "FL_CREATE_JIRA_VERSION_RELEASE_DATE",
                                 description: "The date this version ended on",
                                 type: String,
                                 is_string: true,
                                 optional: true,
                                 default_value: Date.today.to_s)
  ]
end

.descriptionObject



64
65
66
# File 'lib/fastlane/plugin/jira_versions/actions/release_jira_version.rb', line 64

def self.description
  "Releases a version in your JIRA project"
end

.detailsObject



68
69
70
# File 'lib/fastlane/plugin/jira_versions/actions/release_jira_version.rb', line 68

def self.details
  "Use this action to release a version in JIRA"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


150
151
152
# File 'lib/fastlane/plugin/jira_versions/actions/release_jira_version.rb', line 150

def self.is_supported?(platform)
  true
end

.outputObject



136
137
138
139
140
# File 'lib/fastlane/plugin/jira_versions/actions/release_jira_version.rb', line 136

def self.output
  [
    ['RELEASE_JIRA_VERSION_VERSION_ID', 'The versionId for the newly released JIRA project version']
  ]
end

.return_valueObject



142
143
144
# File 'lib/fastlane/plugin/jira_versions/actions/release_jira_version.rb', line 142

def self.return_value
  'The versionId for the newly release JIRA project version'
end

.run(params) ⇒ Object



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
# File 'lib/fastlane/plugin/jira_versions/actions/release_jira_version.rb', line 8

def self.run(params)
  Actions.verify_gem!('jira-ruby')
  require 'jira-ruby'

  site         = params[:url]
  context_path = ""
  auth_type    = :basic
  username     = params[:username]
  password     = params[:password]
  project_name = params[:project_name]
  project_id   = params[:project_id]
  name         = params[:name]
  release_date = params[:release_date]
  released     = true

  options = {
    username:     username,
    password:     password,
    site:         site,
    context_path: context_path,
    auth_type:    auth_type,
    read_timeout: 120
  }

  client = JIRA::Client.new(options)

  unless project_name.nil?
    project = client.Project.find(project_name)
    project_id = project.id
  end

  version = project.versions.find { |version| version.name == name }
  if version.nil?
    raise "Version '#{name}' not found."
    return false
  end
  version.save!({
    "released" => released,
    "releaseDate" => release_date,
    "projectId" => project_id
  })
  version.fetch
  Actions.lane_context[SharedValues::RELEASE_JIRA_VERSION_VERSION_ID] = version.id
  version.id
rescue RuntimeError
  UI.user_error!("#{$!}")
  false
rescue JIRA::HTTPError
  UI.user_error!("Failed to release new JIRA version: #{$!.response.body}")
  false
end