zenflow 0.8.5 → 0.8.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae2ed97af6262779e9958e11f9b2e6423e27c9e4
4
- data.tar.gz: 3f3b3631d60598dfcfd2496e9611b40d556b3c5a
3
+ metadata.gz: 08056c15bf04111493669ac5810d2bee09e1809b
4
+ data.tar.gz: de40476d5eb7b2bbed54f67f8b9e451ef3a48b07
5
5
  SHA512:
6
- metadata.gz: 841b104df941cb9238b1ed83882a8b19e2ad3fab8f6c56dc4499f5d2af4ae002567c20640b83f570838814d94a0ae43ff0bf274f5d6c32e32f1973aad6c05c5e
7
- data.tar.gz: f6636f589dcf351a561502173347e67155d5ba4412fa11c556fb695ce5a7070441fb7510e597df657af184a432a1cc56a7ac69c1c9be3ca147ffd69951165d1f
6
+ metadata.gz: 3c14ab625a909bb5afbaf2cb20a61a909ef081f3230e2dbc9fd49db22d02b3a56d702b6a84fe0c20e073a9b60fe9d93ffb87ccb5839e3fd23d30bc963bc2a8ec
7
+ data.tar.gz: c13bd23582fd6e0c5eee98eaddc4fd67efcc7749d40a036a5da6b36bf9864b6dd5d05322ffb7f6554a9cb231198f7bae7f107fb83c9a7a4acf05a77774d97c27
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zenflow (0.8.4)
4
+ zenflow (0.8.5)
5
5
  colored (~> 1.2)
6
6
  httparty (~> 0.12.0)
7
7
  terminal-table (~> 1.4.5)
@@ -3,8 +3,8 @@
3
3
  [![Gem Version](https://badge.fury.io/rb/zenflow.png)](http://badge.fury.io/rb/zenflow)
4
4
  [![Code Climate](https://codeclimate.com/repos/51bf6e3b7e00a411ad00f6c3/badges/111fbe3664cebffa8e23/gpa.png)](https://codeclimate.com/repos/51bf6e3b7e00a411ad00f6c3/feed)
5
5
  [![Coverage Status](https://coveralls.io/repos/zencoder/zenflow/badge.png)](https://coveralls.io/r/zencoder/zenflow)
6
- [![Dependency Status](https://gemnasium.com/a1d29c5ea446d54bead93a6878bc204b.png)](https://gemnasium.com/zencoder/zenflow)
7
- ![CircleCI](https://circleci.com/gh/zencoder/zenflow.png?circle-token=992f1e59d778a8f6eef0fb9f2888e80cf60d7226)
6
+ [![Dependency Status](https://gemnasium.com/zencoder/zenflow.png)](https://gemnasium.com/zencoder/zenflow)
7
+ ![CircleCI Tests](https://circleci.com/gh/zencoder/zenflow.png?circle-token=13273409fe8b7c62faddf26980040cf502b0348a)
8
8
 
9
9
  -------
10
10
 
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  major: 0
3
3
  minor: 8
4
- patch: 5
4
+ patch: 6
5
5
  pre:
@@ -26,9 +26,10 @@ require 'zenflow/helpers/branch_commands/review'
26
26
  require 'zenflow/helpers/branch_commands/start'
27
27
  require 'zenflow/helpers/branch_commands/update'
28
28
  require 'zenflow/helpers/branch_command'
29
+ require 'zenflow/commands/deploy'
29
30
  require 'zenflow/commands/feature'
30
31
  require 'zenflow/commands/hotfix'
32
+ require 'zenflow/commands/hubs'
31
33
  require 'zenflow/commands/release'
32
- require 'zenflow/commands/deploy'
33
34
  require 'zenflow/commands/reviews'
34
35
  require 'zenflow/cli'
@@ -20,6 +20,9 @@ module Zenflow
20
20
  super
21
21
  end
22
22
 
23
+ desc "hubs SUBCOMMAND", "Manage Github server configurations."
24
+ subcommand "hubs", Zenflow::Hubs
25
+
23
26
  desc "feature SUBCOMMAND", "Manage feature branches."
24
27
  subcommand "feature", Zenflow::Feature
25
28
 
@@ -29,10 +32,10 @@ module Zenflow
29
32
  desc "release SUBCOMMAND", "Manage release branches."
30
33
  subcommand "release", Zenflow::Release
31
34
 
32
- desc "reviews SUBCOMMAND", "Works with code reviews."
35
+ desc "reviews SUBCOMMAND", "Works with code reviews."
33
36
  subcommand "reviews", Zenflow::Reviews
34
37
 
35
- desc "deploy ENV", "Deploy to an environment."
38
+ desc "deploy ENV", "Deploy to an environment."
36
39
  subcommand "deploy", Zenflow::Deploy
37
40
 
38
41
  desc "init", "Write the zenflow config file."
@@ -40,8 +43,7 @@ module Zenflow
40
43
  if Zenflow::Config.configured? && !force
41
44
  already_configured
42
45
  else
43
- set_up_github
44
- authorize_github
46
+ configure_github
45
47
  configure_project
46
48
  configure_branches
47
49
  configure_merge_strategy
@@ -54,24 +56,24 @@ module Zenflow
54
56
 
55
57
  desc "set_up_github", "Set up GitHub user information"
56
58
  def set_up_github
57
- user = Zenflow::Github.user
59
+ user = Zenflow::Github.user(Zenflow::Github::DEFAULT_HUB)
58
60
  if user.to_s != ''
59
61
  if Zenflow::Ask("Your GitHub user is currently #{user}. Do you want to use that?", :options => ["Y", "n"], :default => "y") == "n"
60
- Zenflow::Github.set_user
62
+ Zenflow::Github.set_user(Zenflow::Github::DEFAULT_HUB)
61
63
  end
62
64
  else
63
- Zenflow::Github.set_user
65
+ Zenflow::Github.set_user(Zenflow::Github::DEFAULT_HUB)
64
66
  end
65
67
  end
66
68
 
67
69
  desc "authorize_github", "Get an auth token from GitHub"
68
70
  def authorize_github
69
- if Zenflow::Github.zenflow_token
71
+ if Zenflow::Github.zenflow_token(Zenflow::Github::DEFAULT_HUB)
70
72
  if Zenflow::Ask("You already have a token from GitHub. Do you want to set a new one?", :options => ["y", "N"], :default => "n") == "y"
71
- Zenflow::Github.authorize
73
+ Zenflow::Github.authorize(Zenflow::Github::DEFAULT_HUB)
72
74
  end
73
75
  else
74
- Zenflow::Github.authorize
76
+ Zenflow::Github.authorize(Zenflow::Github::DEFAULT_HUB)
75
77
  end
76
78
  end
77
79
 
@@ -87,6 +89,17 @@ module Zenflow
87
89
  end
88
90
  end
89
91
 
92
+ def configure_github
93
+ #TODO: consolidate these two paths
94
+ if Zenflow::Repo.is_default_hub?
95
+ set_up_github
96
+ authorize_github
97
+ else
98
+ Zenflow::Hubs.config
99
+ Zenflow::Hubs.authorize
100
+ end
101
+ end
102
+
90
103
  def configure_project
91
104
  Zenflow::Log("Project")
92
105
  Zenflow::Config[:project] = Zenflow::Ask("What is the name of this project?", :required => true)
@@ -0,0 +1,124 @@
1
+ module Zenflow
2
+ class Hubs < Thor
3
+
4
+ desc "list", "Show all configured hubs."
5
+ def list
6
+ Zenflow::Log("Recogized hubs")
7
+ Zenflow::Log(Terminal::Table.new(
8
+ headings: ['Hub'],
9
+ rows: get_list_of_hubs()
10
+ ).to_s, indent: false, arrows: false, color: false)
11
+ end
12
+
13
+ desc "current", "Show the current project's hub."
14
+ def current
15
+ Zenflow::Log("This project's hub is #{hub_label(Zenflow::Repo.hub)}")
16
+ end
17
+
18
+ desc "describe [HUB]", "Show configuration details for HUB (current project hub if none specified, or default hub if no current project)."
19
+ def describe(hub=nil)
20
+ hub = Zenflow::Github.resolve_hub(hub)
21
+
22
+ Zenflow::Log("Configuration details for hub #{hub_label(hub)}")
23
+
24
+ Zenflow::Log(Terminal::Table.new(
25
+ headings: ["Parameter", "Github Config Key", "Github Config Value", "Value (with system defaults)"],
26
+ rows: Zenflow::Github.describe_hub(hub)
27
+ ).to_s, indent: false, arrows: false, color: false)
28
+ end
29
+
30
+ desc "config [HUB]", "Configure the specified HUB (current project hub if none specified, or default hub if no current project)."
31
+ def config(hub=nil)
32
+ hub = Zenflow::Github.resolve_hub(hub)
33
+
34
+ Zenflow::Log("Configuring #{hub_label(hub)}")
35
+
36
+ config_api_base_url(hub)
37
+ config_user(hub)
38
+ config_user_agent_base(hub)
39
+ end
40
+
41
+ desc "authorize [HUB]", "Grab an auth token for HUB (current project hub if none specified, or default hub if no current project)."
42
+ def authorize(hub=nil)
43
+ hub = Zenflow::Github.resolve_hub(hub)
44
+
45
+ Zenflow::Log("Authorizing #{hub_label(hub)}")
46
+
47
+ if Zenflow::Github.zenflow_token(hub)
48
+ if Zenflow::Ask("You already have a token from GitHub. Do you want to set a new one?", :options => ["y", "N"], :default => "n") == "y"
49
+ Zenflow::Github.authorize(hub)
50
+ end
51
+ else
52
+ Zenflow::Github.authorize(hub)
53
+ end
54
+ end
55
+
56
+ no_commands {
57
+ def get_list_of_hubs
58
+ hub_config_parameters = Zenflow::Shell.run("git config --get-regexp zenflow\.hub\..*", silent: true).split("\n")
59
+
60
+ # unique, sorted, list of hubs with at least one valid config key
61
+ configured_hubs = hub_config_parameters.inject([]) { |hubs, parameter|
62
+ if parameter =~ /^zenflow\.hub\.(.*)\.#{config_keys_regex}\s.*$/
63
+ hubs << [hub_label($1)]
64
+ end
65
+
66
+ hubs
67
+ }.sort.uniq
68
+
69
+ [
70
+ ["#{hub_label(Zenflow::Github::DEFAULT_HUB)}"]
71
+ ] + configured_hubs
72
+ end
73
+
74
+ def hub_label(hub)
75
+ "#{hub}#{default_hub_tag(hub)}#{current_hub_tag(hub)}"
76
+ end
77
+
78
+ def default_hub_tag(hub)
79
+ Zenflow::Repo.is_default_hub?(hub) ? " [default]" : ""
80
+ end
81
+
82
+ def current_hub_tag(hub)
83
+ Zenflow::Repo.is_current_hub?(hub) ? " [current]" : ""
84
+ end
85
+
86
+ def config_keys_regex
87
+ "(?:#{Zenflow::Github::CONFIG_KEYS.map { |s| s.gsub('.','\\.') }.join('|')})"
88
+ end
89
+
90
+ def config_api_base_url(hub)
91
+ api_base_url = Zenflow::Github.api_base_url(hub,false)
92
+ if api_base_url.to_s != ''
93
+ if Zenflow::Ask("The GitHub API base URL for this hub is currently #{api_base_url}. Do you want to use that?", :options => ["Y", "n"], :default => "y") == "n"
94
+ Zenflow::Github.set_api_base_url(hub)
95
+ end
96
+ else
97
+ Zenflow::Github.set_api_base_url(hub)
98
+ end
99
+ end
100
+
101
+ def config_user(hub)
102
+ user = Zenflow::Github.user(hub)
103
+ if user.to_s != ''
104
+ if Zenflow::Ask("The GitHub user for this hub is currently #{user}. Do you want to use that?", :options => ["Y", "n"], :default => "y") == "n"
105
+ Zenflow::Github.set_user(hub)
106
+ end
107
+ else
108
+ Zenflow::Github.set_user(hub)
109
+ end
110
+ end
111
+
112
+ def config_user_agent_base(hub)
113
+ user_agent_base = Zenflow::Github.user_agent_base(hub,false)
114
+ if user_agent_base.to_s != ''
115
+ if Zenflow::Ask("The GitHub User Agent base for this hub is currently #{user_agent_base}. Do you want to use that?", :options => ["Y", "n"], :default => "y") == "n"
116
+ Zenflow::Github.set_user_agent_base(hub)
117
+ end
118
+ else
119
+ Zenflow::Github.set_user_agent_base(hub)
120
+ end
121
+ end
122
+ }
123
+ end
124
+ end
@@ -1,25 +1,52 @@
1
1
  module Zenflow
2
2
 
3
3
  module Github
4
- def self.user
5
- get_config('github.user')
4
+ DEFAULT_HUB = 'github.com'
5
+
6
+ DEFAULT_API_BASE_URL = 'https://api.github.com'
7
+ DEFAULT_USER_AGENT_BASE = 'Zencoder'
8
+
9
+ API_BASE_URL_KEY = 'api.base.url'
10
+ USER_KEY = 'github.user'
11
+ TOKEN_KEY = 'token'
12
+ USER_AGENT_BASE_KEY = 'user.agent.base'
13
+
14
+ CONFIG_KEYS = [
15
+ API_BASE_URL_KEY,
16
+ USER_KEY,
17
+ TOKEN_KEY,
18
+ USER_AGENT_BASE_KEY
19
+ ]
20
+
21
+ def self.api_base_url(hub=nil,useDefaultValue=true)
22
+ api_base_url = get_config_for_hub(hub, API_BASE_URL_KEY)
23
+ api_base_url ||= DEFAULT_API_BASE_URL if useDefaultValue
24
+ api_base_url
6
25
  end
7
26
 
8
- def self.zenflow_token
9
- get_config('zenflow.token')
27
+ def self.set_api_base_url(hub=nil)
28
+ api_base_url = Zenflow::Ask("What is the base URL of your Github API?", {:default => DEFAULT_API_BASE_URL})
29
+ set_config_for_hub(hub, API_BASE_URL_KEY, api_base_url)
10
30
  end
11
31
 
12
- def self.get_config(key)
13
- config = Zenflow::Shell.run("git config --get #{key.to_s}", silent: true)
14
- config = config.chomp unless config.nil?
15
- config
32
+ def self.user(hub=nil)
33
+ get_config_for_hub(hub, USER_KEY)
34
+ end
35
+
36
+ def self.set_user(hub=nil)
37
+ username = Zenflow::Ask("What is your Github username?")
38
+ set_config_for_hub(hub, USER_KEY, username)
39
+ end
40
+
41
+ def self.zenflow_token(hub=nil)
42
+ get_config_for_hub(hub, TOKEN_KEY)
16
43
  end
17
44
 
18
- def self.authorize
19
- Zenflow::Log("Authorizing with GitHub... Enter your GitHub password.")
20
- oauth_response = JSON.parse(Zenflow::Shell.run(%{curl -u "#{Zenflow::Github.user}" https://api.github.com/authorizations -d '{"scopes":["repo"], "note":"Zenflow"}' --silent}, silent: true))
45
+ def self.authorize(hub=nil)
46
+ Zenflow::Log("Authorizing with GitHub (#{user(hub)}@#{resolve_hub(hub)})... Enter your GitHub password.")
47
+ oauth_response = JSON.parse(Zenflow::Shell.run(%{curl -u "#{Zenflow::Github.user(hub)}" #{Zenflow::Github.api_base_url(hub)}/authorizations -d '{"scopes":["repo"], "note":"Zenflow"}' --silent}, silent: true))
21
48
  if oauth_response['token']
22
- Zenflow::Shell.run("git config --global zenflow.token #{oauth_response['token']}", silent: true)
49
+ set_config_for_hub(hub, TOKEN_KEY, oauth_response['token'])
23
50
  Zenflow::Log("Authorized!")
24
51
  else
25
52
  Zenflow::Log("Something went wrong. Error from GitHub was: #{oauth_response['message']}")
@@ -27,18 +54,69 @@ module Zenflow
27
54
  end
28
55
  end
29
56
 
30
- def self.set_user
31
- username = Zenflow::Ask("What is your Github username?")
32
- Zenflow::Shell.run("git config --global github.user #{username}", silent: true)
57
+ def self.user_agent_base(hub=nil,useDefaultValue=true)
58
+ user_agent_base = get_config_for_hub(hub, USER_AGENT_BASE_KEY)
59
+ user_agent_base ||= DEFAULT_USER_AGENT_BASE if useDefaultValue
60
+ user_agent_base
61
+ end
62
+
63
+ def self.set_user_agent_base(hub=nil)
64
+ user_agent_base = Zenflow::Ask("What base string would you like to use for the User Agent header, 'User-Agent: [user-agent-base]/Zenflow-#{VERSION}?", {:default => DEFAULT_USER_AGENT_BASE})
65
+ set_config_for_hub(hub, USER_AGENT_BASE_KEY, user_agent_base)
66
+ end
67
+
68
+ def self.resolve_hub(hub)
69
+ hub || Zenflow::Repo.hub || DEFAULT_HUB
70
+ end
71
+
72
+ # If this repo is not hosted on the default github, construct a key prefix containing the hub information
73
+ def self.construct_key_for_hub(hub, key)
74
+ default_hub_key_prefix = key == USER_KEY ? "" : "zenflow." # preserves backwards compatibility
75
+ Zenflow::Repo.is_default_hub?(hub) ? "#{default_hub_key_prefix}#{key}" : "zenflow.hub.#{hub}.#{key}"
76
+ end
77
+
78
+ def self.get_config_for_hub(hub, key)
79
+ resolved_hub = resolve_hub(hub)
80
+ key_for_hub = construct_key_for_hub(resolved_hub, key)
81
+ get_global_config(key_for_hub)
82
+ end
83
+
84
+ def self.set_config_for_hub(hub, key, value)
85
+ resolved_hub = resolve_hub(hub)
86
+ key_for_hub = construct_key_for_hub(resolved_hub, key)
87
+ set_global_config(key_for_hub, value)
88
+ end
89
+
90
+ def self.get_global_config(key)
91
+ config = Zenflow::Shell.run("git config --get #{key.to_s}", silent: true)
92
+ config = config.chomp unless config.nil?
93
+ config.to_s == '' ? nil : config
94
+ end
95
+
96
+ def self.set_global_config(key, value)
97
+ Zenflow::Shell.run("git config --global #{key} #{value}", silent: true)
98
+ end
99
+
100
+ def self.describe_hub_parameter(name, hub, key, value)
101
+ [name, construct_key_for_hub(hub, key), get_config_for_hub(hub, key), value]
102
+ end
103
+
104
+ def self.describe_hub(hub)
105
+ [
106
+ describe_hub_parameter("API Base URL", hub, API_BASE_URL_KEY, api_base_url(hub)),
107
+ describe_hub_parameter("User", hub, USER_KEY, user(hub)),
108
+ describe_hub_parameter("Token", hub, TOKEN_KEY, zenflow_token(hub)),
109
+ describe_hub_parameter("User Agent Base", hub, USER_AGENT_BASE_KEY, user_agent_base(hub))
110
+ ]
33
111
  end
34
112
  end
35
113
 
36
114
  class GithubRequest
37
115
  include HTTParty
38
- base_uri "https://api.github.com/repos/#{Zenflow::Repo.slug}"
116
+ base_uri "#{Zenflow::Github.api_base_url}/repos/#{Zenflow::Repo.slug}"
39
117
  format :json
40
118
  headers "Authorization" => "token #{Zenflow::Github.zenflow_token}"
41
- headers "User-Agent" => "Zencoder/Zenflow-#{VERSION}"
119
+ headers "User-Agent" => "#{Zenflow::Github.user_agent_base}/Zenflow-#{VERSION}"
42
120
  end
43
121
 
44
122
  end
@@ -5,9 +5,21 @@ module Zenflow
5
5
  `git remote -v`[/^#{Zenflow::Config[:remote] || 'origin'}\s+(.*?)\s/, 1]
6
6
  end
7
7
 
8
+ def self.hub
9
+ (url && url[/\w+@(.*?):.*?\.git/, 1]) || nil
10
+ end
11
+
8
12
  def self.slug
9
13
  (url && url[/:(.*?)\.git/, 1]) || nil
10
14
  end
11
15
 
16
+ def self.is_current_hub?(check)
17
+ hub == check
18
+ end
19
+
20
+ def self.is_default_hub?(check=nil)
21
+ (check ? check : hub) == Zenflow::Github::DEFAULT_HUB
22
+ end
23
+
12
24
  end
13
25
  end
@@ -0,0 +1,372 @@
1
+ require 'spec_helper'
2
+
3
+ describe Zenflow::Hubs do
4
+ let(:hubs) { Zenflow::Hubs.new }
5
+
6
+ describe '.list' do
7
+ it 'lists recognized hubs in git config' do
8
+ Zenflow::Shell.should_receive(:run).with("git config --get-regexp zenflow\.hub\..*", silent: true).and_return(
9
+ <<EOS
10
+ zenflow.hub.hub.1.api.base.url api_base_url
11
+ zenflow.hub.yet.another.hub.github.user github_user
12
+ zenflow.hub.hub.1.token token
13
+ zenflow.hub.my-hub.token token
14
+ zenflow.hub.one.more.hub.user.agent.base user_agent_base
15
+ zenflow.hub.bad.token.hub.goobers user_agent_base
16
+ EOS
17
+ )
18
+ Zenflow::Repo.should_receive(:is_default_hub?).at_least(:once).with(anything()).and_return(false)
19
+ Zenflow::Repo.should_receive(:is_current_hub?).at_least(:once).with(anything()).and_return(false)
20
+ Zenflow.should_receive(:Log).with("Recogized hubs")
21
+ Terminal::Table.should_receive(:new).with(
22
+ headings: ["Hub"],
23
+ rows: [
24
+ ["github.com"],
25
+ ["hub.1"],
26
+ ["my-hub"],
27
+ ["one.more.hub"],
28
+ ["yet.another.hub"]
29
+ ]
30
+ ).and_return("log-data")
31
+ Zenflow.should_receive(:Log).with("log-data", indent: false, arrows: false, color: false)
32
+ hubs.list
33
+ end
34
+ end
35
+
36
+ describe '.current' do
37
+ it 'logs the hubs of the current project' do
38
+ Zenflow::Repo.should_receive(:hub).twice.and_return('my-hub')
39
+ Zenflow.should_receive(:Log).with("This project's hub is my-hub [current]")
40
+ hubs.current
41
+ end
42
+ end
43
+
44
+ describe '.describe' do
45
+ it 'displays config parameters for the hub' do
46
+ hubs.should_receive(:hub_label).with('my-hub').and_return('my-hub')
47
+ Zenflow.should_receive(:Log).with("Configuration details for hub my-hub")
48
+ Zenflow::Github.should_receive(:describe_hub).with('my-hub').and_return([
49
+ ["Parameter 1", "Github Config Key 1", "Github Conifg Value 1", "Value 1"],
50
+ ["Parameter 2", "Github Config Key 2", "Github Conifg Value 2", "Value 2"],
51
+ ["Parameter 3", "Github Config Key 3", "Github Conifg Value 3", "Value 3"]
52
+ ])
53
+ Terminal::Table.should_receive(:new).with(
54
+ headings: ["Parameter", "Github Config Key", "Github Config Value", "Value (with system defaults)"],
55
+ rows: [
56
+ ["Parameter 1", "Github Config Key 1", "Github Conifg Value 1", "Value 1"],
57
+ ["Parameter 2", "Github Config Key 2", "Github Conifg Value 2", "Value 2"],
58
+ ["Parameter 3", "Github Config Key 3", "Github Conifg Value 3", "Value 3"]
59
+ ]
60
+ ).and_return("log-data")
61
+ Zenflow.should_receive(:Log).with("log-data", {:indent=>false, :arrows=>false, :color=>false})
62
+ hubs.describe('my-hub')
63
+ end
64
+ end
65
+
66
+ describe '.config' do
67
+ it 'calls the individual parameter config methods' do
68
+ Zenflow::Github.should_receive(:resolve_hub).with('my-hub').and_return('my-hub')
69
+ hubs.should_receive(:hub_label).with('my-hub').and_return('my-hub')
70
+ Zenflow.should_receive(:Log).with("Configuring my-hub")
71
+ hubs.should_receive(:config_api_base_url).with('my-hub')
72
+ hubs.should_receive(:config_user).with('my-hub')
73
+ hubs.should_receive(:config_user_agent_base).with('my-hub')
74
+ hubs.config('my-hub')
75
+ end
76
+ end
77
+
78
+ describe '.config_user' do
79
+ context 'when a github user is already saved' do
80
+ before do
81
+ Zenflow::Github.should_receive(:user).and_return('user')
82
+ end
83
+
84
+ context 'and the user decides to set a new one' do
85
+ before do
86
+ Zenflow.should_receive(:Ask).and_return('n')
87
+ end
88
+
89
+ it 'asks for a user' do
90
+ Zenflow::Github.should_receive(:set_user)
91
+ hubs.config_user('my-hub')
92
+ end
93
+ end
94
+
95
+ context 'and the user decides not to set a new one' do
96
+ before do
97
+ Zenflow.should_receive(:Ask).and_return('y')
98
+ end
99
+
100
+ it 'does not ask for a user' do
101
+ Zenflow::Github.should_not_receive(:set_user)
102
+ hubs.config_user('my-hub')
103
+ end
104
+ end
105
+ end
106
+
107
+ context 'when a user is not already saved' do
108
+ before do
109
+ Zenflow::Github.should_receive(:user).and_return(nil)
110
+ end
111
+
112
+ it 'asks for a user' do
113
+ Zenflow::Github.should_receive(:set_user)
114
+ hubs.config_user('my-hub')
115
+ end
116
+ end
117
+ end
118
+
119
+ describe '.authorize' do
120
+ before do
121
+ Zenflow::Github.should_receive(:resolve_hub).with('my-hub').and_return('my-hub')
122
+ hubs.should_receive(:hub_label).with('my-hub').and_return('my-hub')
123
+ Zenflow.should_receive(:Log).with("Authorizing my-hub")
124
+ end
125
+
126
+ context 'when a zenflow_token is already saved' do
127
+ before do
128
+ Zenflow::Github.should_receive(:zenflow_token).and_return('super secret token')
129
+ end
130
+
131
+ context 'and the user decides to set a new one' do
132
+ before do
133
+ Zenflow.should_receive(:Ask).and_return('y')
134
+ end
135
+
136
+ it 'authorizes with Github' do
137
+ Zenflow::Github.should_receive(:authorize).with('my-hub')
138
+ hubs.authorize('my-hub')
139
+ end
140
+ end
141
+
142
+ context 'and the user decides not to set a new one' do
143
+ before do
144
+ Zenflow.should_receive(:Ask).and_return('n')
145
+ end
146
+
147
+ it 'does not authorize with Github' do
148
+ Zenflow::Github.should_not_receive(:authorize)
149
+ hubs.authorize('my-hub')
150
+ end
151
+ end
152
+ end
153
+
154
+ context 'when a zenflow_token is not already saved' do
155
+ before do
156
+ Zenflow::Github.should_receive(:zenflow_token).and_return(nil)
157
+ end
158
+
159
+ it 'authorizes with Github' do
160
+ Zenflow::Github.should_receive(:authorize).with('my-hub')
161
+ hubs.authorize('my-hub')
162
+ end
163
+ end
164
+ end
165
+
166
+ describe '.hub_label' do
167
+ context 'hub is default hub' do
168
+ context 'hub is current hub' do
169
+ before(:each){
170
+ Zenflow::Repo.should_receive(:hub).and_return(Zenflow::Github::DEFAULT_HUB)
171
+ }
172
+
173
+ it 'returns the expected label' do
174
+ expect(hubs.hub_label(Zenflow::Github::DEFAULT_HUB)).to eq("#{Zenflow::Github::DEFAULT_HUB} [default] [current]")
175
+ end
176
+ end
177
+
178
+ context 'hub is not current hub' do
179
+ before(:each){
180
+ Zenflow::Repo.should_receive(:hub).and_return('current-hub')
181
+ }
182
+
183
+ it 'returns the expected label' do
184
+ expect(hubs.hub_label(Zenflow::Github::DEFAULT_HUB)).to eq("#{Zenflow::Github::DEFAULT_HUB} [default]")
185
+ end
186
+ end
187
+ end
188
+
189
+ context 'hub is not default hub' do
190
+ context 'hub is current hub' do
191
+ before(:each){
192
+ Zenflow::Repo.should_receive(:hub).and_return('current-hub')
193
+ }
194
+
195
+ it 'returns the expected label' do
196
+ expect(hubs.hub_label('current-hub')).to eq('current-hub [current]')
197
+ end
198
+ end
199
+
200
+ context 'hub is not current hub' do
201
+ before(:each){
202
+ Zenflow::Repo.should_receive(:hub).and_return('default-hub')
203
+ }
204
+
205
+ it 'returns the expected label' do
206
+ expect(hubs.hub_label('not-current-hub')).to eq('not-current-hub')
207
+ end
208
+ end
209
+ end
210
+ end
211
+
212
+ describe '.default_hub_tag' do
213
+ context 'hub is default hub' do
214
+ it 'returns the expected tag' do
215
+ expect(hubs.default_hub_tag(Zenflow::Github::DEFAULT_HUB)).to eq(' [default]')
216
+ end
217
+ end
218
+
219
+ context 'hub is not default hub' do
220
+ it 'returns the expected tag' do
221
+ expect(hubs.default_hub_tag('not-default-hub')).to eq('')
222
+ end
223
+ end
224
+ end
225
+
226
+ describe '.current_hub_tag' do
227
+ before(:each){
228
+ Zenflow::Repo.should_receive(:hub).and_return('current-hub')
229
+ }
230
+
231
+ context 'hub is current hub' do
232
+ it 'returns the expected tag' do
233
+ expect(hubs.current_hub_tag('current-hub')).to eq(' [current]')
234
+ end
235
+ end
236
+
237
+ context 'hub is not current hub' do
238
+ it 'returns the expected tag' do
239
+ expect(hubs.current_hub_tag('not-current-hub')).to eq('')
240
+ end
241
+ end
242
+ end
243
+
244
+ describe '.config_key_regex' do
245
+ it 'returns the expected regex' do
246
+ expect(hubs.config_keys_regex).to eq('(?:api\\.base\\.url|github\\.user|token|user\\.agent\\.base)')
247
+ end
248
+ end
249
+
250
+ describe '.config_api_base_url' do
251
+ context 'when a github api base url is already saved' do
252
+ before do
253
+ Zenflow::Github.should_receive(:api_base_url).and_return('api-base-url')
254
+ end
255
+
256
+ context 'and the user decides to set a new one' do
257
+ before do
258
+ Zenflow.should_receive(:Ask).and_return('n')
259
+ end
260
+
261
+ it 'asks for an api base url' do
262
+ Zenflow::Github.should_receive(:set_api_base_url)
263
+ hubs.config_api_base_url('my-hub')
264
+ end
265
+ end
266
+
267
+ context 'and the user decides not to set a new one' do
268
+ before do
269
+ Zenflow.should_receive(:Ask).and_return('y')
270
+ end
271
+
272
+ it 'does not ask for an api base url' do
273
+ Zenflow::Github.should_not_receive(:set_api_base_url)
274
+ hubs.config_api_base_url('my-hub')
275
+ end
276
+ end
277
+ end
278
+
279
+ context 'when an api base url is not already saved' do
280
+ before do
281
+ Zenflow::Github.should_receive(:api_base_url).and_return(nil)
282
+ end
283
+
284
+ it 'asks for an api base url' do
285
+ Zenflow::Github.should_receive(:set_api_base_url)
286
+ hubs.config_api_base_url('my-hub')
287
+ end
288
+ end
289
+ end
290
+
291
+ describe '.config_user' do
292
+ context 'when a github user is already saved' do
293
+ before do
294
+ Zenflow::Github.should_receive(:user).and_return('user')
295
+ end
296
+
297
+ context 'and the user decides to set a new one' do
298
+ before do
299
+ Zenflow.should_receive(:Ask).and_return('n')
300
+ end
301
+
302
+ it 'asks for a user' do
303
+ Zenflow::Github.should_receive(:set_user)
304
+ hubs.config_user('my-hub')
305
+ end
306
+ end
307
+
308
+ context 'and the user decides not to set a new one' do
309
+ before do
310
+ Zenflow.should_receive(:Ask).and_return('y')
311
+ end
312
+
313
+ it 'does not ask for a user' do
314
+ Zenflow::Github.should_not_receive(:set_user)
315
+ hubs.config_user('my-hub')
316
+ end
317
+ end
318
+ end
319
+
320
+ context 'when a user is not already saved' do
321
+ before do
322
+ Zenflow::Github.should_receive(:user).and_return(nil)
323
+ end
324
+
325
+ it 'asks for a user' do
326
+ Zenflow::Github.should_receive(:set_user)
327
+ hubs.config_user('my-hub')
328
+ end
329
+ end
330
+ end
331
+
332
+ describe '.config_user_agent_base' do
333
+ context 'when a github user agent base is already saved' do
334
+ before do
335
+ Zenflow::Github.should_receive(:user_agent_base).and_return('user-agent-base')
336
+ end
337
+
338
+ context 'and the user decides to set a new one' do
339
+ before do
340
+ Zenflow.should_receive(:Ask).and_return('n')
341
+ end
342
+
343
+ it 'asks for a user agent base' do
344
+ Zenflow::Github.should_receive(:set_user_agent_base)
345
+ hubs.config_user_agent_base('my-hub')
346
+ end
347
+ end
348
+
349
+ context 'and the user decides not to set a new one' do
350
+ before do
351
+ Zenflow.should_receive(:Ask).and_return('y')
352
+ end
353
+
354
+ it 'does not ask for a user agent base' do
355
+ Zenflow::Github.should_not_receive(:set_user_agent_base)
356
+ hubs.config_user_agent_base('my-hub')
357
+ end
358
+ end
359
+ end
360
+
361
+ context 'when a user agent base is not already saved' do
362
+ before do
363
+ Zenflow::Github.should_receive(:user_agent_base).and_return(nil)
364
+ end
365
+
366
+ it 'asks for a user agent base' do
367
+ Zenflow::Github.should_receive(:set_user_agent_base)
368
+ hubs.config_user_agent_base('my-hub')
369
+ end
370
+ end
371
+ end
372
+ end
@@ -272,9 +272,33 @@ describe Zenflow::CLI do
272
272
  end
273
273
 
274
274
  describe "#init" do
275
+ context "when in a project that doesn't belong to the default hub" do
276
+ context "when zenflow has not been configured" do
277
+ before do
278
+ Zenflow::Config.should_receive(:configured?).and_return(false)
279
+ Zenflow::Repo.should_receive(:is_default_hub?).and_return(false)
280
+ end
281
+
282
+ it 'configures zenflow' do
283
+ subject.should_not_receive(:already_configured)
284
+ Zenflow::Hubs.should_receive(:config)
285
+ Zenflow::Hubs.should_receive(:authorize)
286
+ subject.should_receive(:configure_project)
287
+ subject.should_receive(:configure_branches)
288
+ subject.should_receive(:configure_merge_strategy)
289
+ subject.should_receive(:configure_remotes)
290
+ subject.should_receive(:confirm_some_stuff)
291
+ subject.should_receive(:set_up_changelog)
292
+ Zenflow::Config.should_receive(:save!)
293
+ subject.init
294
+ end
295
+ end
296
+ end
297
+
275
298
  context "when zenflow has not been configured" do
276
299
  before do
277
300
  Zenflow::Config.should_receive(:configured?).and_return(false)
301
+ Zenflow::Repo.should_receive(:is_default_hub?).and_return(true)
278
302
  end
279
303
 
280
304
  it 'configures zenflow' do
@@ -298,6 +322,10 @@ describe Zenflow::CLI do
298
322
  end
299
323
 
300
324
  context 'and it is forced to initialize' do
325
+ before do
326
+ Zenflow::Repo.should_receive(:is_default_hub?).and_return(true)
327
+ end
328
+
301
329
  it 'configures zenflow' do
302
330
  subject.should_not_receive(:already_configured)
303
331
  subject.should_receive(:set_up_github)
@@ -1,15 +1,63 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Zenflow::Github do
4
+ describe '.api_base_url' do
5
+ context 'when the value is present' do
6
+ before(:each){
7
+ Zenflow::Github.should_receive(:get_config_for_hub).with('test-hub', 'api.base.url').and_return("api-base-url")
8
+ }
9
+
10
+ context 'and default is true' do
11
+ it 'returns the expected value' do
12
+ expect(Zenflow::Github.api_base_url('test-hub', true)).to eq("api-base-url")
13
+ end
14
+ end
15
+
16
+ context 'and default is false' do
17
+ it 'returns the expected value' do
18
+ expect(Zenflow::Github.api_base_url('test-hub', false)).to eq("api-base-url")
19
+ end
20
+ end
21
+ end
22
+
23
+ context 'when the value is absent' do
24
+ before(:each){
25
+ Zenflow::Github.should_receive(:get_config_for_hub).with('test-hub', 'api.base.url').and_return(nil)
26
+ }
27
+
28
+ context 'and default is true' do
29
+ it 'returns the expected value' do
30
+ expect(Zenflow::Github.api_base_url('test-hub', true)).to eq("https://api.github.com")
31
+ end
32
+ end
33
+
34
+ context 'and default is false' do
35
+ it 'returns the expected value' do
36
+ expect(Zenflow::Github.api_base_url('test-hub', false)).to eq(nil)
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ describe '.set_api_base_url' do
43
+ let(:api_base_url){'api-base-url'}
44
+
45
+ it 'asks for the API base URL and sets it to zenflow.api.base.url' do
46
+ Zenflow.should_receive(:Ask).and_return(api_base_url)
47
+ Zenflow::Github.should_receive(:set_config_for_hub).with(nil, 'api.base.url', api_base_url)
48
+ Zenflow::Github.set_api_base_url
49
+ end
50
+ end
51
+
4
52
  describe '.user' do
5
53
  let(:user){'github-user'}
6
54
 
7
55
  before(:each){
8
- Zenflow::Shell.should_receive(:run).and_return(user)
56
+ Zenflow::Github.should_receive(:get_config_for_hub).with('test-hub', 'github.user').and_return(user)
9
57
  }
10
58
 
11
59
  it "returns the user" do
12
- expect(Zenflow::Github.user).to eq(user)
60
+ expect(Zenflow::Github.user('test-hub')).to eq(user)
13
61
  end
14
62
  end
15
63
 
@@ -18,7 +66,7 @@ describe Zenflow::Github do
18
66
 
19
67
  it 'asks for the user name and sets it to github.user' do
20
68
  Zenflow.should_receive(:Ask).and_return(user)
21
- Zenflow::Shell.should_receive(:run).with(/github\.user #{user}/, silent: true)
69
+ Zenflow::Github.should_receive(:set_config_for_hub).with(nil, 'github.user', user)
22
70
  Zenflow::Github.set_user
23
71
  end
24
72
  end
@@ -26,9 +74,10 @@ describe Zenflow::Github do
26
74
  describe '.authorize' do
27
75
  context "when authorization fails" do
28
76
  before do
29
- Zenflow.should_receive("Log").with("Authorizing with GitHub... Enter your GitHub password.")
30
- Zenflow::Github.should_receive(:user).and_return('adamkittelson')
31
- Zenflow::Shell.should_receive(:run).and_return('{"message": "failed to authorize, bummer"}')
77
+ Zenflow.should_receive("Log").with("Authorizing with GitHub (adamkittelson@github.com)... Enter your GitHub password.")
78
+ Zenflow::Github.should_receive(:user).twice.and_return('adamkittelson')
79
+ Zenflow::Github.should_receive(:api_base_url).and_return('https://api.base.url')
80
+ Zenflow::Shell.should_receive(:run).with(%{curl -u "adamkittelson" https://api.base.url/authorizations -d '{"scopes":["repo"], "note":"Zenflow"}' --silent}, :silent => true).and_return('{"message": "failed to authorize, bummer"}')
32
81
  end
33
82
 
34
83
  it "logs that something went wrong" do
@@ -39,17 +88,266 @@ describe Zenflow::Github do
39
88
 
40
89
  context "when authorization succeeds" do
41
90
  before do
42
- Zenflow.should_receive("Log").with("Authorizing with GitHub... Enter your GitHub password.")
43
- Zenflow::Github.should_receive(:user).and_return('adamkittelson')
44
- Zenflow::Shell.should_receive(:run).with(%{curl -u "adamkittelson" https://api.github.com/authorizations -d '{"scopes":["repo"], "note":"Zenflow"}' --silent}, :silent => true).and_return('{"token": "super secure token"}')
91
+ Zenflow.should_receive("Log").with("Authorizing with GitHub (adamkittelson@github.com)... Enter your GitHub password.")
92
+ Zenflow::Github.should_receive(:user).twice.and_return('adamkittelson')
93
+ Zenflow::Github.should_receive(:api_base_url).and_return('https://api.base.url')
94
+ Zenflow::Shell.should_receive(:run).with(%{curl -u "adamkittelson" https://api.base.url/authorizations -d '{"scopes":["repo"], "note":"Zenflow"}' --silent}, :silent => true).and_return('{"token": "super secure token"}')
45
95
  end
46
96
 
47
97
  it "adds the token to git config and logs a happy message of success" do
48
- Zenflow::Shell.should_receive(:run).with("git config --global zenflow.token super secure token", :silent => true)
98
+ Zenflow::Github.should_receive(:set_config_for_hub).with(nil, 'token', "super secure token")
49
99
  Zenflow.should_receive("Log").with("Authorized!")
50
100
  Zenflow::Github.authorize
51
101
  end
52
102
  end
53
103
 
54
104
  end
105
+
106
+ describe '.user_agent_base' do
107
+ context 'when the value is present' do
108
+ before(:each){
109
+ Zenflow::Github.should_receive(:get_config_for_hub).with('test-hub', 'user.agent.base').and_return("user-agent-base")
110
+ }
111
+
112
+ context 'and default is true' do
113
+ it 'returns the expected value' do
114
+ expect(Zenflow::Github.user_agent_base('test-hub', true)).to eq("user-agent-base")
115
+ end
116
+ end
117
+
118
+ context 'and default is false' do
119
+ it 'returns the expected value' do
120
+ expect(Zenflow::Github.user_agent_base('test-hub', false)).to eq("user-agent-base")
121
+ end
122
+ end
123
+ end
124
+
125
+ context 'when the value is absent' do
126
+ before(:each){
127
+ Zenflow::Github.should_receive(:get_config_for_hub).with('test-hub', 'user.agent.base').and_return(nil)
128
+ }
129
+
130
+ context 'and default is true' do
131
+ it 'returns the expected value' do
132
+ expect(Zenflow::Github.user_agent_base('test-hub', true)).to eq("Zencoder")
133
+ end
134
+ end
135
+
136
+ context 'and default is false' do
137
+ it 'returns the expected value' do
138
+ expect(Zenflow::Github.user_agent_base('test-hub', false)).to eq(nil)
139
+ end
140
+ end
141
+ end
142
+ end
143
+
144
+ describe '.set_user_agent_base' do
145
+ let(:user_agent_base){'user-agent-base'}
146
+
147
+ it 'asks for the User-Agent base string and sets it to zenflow.user.agent.base' do
148
+ Zenflow.should_receive(:Ask).and_return(user_agent_base)
149
+ Zenflow::Github.should_receive(:set_config_for_hub).with(nil, 'user.agent.base', user_agent_base)
150
+ Zenflow::Github.set_user_agent_base
151
+ end
152
+ end
153
+
154
+ describe '.resolve_hub' do
155
+ context 'when supplied as argument' do
156
+ it 'returns the hub provided' do
157
+ expect(Zenflow::Github.resolve_hub('test-hub')).to eq 'test-hub'
158
+ end
159
+ end
160
+
161
+ context 'when argument is nil' do
162
+ context 'and there is a repo hub' do
163
+ before(:each){
164
+ Zenflow::Repo.should_receive(:hub).and_return('repo-hub')
165
+ }
166
+
167
+ it 'returns the repo hub' do
168
+ expect(Zenflow::Github.resolve_hub(nil)).to eq 'repo-hub'
169
+ end
170
+ end
171
+
172
+ context 'and the repo hub is nil' do
173
+ before(:each){
174
+ Zenflow::Repo.should_receive(:hub).and_return(nil)
175
+ }
176
+
177
+ it 'returns the default hub' do
178
+ expect(Zenflow::Github.resolve_hub(nil)).to eq Zenflow::Github::DEFAULT_HUB
179
+ end
180
+ end
181
+ end
182
+ end
183
+
184
+ describe '.construct_key_for_hub' do
185
+ context 'when hub is the default hub' do
186
+ context 'and key is the api url base key' do
187
+ it 'prepends \'zenflow\' as a prefix' do
188
+ expect(Zenflow::Github.construct_key_for_hub('github.com', 'api.base.url')).to eq("zenflow.api.base.url")
189
+ end
190
+ end
191
+
192
+ context 'and key is the user key' do
193
+ it 'does not prepend a prefix' do
194
+ expect(Zenflow::Github.construct_key_for_hub('github.com', 'github.user')).to eq('github.user')
195
+ end
196
+ end
197
+
198
+ context 'and key is the zenflow token key' do
199
+ it 'prepends \'zenflow\' as a prefix' do
200
+ expect(Zenflow::Github.construct_key_for_hub('github.com', 'token')).to eq("zenflow.token")
201
+ end
202
+ end
203
+
204
+ context 'and key is the user agent base key' do
205
+ it 'prepends \'zenflow\' as a prefix' do
206
+ expect(Zenflow::Github.construct_key_for_hub('github.com', 'user.agent.base')).to eq("zenflow.user.agent.base")
207
+ end
208
+ end
209
+ end
210
+
211
+ context 'hub is not the default hub' do
212
+ context 'and key is the api url base key' do
213
+ it 'prepends a hub-specific prefix' do
214
+ expect(Zenflow::Github.construct_key_for_hub('my-hub', 'api.base.url')).to eq("zenflow.hub.my-hub.api.base.url")
215
+ end
216
+ end
217
+
218
+ context 'and key is the user key' do
219
+ it 'prepends a hub-specific prefix' do
220
+ expect(Zenflow::Github.construct_key_for_hub('my-hub', 'github.user')).to eq("zenflow.hub.my-hub.github.user")
221
+ end
222
+ end
223
+
224
+ context 'and key is the zenflow token key' do
225
+ it 'prepends a hub-specific prefix' do
226
+ expect(Zenflow::Github.construct_key_for_hub('my-hub', 'token')).to eq("zenflow.hub.my-hub.token")
227
+ end
228
+ end
229
+
230
+ context 'and key is the user agent base key' do
231
+ it 'prepends a hub-specific prefix' do
232
+ expect(Zenflow::Github.construct_key_for_hub('my-hub', 'user.agent.base')).to eq("zenflow.hub.my-hub.user.agent.base")
233
+ end
234
+ end
235
+ end
236
+ end
237
+
238
+ describe '.get_config_for_hub' do
239
+ it 'gets the correct global config parameter' do
240
+ Zenflow::Github.should_receive(:get_global_config).with("zenflow.hub.test-hub.test-key")
241
+ Zenflow::Github.get_config_for_hub('test-hub', 'test-key')
242
+ end
243
+ end
244
+
245
+ describe '.set_config_for_hub' do
246
+ it 'sets the correct global config parameter' do
247
+ Zenflow::Github.should_receive(:set_global_config).with("zenflow.hub.test-hub.test-key", "test-value")
248
+ Zenflow::Github.set_config_for_hub('test-hub', 'test-key', 'test-value')
249
+ end
250
+ end
251
+
252
+ describe '.get_global_config' do
253
+ context 'when value is present' do
254
+ before(:each){
255
+ Zenflow::Shell.should_receive(:run).with('git config --get key', silent: true).and_return('value')
256
+ }
257
+
258
+ it 'returns the value' do
259
+ expect(Zenflow::Github.get_global_config('key')).to eq('value')
260
+ end
261
+ end
262
+
263
+ context 'when value is missing' do
264
+ before(:each){
265
+ Zenflow::Shell.should_receive(:run).with('git config --get key', silent: true).and_return('')
266
+ }
267
+
268
+ it 'returns nil' do
269
+ expect(Zenflow::Github.get_global_config('key')).to eq(nil)
270
+ end
271
+ end
272
+ end
273
+
274
+ describe '.set_global_config' do
275
+ before(:each){
276
+ Zenflow::Shell.should_receive(:run).with('git config --global key value', silent: true)
277
+ }
278
+
279
+ it 'sets the value' do
280
+ Zenflow::Github.set_global_config('key', 'value')
281
+ end
282
+ end
283
+
284
+ describe '.config_keys' do
285
+ it 'returns the expected array of keys' do
286
+ expect(Zenflow::Github::CONFIG_KEYS).to eq([
287
+ 'api.base.url',
288
+ 'github.user',
289
+ 'token',
290
+ 'user.agent.base'
291
+ ])
292
+ end
293
+ end
294
+
295
+ describe '.describe_hub_parameter' do
296
+ it 'returns the expected array' do
297
+ Zenflow::Github.should_receive(:get_config_for_hub).with('my-hub', 'key').and_return('config-value')
298
+ expect(Zenflow::Github.describe_hub_parameter('name', 'my-hub', 'key', 'value')).to eq(
299
+ ['name', 'zenflow.hub.my-hub.key', 'config-value', 'value']
300
+ )
301
+ end
302
+ end
303
+
304
+ describe '.describe_hub' do
305
+ context 'all parameters configured' do
306
+ it 'returns the expected data' do
307
+ Zenflow::Github.should_receive(:get_config_for_hub).twice.with('my-hub', 'api.base.url').and_return('api-base-url-config-value')
308
+ Zenflow::Github.should_receive(:get_config_for_hub).twice.with('my-hub', 'github.user').and_return('github-user-config-value')
309
+ Zenflow::Github.should_receive(:get_config_for_hub).twice.with('my-hub', 'token').and_return('token-config-value')
310
+ Zenflow::Github.should_receive(:get_config_for_hub).twice.with('my-hub', 'user.agent.base').and_return('user-agent-base-config-value')
311
+
312
+ expect(Zenflow::Github.describe_hub('my-hub')).to eq([
313
+ ['API Base URL', 'zenflow.hub.my-hub.api.base.url', 'api-base-url-config-value', 'api-base-url-config-value'],
314
+ ['User', 'zenflow.hub.my-hub.github.user', 'github-user-config-value', 'github-user-config-value'],
315
+ ['Token', 'zenflow.hub.my-hub.token', 'token-config-value', 'token-config-value'],
316
+ ['User Agent Base', 'zenflow.hub.my-hub.user.agent.base', 'user-agent-base-config-value', 'user-agent-base-config-value']
317
+ ])
318
+ end
319
+ end
320
+
321
+ context 'no parameters configured' do
322
+ it 'returns the expected data' do
323
+ Zenflow::Github.should_receive(:get_config_for_hub).twice.with('my-hub', 'api.base.url').and_return(nil)
324
+ Zenflow::Github.should_receive(:get_config_for_hub).twice.with('my-hub', 'github.user').and_return(nil)
325
+ Zenflow::Github.should_receive(:get_config_for_hub).twice.with('my-hub', 'token').and_return(nil)
326
+ Zenflow::Github.should_receive(:get_config_for_hub).twice.with('my-hub', 'user.agent.base').and_return(nil)
327
+
328
+ expect(Zenflow::Github.describe_hub('my-hub')).to eq([
329
+ ['API Base URL', 'zenflow.hub.my-hub.api.base.url', nil, 'https://api.github.com'],
330
+ ['User', 'zenflow.hub.my-hub.github.user', nil, nil],
331
+ ['Token', 'zenflow.hub.my-hub.token', nil, nil],
332
+ ['User Agent Base', 'zenflow.hub.my-hub.user.agent.base', nil, 'Zencoder']
333
+ ])
334
+ end
335
+ end
336
+
337
+ context 'hub is default' do
338
+ it 'returns the expected data' do
339
+ Zenflow::Github.should_receive(:get_config_for_hub).twice.with('github.com', 'api.base.url').and_return(nil)
340
+ Zenflow::Github.should_receive(:get_config_for_hub).twice.with('github.com', 'github.user').and_return(nil)
341
+ Zenflow::Github.should_receive(:get_config_for_hub).twice.with('github.com', 'token').and_return(nil)
342
+ Zenflow::Github.should_receive(:get_config_for_hub).twice.with('github.com', 'user.agent.base').and_return(nil)
343
+
344
+ expect(Zenflow::Github.describe_hub('github.com')).to eq([
345
+ ['API Base URL', 'zenflow.api.base.url', nil, 'https://api.github.com'],
346
+ ['User', 'github.user', nil, nil],
347
+ ['Token', 'zenflow.token', nil, nil],
348
+ ['User Agent Base', 'zenflow.user.agent.base', nil, 'Zencoder']
349
+ ])
350
+ end
351
+ end
352
+ end
55
353
  end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe Zenflow::Repo do
4
+ describe '.hub' do
5
+ before(:each){
6
+ Zenflow::Repo.should_receive(:url).twice.and_return("git@github.com:zencoder/zenflow.git")
7
+ }
8
+
9
+ it 'selects the hub from the git remote -v url' do
10
+ expect(Zenflow::Repo.hub).to eq("github.com")
11
+ end
12
+ end
13
+
14
+ describe '.slug' do
15
+ before(:each){
16
+ Zenflow::Repo.should_receive(:url).twice.and_return("git@github.com:zencoder/zenflow.git")
17
+ }
18
+
19
+ it 'selects the repo slug from the git remote -v url' do
20
+ expect(Zenflow::Repo.slug).to eq("zencoder/zenflow")
21
+ end
22
+ end
23
+
24
+ describe '.is_current_hub?' do
25
+ before(:each){
26
+ Zenflow::Repo.should_receive(:url).twice.and_return("git@github.com:zencoder/zenflow.git")
27
+ }
28
+
29
+ context 'when check matches hub' do
30
+ it 'returns true' do
31
+ expect(Zenflow::Repo.is_current_hub?("github.com")).to eq(true)
32
+ end
33
+ end
34
+
35
+ context 'when check does not match hub' do
36
+ it 'returns false' do
37
+ expect(Zenflow::Repo.is_current_hub?("my-hub")).to eq(false)
38
+ end
39
+ end
40
+ end
41
+
42
+ describe '.is_default_hub?' do
43
+ context 'when check is not supplied' do
44
+ context 'and current hub matches default hub' do
45
+ before(:each){
46
+ Zenflow::Repo.should_receive(:url).twice.and_return("git@github.com:zencoder/zenflow.git")
47
+ }
48
+
49
+ it 'returns true' do
50
+ expect(Zenflow::Repo.is_default_hub?).to eq(true)
51
+ end
52
+ end
53
+
54
+ context 'and current hub does not match default hub' do
55
+ before(:each){
56
+ Zenflow::Repo.should_receive(:url).twice.and_return("git@my-hub:zencoder/zenflow.git")
57
+ }
58
+
59
+ it 'returns true' do
60
+ expect(Zenflow::Repo.is_default_hub?).to eq(false)
61
+ end
62
+ end
63
+ end
64
+
65
+ context 'when check is supplied' do
66
+ context 'and check matches default hub' do
67
+ it 'returns true' do
68
+ expect(Zenflow::Repo.is_default_hub?("github.com")).to eq(true)
69
+ end
70
+ end
71
+
72
+ context 'and check does not match default hub' do
73
+ it 'returns false' do
74
+ expect(Zenflow::Repo.is_default_hub?("my-hub")).to eq(false)
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zenflow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.5
4
+ version: 0.8.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Kittelson
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-01-13 00:00:00.000000000 Z
13
+ date: 2014-03-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: thor
@@ -194,6 +194,7 @@ files:
194
194
  - lib/zenflow/commands/deploy.rb
195
195
  - lib/zenflow/commands/feature.rb
196
196
  - lib/zenflow/commands/hotfix.rb
197
+ - lib/zenflow/commands/hubs.rb
197
198
  - lib/zenflow/commands/release.rb
198
199
  - lib/zenflow/commands/reviews.rb
199
200
  - lib/zenflow/helpers/ask.rb
@@ -232,6 +233,7 @@ files:
232
233
  - spec/zenflow/commands/deploy_spec.rb
233
234
  - spec/zenflow/commands/feature_spec.rb
234
235
  - spec/zenflow/commands/hotfix_spec.rb
236
+ - spec/zenflow/commands/hubs_spec.rb
235
237
  - spec/zenflow/commands/release_spec.rb
236
238
  - spec/zenflow/commands/reviews_spec.rb
237
239
  - spec/zenflow/helpers/ask_spec.rb
@@ -243,6 +245,7 @@ files:
243
245
  - spec/zenflow/helpers/help_spec.rb
244
246
  - spec/zenflow/helpers/log_spec.rb
245
247
  - spec/zenflow/helpers/pull_request_spec.rb
248
+ - spec/zenflow/helpers/repo_spec.rb
246
249
  - spec/zenflow/helpers/shell_spec.rb
247
250
  - spec/zenflow/helpers/version_spec.rb
248
251
  - zenflow.gemspec
@@ -266,7 +269,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
266
269
  version: '0'
267
270
  requirements: []
268
271
  rubyforge_project:
269
- rubygems_version: 2.1.11
272
+ rubygems_version: 2.2.1
270
273
  signing_key:
271
274
  specification_version: 4
272
275
  summary: Branch management and deployment tool.