danger-pivotal_tracker 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in danger-pivotal_tracker.gemspec
4
+ gemspec
5
+
6
+ gem 'danger-auto_label'
7
+
8
+ gem 'simplecov', require: false, group: :test
@@ -0,0 +1,148 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ danger-pivotal_tracker (0.0.1)
5
+ danger-plugin-api (~> 1.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.6.0)
11
+ public_suffix (>= 2.0.2, < 4.0)
12
+ ast (2.4.0)
13
+ claide (1.0.2)
14
+ claide-plugins (0.9.2)
15
+ cork
16
+ nap
17
+ open4 (~> 1.3)
18
+ coderay (1.1.2)
19
+ colored2 (3.1.2)
20
+ cork (0.3.0)
21
+ colored2 (~> 3.1)
22
+ danger (6.0.9)
23
+ claide (~> 1.0)
24
+ claide-plugins (>= 0.9.2)
25
+ colored2 (~> 3.1)
26
+ cork (~> 0.1)
27
+ faraday (~> 0.9)
28
+ faraday-http-cache (~> 2.0)
29
+ git (~> 1.5)
30
+ kramdown (~> 2.0)
31
+ kramdown-parser-gfm (~> 1.0)
32
+ no_proxy_fix
33
+ octokit (~> 4.7)
34
+ terminal-table (~> 1)
35
+ danger-auto_label (1.3.1)
36
+ danger-plugin-api (~> 1.0)
37
+ danger-plugin-api (1.0.0)
38
+ danger (> 2.0)
39
+ diff-lcs (1.3)
40
+ docile (1.3.2)
41
+ faraday (0.15.4)
42
+ multipart-post (>= 1.2, < 3)
43
+ faraday-http-cache (2.0.0)
44
+ faraday (~> 0.8)
45
+ ffi (1.11.1)
46
+ formatador (0.2.5)
47
+ git (1.5.0)
48
+ guard (2.15.0)
49
+ formatador (>= 0.2.4)
50
+ listen (>= 2.7, < 4.0)
51
+ lumberjack (>= 1.0.12, < 2.0)
52
+ nenv (~> 0.1)
53
+ notiffany (~> 0.0)
54
+ pry (>= 0.9.12)
55
+ shellany (~> 0.0)
56
+ thor (>= 0.18.1)
57
+ guard-compat (1.2.1)
58
+ guard-rspec (4.7.3)
59
+ guard (~> 2.1)
60
+ guard-compat (~> 1.1)
61
+ rspec (>= 2.99.0, < 4.0)
62
+ jaro_winkler (1.5.3)
63
+ json (2.2.0)
64
+ kramdown (2.1.0)
65
+ kramdown-parser-gfm (1.1.0)
66
+ kramdown (~> 2.0)
67
+ listen (3.0.7)
68
+ rb-fsevent (>= 0.9.3)
69
+ rb-inotify (>= 0.9.7)
70
+ lumberjack (1.0.13)
71
+ method_source (0.9.2)
72
+ multipart-post (2.1.1)
73
+ nap (1.1.0)
74
+ nenv (0.3.0)
75
+ no_proxy_fix (0.1.2)
76
+ notiffany (0.1.1)
77
+ nenv (~> 0.1)
78
+ shellany (~> 0.0)
79
+ octokit (4.14.0)
80
+ sawyer (~> 0.8.0, >= 0.5.3)
81
+ open4 (1.3.4)
82
+ parallel (1.17.0)
83
+ parser (2.6.3.0)
84
+ ast (~> 2.4.0)
85
+ pry (0.12.2)
86
+ coderay (~> 1.1.0)
87
+ method_source (~> 0.9.0)
88
+ public_suffix (3.1.1)
89
+ rainbow (3.0.0)
90
+ rake (10.5.0)
91
+ rb-fsevent (0.10.3)
92
+ rb-inotify (0.10.0)
93
+ ffi (~> 1.0)
94
+ rspec (3.8.0)
95
+ rspec-core (~> 3.8.0)
96
+ rspec-expectations (~> 3.8.0)
97
+ rspec-mocks (~> 3.8.0)
98
+ rspec-core (3.8.2)
99
+ rspec-support (~> 3.8.0)
100
+ rspec-expectations (3.8.4)
101
+ diff-lcs (>= 1.2.0, < 2.0)
102
+ rspec-support (~> 3.8.0)
103
+ rspec-mocks (3.8.1)
104
+ diff-lcs (>= 1.2.0, < 2.0)
105
+ rspec-support (~> 3.8.0)
106
+ rspec-support (3.8.2)
107
+ rubocop (0.73.0)
108
+ jaro_winkler (~> 1.5.1)
109
+ parallel (~> 1.10)
110
+ parser (>= 2.6)
111
+ rainbow (>= 2.2.2, < 4.0)
112
+ ruby-progressbar (~> 1.7)
113
+ unicode-display_width (>= 1.4.0, < 1.7)
114
+ ruby-progressbar (1.10.1)
115
+ sawyer (0.8.2)
116
+ addressable (>= 2.3.5)
117
+ faraday (> 0.8, < 2.0)
118
+ shellany (0.0.1)
119
+ simplecov (0.17.0)
120
+ docile (~> 1.1)
121
+ json (>= 1.8, < 3)
122
+ simplecov-html (~> 0.10.0)
123
+ simplecov-html (0.10.2)
124
+ terminal-table (1.8.0)
125
+ unicode-display_width (~> 1.1, >= 1.1.1)
126
+ thor (0.20.3)
127
+ unicode-display_width (1.6.0)
128
+ yard (0.9.20)
129
+
130
+ PLATFORMS
131
+ ruby
132
+
133
+ DEPENDENCIES
134
+ bundler
135
+ danger-auto_label
136
+ danger-pivotal_tracker!
137
+ guard (~> 2.14)
138
+ guard-rspec (~> 4.7)
139
+ listen (= 3.0.7)
140
+ pry
141
+ rake (~> 10.0)
142
+ rspec (~> 3.4)
143
+ rubocop
144
+ simplecov
145
+ yard
146
+
147
+ BUNDLED WITH
148
+ 2.0.1
@@ -0,0 +1,19 @@
1
+ # A guardfile for making Danger Plugins
2
+ # For more info see https://github.com/guard/guard#readme
3
+
4
+ # To run, use `bundle exec guard`.
5
+
6
+ guard :rspec, cmd: 'bundle exec rspec' do
7
+ require 'guard/rspec/dsl'
8
+ dsl = Guard::RSpec::Dsl.new(self)
9
+
10
+ # RSpec files
11
+ rspec = dsl.rspec
12
+ watch(rspec.spec_helper) { rspec.spec_dir }
13
+ watch(rspec.spec_support) { rspec.spec_dir }
14
+ watch(rspec.spec_files)
15
+
16
+ # Ruby files
17
+ ruby = dsl.ruby
18
+ dsl.watch_spec_files_for(ruby.lib_files)
19
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2019 Kevin Morton <kevnm67@gmail.com>
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,58 @@
1
+ # Danger Pivotal Tracker Plugin
2
+ <!-- TOC depthFrom:1 depthTo:6 withLinks:1 updateOnSave:1 orderedList:0 -->
3
+
4
+ - [Danger Pivotal Tracker Plugin](#danger-pivotal-tracker-plugin)
5
+ - [Installation](#installation)
6
+ - [Usage](#usage)
7
+ - [Development](#development)
8
+
9
+ <!-- /TOC -->
10
+ <body>
11
+ <table>
12
+ <thead>
13
+ <tr>
14
+ <th>Service</th>
15
+ <th>Badge</th>
16
+ </tr>
17
+ </thead>
18
+ <tbody>
19
+ <tr>
20
+ <td>Travis CI (Master)</td>
21
+ <td><a href="https://travis-ci.com/kevnm67/danger-pivotal_tracker"><img src="https://travis-ci.com/kevnm67/danger-pivotal_tracker.svg?branch=master" /></a></td>
22
+ </tr>
23
+ <tr>
24
+ <td>Travis CI (Develop)</td>
25
+ <td><a href="https://travis-ci.com/kevnm67/danger-pivotal_tracker"><img src="https://travis-ci.com/kevnm67/danger-pivotal_tracker.svg?branch=develop" /></a></td>
26
+ </tr>
27
+ <tr>
28
+ <td>Code Climate</td>
29
+ <td><a href="https://codeclimate.com/github/kevnm67/danger-pivotal_tracker/maintainability"><img src="https://api.codeclimate.com/v1/badges/ad4a58bf6d0c81d8e6f4/maintainability" /></a></td>
30
+ </tr>
31
+ <tr>
32
+ <td>Code Coverage</td>
33
+ <td><a href="https://codeclimate.com/github/kevnm67/danger-pivotal_tracker/test_coverage"><img src="https://api.codeclimate.com/v1/badges/ad4a58bf6d0c81d8e6f4/test_coverage" /></a></td>
34
+ </tr>
35
+ </tbody>
36
+ </table>
37
+ </body>
38
+
39
+
40
+ ## Installation
41
+
42
+ $ gem install danger-pivotal_tracker
43
+
44
+ ## Usage
45
+
46
+ Methods and attributes from this plugin are available in
47
+ your `Dangerfile` under the `pivotal_tracker` namespace.
48
+
49
+ ## Development
50
+
51
+ 1. Clone this repo
52
+ 2. Run `bundle install` to setup dependencies.
53
+ 3. Run `bundle exec rake spec` to run the tests.
54
+ 4. Use `bundle exec guard` to automatically have tests run as you make changes.
55
+ 5. Make your changes.
56
+
57
+
58
+ ![](./docs/images/walter-code-cov.jpeg)
@@ -0,0 +1,23 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:specs)
6
+
7
+ task default: :specs
8
+
9
+ task :spec do
10
+ Rake::Task['specs'].invoke
11
+ Rake::Task['rubocop'].invoke
12
+ Rake::Task['spec_docs'].invoke
13
+ end
14
+
15
+ desc 'Run RuboCop on the lib/specs directory'
16
+ RuboCop::RakeTask.new(:rubocop) do |task|
17
+ task.patterns = ['lib/**/*.rb', 'spec/**/*.rb']
18
+ end
19
+
20
+ desc 'Ensure that the plugin passes `danger plugins lint`'
21
+ task :spec_docs do
22
+ sh 'bundle exec danger plugins lint'
23
+ end
@@ -0,0 +1,50 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pivotal_tracker/gem_version.rb'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'danger-pivotal_tracker'
8
+ spec.version = PivotalTracker::VERSION
9
+ spec.authors = ['Kevin Morton']
10
+ spec.email = ['']
11
+ spec.description = %q{A short description of danger-pivotal_tracker.}
12
+ spec.summary = %q{A longer description of danger-pivotal_tracker.}
13
+ spec.homepage = 'https://github.com/kevnm67/danger-pivotal_tracker'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+ spec.metadata["yard.run"] = "yri" # use "yard" to build full HTML docs.
21
+
22
+ spec.add_runtime_dependency 'danger-plugin-api', '~> 1.0'
23
+
24
+ # General ruby development
25
+ spec.add_development_dependency 'bundler'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+
28
+ # Testing support
29
+ spec.add_development_dependency 'rspec', '~> 3.4'
30
+
31
+ # Linting code and docs
32
+ spec.add_development_dependency "rubocop"
33
+ spec.add_development_dependency "yard"
34
+
35
+ # Makes testing easy via `bundle exec guard`
36
+ spec.add_development_dependency 'guard', '~> 2.14'
37
+ spec.add_development_dependency 'guard-rspec', '~> 4.7'
38
+
39
+ # If you want to work on older builds of ruby
40
+ spec.add_development_dependency 'listen', '3.0.7'
41
+
42
+ # This gives you the chance to run a REPL inside your tests
43
+ # via:
44
+ #
45
+ # require 'pry'
46
+ # binding.pry
47
+ #
48
+ # This will stop test execution and let you inspect the results
49
+ spec.add_development_dependency 'pry'
50
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pivotal_tracker/gem_version"
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pivotal_tracker/plugin"
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PivotalTracker
4
+ VERSION = "0.0.2"
5
+ end
@@ -0,0 +1,134 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Danger
4
+ # This is your plugin class. Any attributes or methods you expose here will
5
+ # be available from within your Dangerfile.
6
+ #
7
+ # To be published on the Danger plugins site, you will need to have
8
+ # the public interface documented. Danger uses [YARD](http://yardoc.org/)
9
+ # for generating documentation from your plugin source, and you can verify
10
+ # by running `danger plugins lint` or `bundle exec rake spec`.
11
+ #
12
+ # @example Check the PR for pivotal tracker story ID's and, if found, post links in the comments.
13
+ #
14
+ # check(key: "Delivered", project_id: "PROJECT_ID")
15
+ #
16
+ # @see kevnm67/danger-pivotal_tracker
17
+ # @tags pivotal-tracker, pivotal
18
+ #
19
+ class DangerPivotalTracker < Plugin
20
+ # Checks PR for pivotal stories and post links to the PR comments.
21
+ #
22
+ # @param [Array] key
23
+ # An array of story status's (e.g. Delivered, Finished, etc.)
24
+ #
25
+ # @param [String] project_id
26
+ # The pivotal tracker project ID.
27
+ #
28
+ # @param [String] emoji
29
+ # The emoji you want to display in the message.
30
+ #
31
+ # @param [Boolean] search_title
32
+ # Option to evaluate the PR title for matching pivotal stories.
33
+ #
34
+ # @param [Boolean] search_commits
35
+ # Option to evaluate commits for story matches.
36
+ #
37
+ # @param [Boolean] fail_on_warning
38
+ # Option to fail danger if no stories are found
39
+ #
40
+ # @param [Boolean] report_missing
41
+ # Option to report if no storues were found
42
+ #
43
+ # @return [void]
44
+ #
45
+ def check(key: "", project_id: "nil", emoji: ":link:", search_title: true, search_commits: false, fail_on_warning: false, report_missing: true)
46
+ url = "https://www.pivotaltracker.com/n/projects/#{project_id}/stories/"
47
+
48
+ throw Error("'key' missing - must supply an array of story ids") if key.nil?
49
+
50
+ pivotal_stories = find_pivotal_stories(key: key, search_title: search_title, search_commits: search_commits)
51
+
52
+ if !pivotal_stories.empty?
53
+ story_urls = pivotal_stories.map { |issue| link(href: ensure_url_ends_with_slash(url), issue: issue) }.join(", ")
54
+ message("#{emoji} #{story_urls}")
55
+ elsif report_missing
56
+ msg = "No story ID's were matched in the PR title or commit messages (e.g. [\#123])"
57
+
58
+ if fail_on_warning
59
+ fail(msg)
60
+ else
61
+ warn(msg)
62
+ end
63
+ end
64
+ end
65
+
66
+ # Attempts to find story ID's from PR metadata.
67
+ #
68
+ # @param key [Type] default: nil
69
+ # @param search_title [Type] default: true
70
+ # @param search_commits [Type] default: false
71
+ # @return [Type] Matches story ids.
72
+ def find_pivotal_stories(key: nil, search_title: true, search_commits: true)
73
+ keys = key.kind_of?(Array) ? key.join(" |") : key
74
+ story_key_regex_string = /(#{keys} )#(\d{6,})/i
75
+ regexp = Regexp.new(/#{story_key_regex_string}/)
76
+
77
+ matching_stories = []
78
+
79
+ if search_title
80
+ github.pr_title.gsub(regexp) do |match|
81
+ matching_stories << extract_id(match).first
82
+
83
+ puts "matches #{matching_stories}"
84
+ end
85
+ end
86
+
87
+ if search_commits
88
+ puts "git commits #{git.commits}"
89
+ git.commits.map do |commit|
90
+ commit.message.gsub(regexp) do |match|
91
+ matching_stories << extract_id(match).first
92
+ end
93
+ end
94
+ end
95
+
96
+ if matching_stories.empty?
97
+ github.pr_body.gsub(regexp) do |match|
98
+ matching_stories << extract_id(match).first
99
+ end
100
+ end
101
+
102
+ return matching_stories.uniq
103
+ end
104
+
105
+ private
106
+
107
+ # Extracts all numbers from a given string.
108
+ #
109
+ # @param str [String] String to evaluate.
110
+ # @return [String] Numberical string.
111
+ def extract_id(str)
112
+ str.to_s.scan(/\d+/)
113
+ end
114
+
115
+ # Adds a slash at the end of the url if needed.
116
+ #
117
+ # @param url [String] URL to evaluate.
118
+ # @return [String] URL ending with a slash.
119
+ def ensure_url_ends_with_slash(url)
120
+ return "#{url}/" unless url.end_with?("/")
121
+
122
+ return url
123
+ end
124
+
125
+ # Creates an HTML string to post to the PR comments.
126
+ #
127
+ # @param href [String] default: nil.
128
+ # @param issue [String] default: nil
129
+ # @return [String] HTML string linking to the story issue.
130
+ def link(href: nil, issue: nil)
131
+ return "<a href='#{href}#{issue}'>#{issue}</a>"
132
+ end
133
+ end
134
+ end