git_flower 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 437cd16229bd94b676971ac50d6b86f4d792fe64
4
+ data.tar.gz: 171eee617b2500ead9a364c380effc833e1e082a
5
+ SHA512:
6
+ metadata.gz: ab3da35e297f3cab5bda3d0056722712f3dd659726139b43a6c5f3dbca42b5e98837e2b142eb43c92a99cbde882f3250a7eb0daa30f7f06ba11d84153c2a0e0c
7
+ data.tar.gz: 26397d79ff5f5deb4157587c1cab10c798271d65c6dbfa8e2c1dc24383370525712bfd65f372face2021b6d292d8ae5b1feb1f910312f4cd34c2acc9d3a4a936
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ .byebug_history
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
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.4.1
5
+ before_install: gem install bundler -v 1.15.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at alex.wilkinson@me.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in git_flower.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,89 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ git_flower (0.1.1)
5
+ activesupport (~> 5.1.2)
6
+ faraday (~> 0.9.0)
7
+ git (~> 1.3.0)
8
+ thor (~> 0.19.4)
9
+ tracker_api (= 0.2.9)
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ activemodel (5.1.2)
15
+ activesupport (= 5.1.2)
16
+ activesupport (5.1.2)
17
+ concurrent-ruby (~> 1.0, >= 1.0.2)
18
+ i18n (~> 0.7)
19
+ minitest (~> 5.1)
20
+ tzinfo (~> 1.1)
21
+ addressable (2.5.1)
22
+ public_suffix (~> 2.0, >= 2.0.2)
23
+ axiom-types (0.1.1)
24
+ descendants_tracker (~> 0.0.4)
25
+ ice_nine (~> 0.11.0)
26
+ thread_safe (~> 0.3, >= 0.3.1)
27
+ byebug (9.0.6)
28
+ coercible (1.0.0)
29
+ descendants_tracker (~> 0.0.1)
30
+ concurrent-ruby (1.0.5)
31
+ descendants_tracker (0.0.4)
32
+ thread_safe (~> 0.3, >= 0.3.1)
33
+ diff-lcs (1.3)
34
+ equalizer (0.0.11)
35
+ excon (0.57.1)
36
+ faraday (0.9.2)
37
+ multipart-post (>= 1.2, < 3)
38
+ faraday_middleware (0.11.0.1)
39
+ faraday (>= 0.7.4, < 1.0)
40
+ git (1.3.0)
41
+ i18n (0.8.5)
42
+ ice_nine (0.11.2)
43
+ minitest (5.10.2)
44
+ multipart-post (2.0.0)
45
+ public_suffix (2.0.5)
46
+ rake (10.5.0)
47
+ rspec (3.6.0)
48
+ rspec-core (~> 3.6.0)
49
+ rspec-expectations (~> 3.6.0)
50
+ rspec-mocks (~> 3.6.0)
51
+ rspec-core (3.6.0)
52
+ rspec-support (~> 3.6.0)
53
+ rspec-expectations (3.6.0)
54
+ diff-lcs (>= 1.2.0, < 2.0)
55
+ rspec-support (~> 3.6.0)
56
+ rspec-mocks (3.6.0)
57
+ diff-lcs (>= 1.2.0, < 2.0)
58
+ rspec-support (~> 3.6.0)
59
+ rspec-support (3.6.0)
60
+ thor (0.19.4)
61
+ thread_safe (0.3.6)
62
+ tracker_api (0.2.9)
63
+ activemodel
64
+ activesupport
65
+ addressable
66
+ excon
67
+ faraday (~> 0.9.0)
68
+ faraday_middleware
69
+ virtus
70
+ tzinfo (1.2.3)
71
+ thread_safe (~> 0.1)
72
+ virtus (1.0.5)
73
+ axiom-types (~> 0.1)
74
+ coercible (~> 1.0)
75
+ descendants_tracker (~> 0.0, >= 0.0.3)
76
+ equalizer (~> 0.0, >= 0.0.9)
77
+
78
+ PLATFORMS
79
+ ruby
80
+
81
+ DEPENDENCIES
82
+ bundler (~> 1.15)
83
+ byebug
84
+ git_flower!
85
+ rake (~> 10.0)
86
+ rspec (~> 3.0)
87
+
88
+ BUNDLED WITH
89
+ 1.15.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Alex Wilkinson
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,115 @@
1
+ # GitFlower
2
+
3
+ GitFlower is a command-line utility that starts features and hotfixes using the git-flow branching model and creates corresponding features and bugs on PivotalTracker using the Pivotal API. Link tickets in Pivotal with your git-flow branches without leaving the comfort of the command line!
4
+
5
+ While GitFlower only supports Pivotal at the moment, the plan is to add support for all popular project management systems. Once I have developed an adapter system for easily working with multiple APIs, I will publish my priority list on this README.
6
+
7
+ If I'm not currently planning on adding your favorite PM tool, or it's not happening fast enough, feel free to contribute!
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'git_flower'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install git_flower
24
+
25
+ You will have to export your Pivotal API Key and a Project ID from your
26
+ environment. Here's an example of how to do so in ZSH:
27
+
28
+ ```zsh
29
+ export PIVOTAL_TOKEN="TOKEN HERE"
30
+ export PIVOTAL_PROJECT_ID="some_number_here"
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ The `git-flower create` commands will create a Pivotal story for your feature or hotfix, start a git-flow branch off of develop, and check out that branch. All you need to do is pass a story name, and it will set a titleized version as the Pivotal ticket name and a slugified version as the branch name.
36
+
37
+ The commands won't run under the following conditions:
38
+
39
+ * You have added but uncommitted git changes.
40
+ * Local develop is not up to date with origin.
41
+
42
+ By default, it will use `$USER` as the owner of the Pivotal story. For Pivotal to properly assign the owner, the name of your Pivotal user needs to match`$USER`.
43
+
44
+ ### Feature
45
+
46
+ To create a new feature, with optional labels for the Pivotal feature, run the
47
+ following:
48
+
49
+ $ git-flower feature create [NAME] [--labels=one two three]
50
+
51
+ So if you wanted to create a Pivotal feature named "Save All The Cats" with the labels `cat` and `life-goal`, you could execute the following:
52
+
53
+ $ git-flower feature create "Save All The Cats" --labels cat life-goal
54
+
55
+ And you will be checked out to the following branch, where the number
56
+ represents the Pivotal Story ID.
57
+
58
+ ```
59
+ feature/1234-save-all-the-cats
60
+ ```
61
+
62
+ Your Pivotal Feature would look something like this:
63
+
64
+ ![Pivotal Feature Example](https://photos-1.dropbox.com/t/2/AADrhIDYH53IfCbz1VtLnPrNYX0MIHau-ub8g2cqxyclxQ/12/49046/png/32x32/3/1499760000/0/2/git-flower-feature.png/EIbdIhi4-dHgBCACKAI/-z2SbCaiHwKR-cyBs3xEw6ru8kdKgh7Fr8NEtw75NFI?dl=0&size=2048x1536&size_mode=3)
65
+
66
+ ### Hotfix
67
+
68
+ To create a new hotfix, with optional labels for the Pivotal bug, run the
69
+ following:
70
+
71
+ $ git-flower hotfix create [NAME] [--labels=one two three]
72
+
73
+ So if you wanted to create a Pivotal bug named "Missing Cat" with
74
+ the labels `cat` and `nightmare`, you could execute the following:
75
+
76
+ $ git-flower hotfix create "Missing Cat" --labels cat nightmare
77
+
78
+ And you will be checked out to the following branch, where the number
79
+ represents the Pivotal Story ID.
80
+
81
+ ```
82
+ hotfix/5678-missing-cat
83
+ ```
84
+
85
+ Your Pivotal Bug would look something like this:
86
+
87
+ ![Pivotal Bug Example](https://photos-2.dropbox.com/t/2/AADERZmXtrsHQ202P285d5je1vTwaRHK6PZtQTNkknzbjQ/12/49046/png/32x32/3/1499763600/0/2/git-flower-bug.png/EIbdIhi4-dHgBCACKAI/VCWQS444mMy3075Fb1w4mf4vmfuz5js8GPKfI87yI_M?dl=0&size=2048x1536&size_mode=3)
88
+
89
+ ### Hitch Integration
90
+
91
+ If you're a pair programmer, and would like to set joint assignees on your
92
+ Pivotal tickets using [Hitch](https://github.com/therubymug/hitch), make sure you have the library configured and have a `.hitchrc` file in your home directory.
93
+
94
+ If all is set up correctly, GitFlower will detect who you are hitched with and
95
+ add both as story owners. If you are not hitched with anyone, it will default
96
+ to `$USER`.
97
+
98
+ ## Development
99
+
100
+ 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.
101
+
102
+ 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).
103
+
104
+ ## Contributing
105
+
106
+ Bug reports and pull requests are welcome on GitLab at https://gitlab.com/alexwilkinson/git-flower. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
107
+
108
+ ## License
109
+
110
+ The gem is available as open source under the terms of the [MIT
111
+ License](http://opensource.org/licenses/MIT).
112
+
113
+ ## Code of Conduct
114
+
115
+ Everyone interacting in the GitFlower project’s code base and issue trackers is expected to follow the [code of conduct](https://gitlab.com/alexwilkinson/git-flower/blob/master/CODE_OF_CONDUCT.md).
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 "git_flower"
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(__FILE__)
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
data/exe/git-flower ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../lib/git_flower/cli'
3
+
4
+ GitFlower::CLI.start(ARGV)
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "git_flower/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "git_flower"
8
+ spec.version = GitFlower::VERSION
9
+ spec.authors = ["Alex Wilkinson"]
10
+ spec.email = ["alex.wilkinson@me.com"]
11
+
12
+ spec.summary = %q{A CLI for starting git-flow features and hotfixes on PivotalTracker.}
13
+ spec.description = %q{This library starts features and hotfixes using the git-flow branching model and creates corresponding features and bugs on PivotalTracker using the Pivotal API.}
14
+ spec.homepage = "https://gitlab.com/alexwilkinson/git-flower"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.15"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency "byebug"
28
+
29
+ spec.add_dependency "git", "~> 1.3.0"
30
+ spec.add_dependency "thor", "~> 0.19.4"
31
+ spec.add_dependency "activesupport", "~> 5.1.2"
32
+ spec.add_dependency "faraday", "~> 0.9.0"
33
+ spec.add_dependency "tracker_api", "0.2.9"
34
+ end
data/lib/git_flower.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "git_flower/version"
2
+ require "git_flower/story"
3
+ require "git_flower/feature"
4
+ require "git_flower/hotfix"
5
+ require "git_flower/git_repository"
6
+ require "git_flower/pivotal_project"
7
+
8
+ module GitFlower
9
+ end
@@ -0,0 +1,13 @@
1
+ require 'thor'
2
+ require_relative './feature-cli.rb'
3
+ require_relative './hotfix-cli.rb'
4
+
5
+ module GitFlower
6
+ class CLI < Thor
7
+ desc "feature SUBCOMMAND ...ARGS", "manage git-flow features"
8
+ subcommand "feature", GitFlower::FeatureCLI
9
+
10
+ desc "hotfix SUBCOMMAND ...ARGS", "manage git-flow hotfixes"
11
+ subcommand "hotfix", GitFlower::HotfixCLI
12
+ end
13
+ end
@@ -0,0 +1,58 @@
1
+ require 'thor'
2
+ require_relative 'feature'
3
+
4
+ module GitFlower
5
+ class FeatureCLI < Thor
6
+ namespace :feature
7
+
8
+ desc "create STORY_NAME [--labels=one two three]", "Create hotfix story and git branch for it"
9
+ long_desc <<-desc
10
+ This script will create a feature pivotal story and start a feature branch for
11
+ you. All you need to do is pass a story name. It will then create the branch
12
+ name using a slugified version of the name you passed it.
13
+
14
+ It will detect who you are hitched with and add both as story owners.
15
+
16
+ It won't run under the following conditions:
17
+ \x5 * You have added but uncommitted git changes.
18
+ \x5 * If local develop is not up to date with origin.
19
+
20
+ If you want to use it, you have to add your Pivotal API Key and Pivotal
21
+ Project ID as environment variables.
22
+
23
+ You can find the your token at the bottom of the User Profile page on Pivotal,
24
+ which you can get to by clicking your name in the top right corner.
25
+ \x5 export PIVOTAL_TOKEN="TOKEN HERE"
26
+ \x5 export PIVOTAL_PROJECT_ID="some_number_here"
27
+
28
+ This script can also detect if you are "hitched" with someone using the
29
+ hitch gem (it reads ~/.hitchrc), and add who you are hitched with as story
30
+ owners. If you don't hitch the Pivotal card will be assigned to $USER (note
31
+ your Pivotal user needs to match your unix user in this case)
32
+
33
+ > feature create 'Do The Needful'
34
+ desc
35
+
36
+ option :labels, type: :array, desc: "The labels you want to apply to your story"
37
+
38
+ def create(story_name)
39
+ feature = Feature.new(
40
+ story_name: story_name,
41
+ labels: options[:labels],
42
+ project_id: project_id,
43
+ pivotal_token: pivotal_token
44
+ )
45
+ feature.save!
46
+ end
47
+
48
+ private
49
+
50
+ def project_id
51
+ ENV['PIVOTAL_PROJECT_ID']
52
+ end
53
+
54
+ def pivotal_token
55
+ ENV['PIVOTAL_TOKEN']
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,23 @@
1
+ require 'active_support/inflector'
2
+ require_relative 'story'
3
+
4
+ module GitFlower
5
+ class Feature < Story
6
+ def save!
7
+ validate_environment_and_arguments!
8
+ validate_git_repository!
9
+
10
+ create_feature!
11
+ end
12
+
13
+ private
14
+
15
+ def validate_git_repository!
16
+ GitRepository.new(Dir.pwd).validate_for_feature!
17
+ end
18
+
19
+ def create_feature!
20
+ create_story!("feature")
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,80 @@
1
+ require 'git'
2
+
3
+ class GitError < StandardError; end
4
+ class GitFlowError < StandardError; end
5
+
6
+ module GitFlower
7
+ class GitRepository
8
+ def initialize(path_to_repo)
9
+ @repo = find_git_repo(path_to_repo)
10
+ end
11
+
12
+ def validate_for_hotfix!
13
+ puts "Checking for commited files"
14
+ if has_added_files?
15
+ raise GitError, "Please commit or stash all added files."
16
+ end
17
+
18
+ puts "Checking if master and develop are up to date"
19
+ if !master_up_to_date? || !develop_up_to_date?
20
+ raise GitError, "Please pull --rebase master and develop"
21
+ end
22
+
23
+ puts "Checking for existing hotfix branch"
24
+ if has_existing_branch_name?("hotfix")
25
+ raise GitFlowError, "You already have an existing hotfix branch"
26
+ end
27
+ end
28
+
29
+ def validate_for_feature!
30
+ puts "Checking for commited files"
31
+ if has_added_files?
32
+ raise GitError, "Please commit or stash all added files."
33
+ end
34
+
35
+ puts "Checking if develop is up to date"
36
+ if !develop_up_to_date?
37
+ raise GitError, "Please pull --rebase develop"
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def has_added_files?
44
+ !@repo.status.added.empty?
45
+ end
46
+
47
+ def master_up_to_date?
48
+ branch_up_to_date?('master')
49
+ end
50
+
51
+ def develop_up_to_date?
52
+ branch_up_to_date?('develop')
53
+ end
54
+
55
+ def has_existing_branch_name?(branch_name)
56
+ !@repo.branches.local.map(&:name).select { |name| name =~ /^#{branch_name}.*/ }.empty?
57
+ end
58
+
59
+ def branch_up_to_date?(branch_name)
60
+ @repo.revparse(branch_name) == @repo.revparse("origin/#{branch_name}")
61
+ end
62
+
63
+ def no_git_repo_can_be_found
64
+ !system 'git status'
65
+ end
66
+
67
+ def find_git_repo(initial_dir)
68
+ if no_git_repo_can_be_found
69
+ raise GitError
70
+ end
71
+
72
+ if Dir.exist?('.git')
73
+ Git.open(initial_dir)
74
+ else
75
+ Dir.chdir('..')
76
+ find_git_repo(Dir.pwd)
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,58 @@
1
+ require 'thor'
2
+ require_relative 'hotfix'
3
+
4
+ module GitFlower
5
+ class HotfixCLI < Thor
6
+ namespace :hotfix
7
+
8
+ desc "create STORY_NAME [labels]", "Create hotfix story and git branch for it"
9
+ long_desc <<-eoht
10
+ This script will create a bug pivotal story and start a hotfix branch for
11
+ you. All you need to do is pass a story name. It will then create the branch
12
+ name using a slugified version of the name you passed it.
13
+
14
+ It won't run under the following conditions:
15
+ \x5 * You have added but uncommitted git changes.
16
+ \x5 * If local master and develop are not up to date with origin.
17
+ \x5 * If you already have a local hotfix branch (because git-flow won't run)
18
+
19
+ If you want to use it, you have to add your Pivotal API Key and Pivotal
20
+ Project ID as environment variables.
21
+
22
+ You can find the your token at the bottom of the User Profile page on Pivotal,
23
+ which you can get to by clicking your name in the top right corner.
24
+ \x5 export PIVOTAL_TOKEN="TOKEN HERE"
25
+ \x5 export PIVOTAL_PROJECT_ID="some_number_here"
26
+
27
+ This script can also detect if you are "hitched" with someone using the
28
+ hitch gem (it reads ~/.hitchrc), and add who you are hitched with as story owners.
29
+ If you don't hitch the Pivotal card will
30
+ be assigned to $USER (note your Pivotal user needs to match your unix user
31
+ in this case)
32
+
33
+ create-hotfix create 'Do The Needful'
34
+ eoht
35
+
36
+ option :labels, type: :array, desc: "The labels you want to apply to your story"
37
+
38
+ def create(story_name)
39
+ hotfix = Hotfix.new(
40
+ story_name: story_name,
41
+ labels: options[:labels],
42
+ project_id: project_id,
43
+ pivotal_token: pivotal_token
44
+ )
45
+ hotfix.save!
46
+ end
47
+
48
+ private
49
+
50
+ def project_id
51
+ ENV['PIVOTAL_PROJECT_ID']
52
+ end
53
+
54
+ def pivotal_token
55
+ ENV['PIVOTAL_TOKEN']
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,23 @@
1
+ require 'active_support/inflector'
2
+ require_relative 'story'
3
+
4
+ module GitFlower
5
+ class Hotfix < Story
6
+ def save!
7
+ validate_environment_and_arguments!
8
+ validate_git_repository!
9
+
10
+ create_hotfix!
11
+ end
12
+
13
+ private
14
+
15
+ def validate_git_repository!
16
+ GitRepository.new(Dir.pwd).validate_for_hotfix!
17
+ end
18
+
19
+ def create_hotfix!
20
+ create_story!("hotfix")
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,48 @@
1
+ require 'tracker_api'
2
+
3
+ module GitFlower
4
+ class PivotalProject
5
+ def initialize(pivotal_token, project_id)
6
+ client = TrackerApi::Client.new(token: pivotal_token)
7
+ # we only have one project so this works well
8
+ @project = client.project(project_id)
9
+ end
10
+
11
+ def create_story(type, options)
12
+ if type == "feature"
13
+ create_feature(options)
14
+ elsif type == "hotfix"
15
+ create_hotfix(options)
16
+ end
17
+ end
18
+
19
+ def create_hotfix(options)
20
+ story_owner_ids = find_users(options[:owner_usernames]).map(&:id)
21
+ project.create_story(name: options[:name],
22
+ labels: options[:labels],
23
+ story_type: 'bug',
24
+ current_state: 'started',
25
+ owner_ids: story_owner_ids)
26
+ end
27
+
28
+ def create_feature(options)
29
+ story_owner_ids = find_users(options[:owner_usernames]).map(&:id)
30
+ project.create_story(name: options[:name],
31
+ labels: options[:labels],
32
+ story_type: 'feature',
33
+ current_state: 'started',
34
+ estimate: 0,
35
+ owner_ids: story_owner_ids)
36
+ end
37
+
38
+ private
39
+
40
+ attr_reader :project
41
+
42
+ def find_users(owner_usernames)
43
+ project.memberships.map(&:person).select do |person|
44
+ owner_usernames.include? person.email.split("@").first
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,75 @@
1
+ require 'shellwords'
2
+ require 'yaml'
3
+ require 'active_support'
4
+ require_relative 'git_repository'
5
+ require_relative 'pivotal_project'
6
+
7
+ module GitFlower
8
+ class Story
9
+ def initialize(story_name:, labels:, project_id:, pivotal_token:)
10
+ @story_name = story_name
11
+ @labels = Array(labels)
12
+ @project_id = project_id
13
+ @pivotal_token = pivotal_token
14
+ end
15
+
16
+ def create_story!(type)
17
+ if type.nil? || !["feature", "hotfix"].include?(type)
18
+ raise ArgumentError, "You need to specify that your story is a feature or a hotfix"
19
+ end
20
+
21
+ story = pivotal_project.create_story(type,
22
+ name: story_name.titleize,
23
+ labels: labels,
24
+ owner_usernames: derive_story_owners)
25
+
26
+ puts "Your pivotal story is https://www.pivotaltracker.com/story/show/#{story.id}"
27
+ puts "Creating #{type} branch for #{story_name}"
28
+
29
+ `git flow #{type} start #{branch_name(story.id)}`
30
+ end
31
+
32
+ private
33
+
34
+ attr_reader :story_name, :labels, :project_id, :pivotal_token
35
+
36
+ def validate_environment_and_arguments!
37
+ if env_variable_undefined?(story_name)
38
+ raise ArgumentError, "please pass a pivotal story name"
39
+ end
40
+
41
+ if env_variable_undefined?(project_id)
42
+ raise ArgumentError, "You need to populate the PIVOTAL_PROJECT_ID environment variable"
43
+ end
44
+
45
+ if env_variable_undefined?(pivotal_token)
46
+ raise ArgumentError, "You need to populate the PIVOTAL_TOKEN environment variable"
47
+ end
48
+ end
49
+
50
+ def env_variable_undefined?(variable)
51
+ variable.nil? || variable.empty?
52
+ end
53
+
54
+ def pivotal_project
55
+ PivotalProject.new(pivotal_token, project_id)
56
+ end
57
+
58
+ def derive_story_owners
59
+ begin
60
+ hitch_config = YAML.load_file("#{ENV['HOME']}/.hitchrc")
61
+ if hitch_config[:current_pair].empty?
62
+ Array(ENV['USER'])
63
+ else
64
+ hitch_config[:current_pair]
65
+ end
66
+ rescue
67
+ Array(ENV['USER'])
68
+ end
69
+ end
70
+
71
+ def branch_name(story_id)
72
+ Shellwords.shellescape("#{story_id}-#{story_name.parameterize}")
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,3 @@
1
+ module GitFlower
2
+ VERSION = "0.1.1"
3
+ end
metadata ADDED
@@ -0,0 +1,196 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git_flower
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Alex Wilkinson
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-07-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
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: git
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.3.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.3.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: thor
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.19.4
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.19.4
97
+ - !ruby/object:Gem::Dependency
98
+ name: activesupport
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 5.1.2
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 5.1.2
111
+ - !ruby/object:Gem::Dependency
112
+ name: faraday
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.9.0
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.9.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: tracker_api
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '='
130
+ - !ruby/object:Gem::Version
131
+ version: 0.2.9
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '='
137
+ - !ruby/object:Gem::Version
138
+ version: 0.2.9
139
+ description: This library starts features and hotfixes using the git-flow branching
140
+ model and creates corresponding features and bugs on PivotalTracker using the Pivotal
141
+ API.
142
+ email:
143
+ - alex.wilkinson@me.com
144
+ executables:
145
+ - git-flower
146
+ extensions: []
147
+ extra_rdoc_files: []
148
+ files:
149
+ - ".gitignore"
150
+ - ".rspec"
151
+ - ".travis.yml"
152
+ - CODE_OF_CONDUCT.md
153
+ - Gemfile
154
+ - Gemfile.lock
155
+ - LICENSE.txt
156
+ - README.md
157
+ - Rakefile
158
+ - bin/console
159
+ - bin/setup
160
+ - exe/git-flower
161
+ - git_flower.gemspec
162
+ - lib/git_flower.rb
163
+ - lib/git_flower/cli.rb
164
+ - lib/git_flower/feature-cli.rb
165
+ - lib/git_flower/feature.rb
166
+ - lib/git_flower/git_repository.rb
167
+ - lib/git_flower/hotfix-cli.rb
168
+ - lib/git_flower/hotfix.rb
169
+ - lib/git_flower/pivotal_project.rb
170
+ - lib/git_flower/story.rb
171
+ - lib/git_flower/version.rb
172
+ homepage: https://gitlab.com/alexwilkinson/git-flower
173
+ licenses:
174
+ - MIT
175
+ metadata: {}
176
+ post_install_message:
177
+ rdoc_options: []
178
+ require_paths:
179
+ - lib
180
+ required_ruby_version: !ruby/object:Gem::Requirement
181
+ requirements:
182
+ - - ">="
183
+ - !ruby/object:Gem::Version
184
+ version: '0'
185
+ required_rubygems_version: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ requirements: []
191
+ rubyforge_project:
192
+ rubygems_version: 2.6.12
193
+ signing_key:
194
+ specification_version: 4
195
+ summary: A CLI for starting git-flow features and hotfixes on PivotalTracker.
196
+ test_files: []