capistrano-jira 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3d71f8dc9b592a0718a36cf151d5148857fc29a3
4
+ data.tar.gz: fc9afc9620a9e4ff96feb186f6772b3c64c25482
5
+ SHA512:
6
+ metadata.gz: 179755583fad4d3ce68efda8b725f6276cc34decd592516fe1dafe43e912cda59bb782db5cfbd1d34e775def6418c591c412d80f37fa388e69fefede85234035
7
+ data.tar.gz: e1ae6415135e0a3377020f7dd9ef5ff7689136675fc77be99e43e2124124b1a0b6a4eadcb8b59fb1c9496b1530ffc88e1e974433a9306ce97ff44f1eb4622d22
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-jira.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ [![Build Status](https://travis-ci.org/wojw5/capistrano-jira.svg?branch=master)](https://travis-ci.org/wojw5/capistrano-jira)
2
+ [![Code Climate](https://codeclimate.com/github/wojw5/capistrano-jira/badges/gpa.svg)](https://codeclimate.com/github/wojw5/capistrano-jira)
3
+ # Capistrano::Jira
4
+
5
+ Transit JIRA issues automatically after deployment.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'capistrano-jira'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install capistrano-jira
22
+
23
+ ## Usage
24
+
25
+ - Require library in `Capfile`
26
+ ```ruby
27
+ require 'capistrano/jira'
28
+ ```
29
+
30
+ - Set general parameters in `config/deploy.rb`
31
+ ```ruby
32
+ set :jira_username, 'john.doe@exalmple.com' # default: ENV['CAPISTRANO_JIRA_USERNAME']
33
+ set :jira_password, 'p@55w0rD' # default: ENV['CAPISTRANO_JIRA_PASSWORD']
34
+ set :jira_site, 'https://example.atlassian.net' # default: ENV['CAPISTRANO_JIRA_SITE']
35
+ set :jira_project_key, 'PROJ' # required
36
+ ```
37
+
38
+ - Set parameters for specific environment (for example `config/deploy/staging.rb`)
39
+ ```ruby
40
+ set :jira_status_name, 'QA passed' # required; name of status from which issues should be transited
41
+ set :jira_transition_name, 'Deploy to staging' # required; name of transition that should be executed
42
+ set :jira_filter_jql, 'component = Backend' # optional; additional JQL filter to scope issues
43
+ ```
44
+
45
+ Then while running deployment you should see transitioned issues.
46
+
47
+ When transition fails for some reason (for example HTTP Error) it will inform you but NOT fail whole deployment.
48
+
49
+ ## Checking setup
50
+
51
+ To check if setup is proper or diagnose a problem run for your environment
52
+ ```
53
+ cap staging jira:check
54
+ ```
55
+
56
+ Proper output will be similar to this:
57
+ ```
58
+ => Required params
59
+ jira_username = wojtek@codegarden.online
60
+ jira_password = **********
61
+ jira_site = https://example.atlassian.net
62
+ jira_project_key = PROJ
63
+ jira_status_name = QA passed
64
+ jira_transition_name = Deploy to staging
65
+ <= OK
66
+ => Checking connection
67
+ <= OK
68
+ => Checking for given project key
69
+ <= OK
70
+ ```
71
+ ## Development
72
+
73
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
74
+
75
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
76
+
77
+ ## Contributing
78
+
79
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/capistrano-jira.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'capistrano/jira'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capistrano/jira/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'capistrano-jira'
8
+ spec.version = Capistrano::Jira::VERSION
9
+ spec.authors = ['Wojciech Widenka']
10
+ spec.email = ['wojtek@codegarden.online']
11
+
12
+ spec.summary =
13
+ 'Automated JIRA issues transitions after deployment with Capistrano'
14
+ spec.homepage = 'https://github.com/wojw5/capistrano-jira'
15
+
16
+ spec.files = `git ls-files -z`
17
+ .split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'capistrano'
22
+ spec.add_dependency 'jira-ruby'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.12'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rspec', '~> 3.0'
27
+ end
@@ -0,0 +1,6 @@
1
+ module Capistrano
2
+ module Jira
3
+ class TransitionError < StandardError; end
4
+ class FinderError < StandardError; end
5
+ end
6
+ end
@@ -0,0 +1,33 @@
1
+ module Capistrano
2
+ module Jira
3
+ class IssueFinder
4
+ attr_reader :issues
5
+
6
+ def find!
7
+ @issues = execute
8
+ end
9
+
10
+ def find
11
+ @issues ||= execute
12
+ end
13
+
14
+ private
15
+
16
+ def jql
17
+ [
18
+ "project = #{fetch(:jira_project_key)}",
19
+ "status = #{fetch(:jira_status_name)}",
20
+ fetch(:jira_filter_jql)
21
+ ].compact.join(' AND ')
22
+ end
23
+
24
+ def execute
25
+ Jira.client.Issue.jql(jql, fields: ['status'], max_results: 1_000_000)
26
+ rescue JIRA::HTTPError => e
27
+ r = e.response
28
+ raise FinderError,
29
+ "#{r.class.name}; #{r.code}: #{r.message} \n #{r.body}"
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,39 @@
1
+ module Capistrano
2
+ module Jira
3
+ class IssueTransiter
4
+ attr_reader :issue
5
+
6
+ def initialize(issue)
7
+ @issue = issue
8
+ end
9
+
10
+ def transit
11
+ validate_transition
12
+ execute
13
+ end
14
+
15
+ private
16
+
17
+ def transition
18
+ @transition ||= issue.transitions.all.find do |t|
19
+ t.attrs['name'].casecmp(fetch(:jira_transition_name)).zero?
20
+ end
21
+ end
22
+
23
+ def validate_transition
24
+ unless transition
25
+ raise TransitionError,
26
+ "Transition #{fetch(:jira_transition_name)} not available"
27
+ end
28
+ end
29
+
30
+ def execute
31
+ issue.transitions.build.save!(transition: { id: transition.id })
32
+ rescue JIRA::HTTPError => e
33
+ r = e.response
34
+ raise TransitionError,
35
+ "#{r.class.name}; #{r.code}: #{r.message} \n #{r.body}"
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module Jira
3
+ VERSION = '0.1.0'.freeze
4
+ end
5
+ end
@@ -0,0 +1,19 @@
1
+ require 'capistrano/jira/version'
2
+ require 'capistrano/jira/errors'
3
+ require 'capistrano/jira/issue_finder'
4
+ require 'capistrano/jira/issue_transiter'
5
+ require 'jira-ruby'
6
+
7
+ module Capistrano
8
+ module Jira
9
+ def self.client
10
+ ::JIRA::Client.new(username: fetch(:jira_username),
11
+ password: fetch(:jira_password),
12
+ site: fetch(:jira_site),
13
+ context_path: '',
14
+ auth_type: :basic)
15
+ end
16
+ end
17
+ end
18
+
19
+ load File.expand_path('../tasks/jira.rake', __FILE__)
@@ -0,0 +1,59 @@
1
+ namespace :load do
2
+ task :defaults do
3
+ set :jira_username, ENV['CAPISTRANO_JIRA_USERNAME']
4
+ set :jira_password, ENV['CAPISTRANO_JIRA_PASSWORD']
5
+ set :jira_site, ENV['CAPISTRANO_JIRA_SITE']
6
+ set :jira_project_key, nil
7
+ set :jira_status_name, nil
8
+ set :jira_transition_name, nil
9
+ set :jira_filter_jql, nil
10
+ end
11
+ end
12
+
13
+ namespace :jira do
14
+ desc 'Find and transit possible JIRA issues'
15
+ task :find_and_transit do |_t|
16
+ puts 'Looking for issues'
17
+ issues = Capistrano::Jira::IssueFinder.new.find
18
+ issues.each do |issue|
19
+ begin
20
+ Capistrano::Jira::IssueTransiter.new(issue).transit
21
+ puts "#{issue.key}\t\u{2713} Transited"
22
+ rescue Capistrano::Jira::TransitionError => e
23
+ puts "#{issue.key}\t\u{2717} #{e.message}"
24
+ end
25
+ end
26
+ end
27
+
28
+ desc 'Check JIRA setup'
29
+ task :check do
30
+ errored = false
31
+ required_params = %i(jira_username jira_password jira_site jira_project_key
32
+ jira_status_name jira_transition_name)
33
+ puts '=> Required params'
34
+ required_params.each do |param|
35
+ print "#{param} = "
36
+ if fetch(param).nil? || fetch(param) == ''
37
+ puts '!!!!!! EMPTY !!!!!!'
38
+ errored = true
39
+ else
40
+ puts param == :jira_password ? '**********' : fetch(param)
41
+ end
42
+ end
43
+ raise StandardError, 'Not all required parameters are set' if errored
44
+ puts '<= OK'
45
+
46
+ puts '=> Checking connection'
47
+ projects = ::Capistrano::Jira.client.Project.all
48
+ puts '<= OK'
49
+
50
+ puts '=> Checking for given project key'
51
+ exist = projects.any? { |project| project.key == fetch(:jira_project_key) }
52
+ unless exist
53
+ raise StandardError, "Project #{fetch(:jira_project_key)} not found"
54
+ end
55
+ puts '<= OK'
56
+ end
57
+
58
+ after 'deploy:finished', 'jira:find_and_transit'
59
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-jira
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Wojciech Widenka
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capistrano
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: jira-ruby
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: '1.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.12'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description:
84
+ email:
85
+ - wojtek@codegarden.online
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/setup
98
+ - capistrano-jira.gemspec
99
+ - lib/capistrano/jira.rb
100
+ - lib/capistrano/jira/errors.rb
101
+ - lib/capistrano/jira/issue_finder.rb
102
+ - lib/capistrano/jira/issue_transiter.rb
103
+ - lib/capistrano/jira/version.rb
104
+ - lib/capistrano/tasks/jira.rake
105
+ homepage: https://github.com/wojw5/capistrano-jira
106
+ licenses: []
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.5.1
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Automated JIRA issues transitions after deployment with Capistrano
128
+ test_files: []