fastlane-plugin-set_jira_fix_version 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7c85148e12d7d864168c8acb743ca0476c6e2f17
4
+ data.tar.gz: 65b405af05ae939e543f3f6597fca6530dd7e87b
5
+ SHA512:
6
+ metadata.gz: 2ec94d2f92dc223a62c929ca899e4339bf19e0ab6ac0057dea75aa33bdb1fac09cda57298ba97f88520d80946d4324c3f94e699258eefcfb5bc35bb97124bee6
7
+ data.tar.gz: 13f8e976bf5ff4bac5ac9a540feee4c52225de72b0b179b0bf4c59c8f9311766cfb6990ad5ff64d3962296a760119122b8d38c25078e178c22d70013b7555d54
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Yuriy Tolstoguzov <Yuriy.Tolstoguzov@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,52 @@
1
+ # set_jira_fix_version plugin
2
+
3
+ [![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-set_jira_fix_version)
4
+
5
+ ## Getting Started
6
+
7
+ This project is a [fastlane](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-set_jira_fix_version`, add it to your project by running:
8
+
9
+ ```bash
10
+ fastlane add_plugin set_jira_fix_version
11
+ ```
12
+
13
+ ## About set_jira_fix_version
14
+
15
+ Adds fix version to specified JIRA issues. Creates version if needed
16
+
17
+ This action allows to easily add fix version to specified JIRA issues. It supports basic and cookie authorization. If JIRA account password won't be specified in parameters (recommended) it will ask it at first launch and save in a macOS keychain. If JIRA version with specified name is not created, this action will create it. The action can take issue IDs from lane context (`FL_JIRA_ISSUE_IDS`) and many other JIRA related parameters from environment variables.
18
+
19
+ ## [WIP]: Example
20
+
21
+ Check out the [example `Fastfile`](fastlane/Fastfile) to see how to use this plugin. Try it by cloning the repo, running `fastlane install_plugins` and `bundle exec fastlane test`.
22
+
23
+ **Note to author:** Please set up a sample project to make it easy for users to explore what your plugin does. Provide everything that is necessary to try out the plugin in this project (including a sample Xcode/Android project if necessary)
24
+
25
+ ## Run tests for this plugin
26
+
27
+ To run both the tests, and code style validation, run
28
+
29
+ ```
30
+ rake
31
+ ```
32
+
33
+ To automatically fix many of the styling issues, use
34
+ ```
35
+ rubocop -a
36
+ ```
37
+
38
+ ## Issues and Feedback
39
+
40
+ For any other issues and feedback about this plugin, please submit it to this repository.
41
+
42
+ ## Troubleshooting
43
+
44
+ If you have trouble using plugins, check out the [Plugins Troubleshooting](https://docs.fastlane.tools/plugins/plugins-troubleshooting/) guide.
45
+
46
+ ## Using `fastlane` Plugins
47
+
48
+ For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://docs.fastlane.tools/plugins/create-plugin/).
49
+
50
+ ## About `fastlane`
51
+
52
+ `fastlane` is the easiest way to automate beta deployments and releases for your iOS and Android apps. To learn more, check out [fastlane.tools](https://fastlane.tools).
@@ -0,0 +1,16 @@
1
+ require 'fastlane/plugin/set_jira_fix_version/version'
2
+
3
+ module Fastlane
4
+ module SetJiraFixVersion
5
+ # Return all .rb files inside the "actions" and "helper" directory
6
+ def self.all_classes
7
+ Dir[File.expand_path('**/{actions,helper}/*.rb', File.dirname(__FILE__))]
8
+ end
9
+ end
10
+ end
11
+
12
+ # By default we want to import all available actions and helpers
13
+ # A plugin can contain any number of actions and plugins
14
+ Fastlane::SetJiraFixVersion.all_classes.each do |current|
15
+ require current
16
+ end
@@ -0,0 +1,93 @@
1
+ module Fastlane
2
+ module Actions
3
+ module SharedValues
4
+ FL_JIRA_ISSUE_IDS = :FL_JIRA_ISSUE_IDS
5
+ end
6
+
7
+ class JiraIssueKeysFromChangelogAction < Action
8
+ def self.run(params)
9
+ tag = params[:tag]
10
+ project_key = params[:project_key]
11
+
12
+ if tag.start_with?("`") && tag.end_with?("`")
13
+ tag_command = tag.tr("`", "")
14
+ tag = `#{tag_command}`
15
+ tag.strip!
16
+ end
17
+ UI.message("Looking for issue keys starting from tag: #{tag}")
18
+
19
+ git_log = `git log #{tag}..HEAD --format=%s`
20
+ issue_key_regex = /#{project_key}-\d+(?!\!)/
21
+ issue_keys = git_log.scan(issue_key_regex).uniq
22
+
23
+ if issue_keys.nil? || issue_keys.empty?
24
+ UI.error("No issue keys were found!")
25
+ else
26
+ UI.message("Issues found: #{issue_keys}")
27
+ end
28
+ Actions.lane_context[SharedValues::FL_JIRA_ISSUE_IDS] = issue_keys
29
+ return issue_keys
30
+ end
31
+
32
+ #####################################################
33
+ # @!group Documentation
34
+ #####################################################
35
+
36
+ def self.description
37
+ "Gets list of JIRA issues kyes from git log starting from specified tag"
38
+ end
39
+
40
+ def self.available_options
41
+ [
42
+ FastlaneCore::ConfigItem.new(key: :tag,
43
+ env_name: "FL_JIRA_ISSUE_KEYS_FROM_CHANGELOG_TAG_NAME",
44
+ description: "Tag name of shell command in `` to that returns tag name",
45
+ is_string: true,
46
+ default_value: "`git describe --tags --abbrev=0`"),
47
+ FastlaneCore::ConfigItem.new(key: :project_key,
48
+ env_name: "FL_JIRA_PROJECT_ID",
49
+ description: "Project key that corresponds to JIRA issue id prefixes",
50
+ is_string: true)
51
+ ]
52
+ end
53
+
54
+ def self.output
55
+ [
56
+ ['FL_JIRA_ISSUE_KEYS_FROM_CHANGELOG', 'JIRA issue keys collected from specified tag']
57
+ ]
58
+ end
59
+
60
+ def self.return_value
61
+ "Returns array of JIRA issue keys from git log starting from specified tag"
62
+ end
63
+
64
+ def self.authors
65
+ ["yuriy-tolstoguzov"]
66
+ end
67
+
68
+ def self.is_supported?(platform)
69
+ true
70
+ end
71
+
72
+ def self.example_code
73
+ [
74
+ 'jira_issue_keys_from_changelog(
75
+ project_key: "IOS",
76
+ tag: "builds/latest-tag"
77
+ )',
78
+ 'jira_issue_keys_from_changelog(
79
+ project_key: "IOS"
80
+ )'
81
+ ]
82
+ end
83
+
84
+ def self.sample_return_value
85
+ ["IOS-1000", "IOS-1001"]
86
+ end
87
+
88
+ def self.category
89
+ :misc
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,185 @@
1
+ module Fastlane
2
+ module Actions
3
+ class SetJiraFixVersionAction < Action
4
+ def self.run(params)
5
+ Actions.verify_gem!('jira-ruby')
6
+ require 'jira-ruby'
7
+
8
+ site = params[:url]
9
+ auth_type = params[:auth_type]
10
+ use_cookies = params[:use_cookies]
11
+ project_id = params[:project_key]
12
+ version_name = params[:version_name]
13
+ issue_ids = self.issue_ids_from_param(params)
14
+
15
+ account_manager = self.account_manager(params)
16
+ username = account_manager.user
17
+ password = account_manager.password
18
+
19
+ options = {
20
+ site: site,
21
+ auth_type: auth_type,
22
+ use_cookies: use_cookies,
23
+ username: username,
24
+ password: password
25
+ }
26
+ client = JIRA::Client.new(options)
27
+
28
+ self.save_version(client, version_name, project_id, issue_ids)
29
+ end
30
+
31
+ def self.account_manager(params)
32
+ require 'credentials_manager'
33
+
34
+ username = params[:username]
35
+ password = params[:password]
36
+
37
+ # gets password via interactive shell if needed
38
+ return CredentialsManager::AccountManager.new(
39
+ user: username,
40
+ password: password,
41
+ prefix: "set_jira_fix_version",
42
+ note: "set_jira_fix_version fastlane action"
43
+ )
44
+ end
45
+
46
+ def self.issue_ids_from_param(params)
47
+ issue_ids = params[:issue_ids]
48
+
49
+ if issue_ids.nil?
50
+ issue_ids = Actions.lane_context[SharedValues::FL_JIRA_ISSUE_IDS]
51
+ end
52
+
53
+ if issue_ids.kind_of?(Array) == false || issue_ids.empty?
54
+ UI.user_error!("No issue ids or keys were supplied or the value is not an array.")
55
+ return
56
+ end
57
+
58
+ UI.message("Issues: #{issue_ids}")
59
+ return issue_ids
60
+ end
61
+
62
+ def self.save_version(client, version_name, project_key, issue_ids)
63
+ # create new version if needed
64
+ begin
65
+ project = client.Project.find(project_key)
66
+ rescue => error
67
+ UI.error("JIRA API call failed. Check if JIRA is available and correct credentials for user with proper permissions are provided!")
68
+ UI.user_error!(error.response)
69
+ return
70
+ end
71
+
72
+ is_version_created = false
73
+ project.versions.each do |version|
74
+ if version.name == version_name
75
+ is_version_created = true
76
+ break
77
+ end
78
+ end
79
+
80
+ # if the version does not exist then create this JIRA version
81
+ if is_version_created == false
82
+ version = project.versions.build
83
+ create_version_parameters = { "name" => version_name, "projectId" => project.id }
84
+ version.save(create_version_parameters)
85
+ UI.message("#{version_name} version is created.")
86
+ else
87
+ UI.message("#{version_name} version already exists and will be used as a fix version.")
88
+ end
89
+
90
+ # update issues with fix version
91
+ issue_ids.each do |issue_id|
92
+ begin
93
+ issue = client.Issue.find(issue_id)
94
+ rescue
95
+ UI.error("JIRA issue with #{issue_id} is not found or specified user don't have permissions to see it. It won't be updated!")
96
+ end
97
+ add_new_version_parameters = { 'update' => { 'fixVersions' => [{ 'add' => { 'name' => version_name } }] } }
98
+ issue.save(add_new_version_parameters)
99
+ UI.message("#{issue_id} is updated with fix version #{version_name}")
100
+ end
101
+ end
102
+
103
+ #####################################################
104
+ # @!group Documentation
105
+ #####################################################
106
+
107
+ def self.description
108
+ "Adds fix version to specified JIRA issues. Creates version if needed"
109
+ end
110
+
111
+ def self.details
112
+ [
113
+ "This action allows to easily add fix version to specified JIRA issues. It supports basic and cookie authorization.",
114
+ "If JIRA account password won't be specified in parameters (recommended) it will ask it at first launch and save in a macOS keychain.",
115
+ "If JIRA version with specified name is not created, this action will create it. The action can take issue IDs from lane context",
116
+ "(FL_JIRA_ISSUE_IDS) and many other JIRA related parameters from environment variables."
117
+ ].join("\n")
118
+ end
119
+
120
+ def self.available_options
121
+ [
122
+ FastlaneCore::ConfigItem.new(key: :url,
123
+ env_name: "FL_JIRA_SITE",
124
+ description: "URL for JIRA instance",
125
+ verify_block: proc do |value|
126
+ UI.user_error!("No url for JIRA given, pass using `url: 'url'`") if value.to_s.length == 0
127
+ end),
128
+ FastlaneCore::ConfigItem.new(key: :username,
129
+ env_name: "FL_JIRA_USERNAME",
130
+ optional: true,
131
+ description: "Username for JIRA"),
132
+ FastlaneCore::ConfigItem.new(key: :password,
133
+ env_name: "FL_JIRA_PASSWORD",
134
+ description: "Password for JIRA",
135
+ optional: true,
136
+ sensitive: true),
137
+ FastlaneCore::ConfigItem.new(key: :auth_type,
138
+ description: "Authorization type to use. Currently supported: :basic or :cookie",
139
+ default_value: :basic),
140
+ FastlaneCore::ConfigItem.new(key: :use_cookies,
141
+ description: "Whether JIRA client should use cookies",
142
+ default_value: false),
143
+ FastlaneCore::ConfigItem.new(key: :issue_ids,
144
+ description: "Issue IDs or keys for JIRA, i.e. [\"IOS-123\", \"IOS-123\"]",
145
+ optional: true,
146
+ is_string: false),
147
+ FastlaneCore::ConfigItem.new(key: :version_name,
148
+ env_name: "FL_JIRA_VERSION_NAME",
149
+ description: "Version name that will be set as fix version to specified issues.\nIf version does not exist, it will be created",
150
+ is_string: true,
151
+ optional: true),
152
+ FastlaneCore::ConfigItem.new(key: :project_key,
153
+ env_name: "FL_JIRA_PROJECT_ID",
154
+ description: "Project ID or key where version will be created if needed",
155
+ is_string: true,
156
+ optional: true)
157
+ ]
158
+ end
159
+
160
+ def self.authors
161
+ ["yuriy-tolstoguzov", "vadimux"]
162
+ end
163
+
164
+ def self.example_code
165
+ [
166
+ 'set_jira_fix_version(
167
+ url: "https://jira.yourdomain.com",
168
+ username: "Your username",
169
+ issue_ids: ["IOS-1000", "IOS-1001"],
170
+ version_name: "1.0.0 (123)",
171
+ project_key: "IOS"
172
+ )'
173
+ ]
174
+ end
175
+
176
+ def self.category
177
+ :misc
178
+ end
179
+
180
+ def self.is_supported?(platform)
181
+ true
182
+ end
183
+ end
184
+ end
185
+ end
@@ -0,0 +1,12 @@
1
+ module Fastlane
2
+ module Helper
3
+ class SetJiraFixVersionHelper
4
+ # class methods that you define here become available in your action
5
+ # as `Helper::SetJiraFixVersionHelper.your_method`
6
+ #
7
+ def self.show_message
8
+ UI.message("Hello from the set_jira_fix_version plugin helper!")
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ module Fastlane
2
+ module SetJiraFixVersion
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fastlane-plugin-set_jira_fix_version
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - yuriy-tolstoguzov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jira-ruby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 1.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 1.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: fastlane
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: 2.20.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: 2.20.0
111
+ description:
112
+ email: Yuriy.Tolstoguzov@gmail.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - lib/fastlane/plugin/set_jira_fix_version/actions/jira_issue_keys_from_changelog.rb
118
+ - lib/fastlane/plugin/set_jira_fix_version/actions/set_jira_fix_version_action.rb
119
+ - lib/fastlane/plugin/set_jira_fix_version/helper/set_jira_fix_version_helper.rb
120
+ - lib/fastlane/plugin/set_jira_fix_version/version.rb
121
+ - lib/fastlane/plugin/set_jira_fix_version.rb
122
+ - README.md
123
+ - LICENSE
124
+ homepage: https://github.com/yuriy-tolstoguzov/fastlane-plugin-set_jira_fix_version
125
+ licenses:
126
+ - MIT
127
+ metadata: {}
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.0.14.1
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: Adds fix version to specified JIRA issues. Creates version if needed
148
+ test_files: []
149
+ has_rdoc: