zenflow 0.8.11 → 0.8.12

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: b67040a126c62ab1469ef2a30368d38de33c5fca
4
- data.tar.gz: dcba8ef01d0261d39ee5d4f69c5c7f15a5bfda03
3
+ metadata.gz: 535021ad71ee3cd875c4678f99c3c27f8805f642
4
+ data.tar.gz: 68935fb8a30a1cf0eebcb3c64949ada99e050269
5
5
  SHA512:
6
- metadata.gz: 2ad33edb69aa5f56bd4946c1c05f60e7dcf3618e94c9ec30e04af4043be80ff0097af464d939431d070377f95b06088abaa27a80b0356ec663928a26505b1104
7
- data.tar.gz: 99c6641438d33951e12418443b125d86dd1a35b56904d553508e0c1f6a3d8c8f036402ae10f5274fdfd9423a5a112c2101490e5e86a0fd82465132d7d9e71cb3
6
+ metadata.gz: 2372fe27f75467045ebb30314d5647ca5595179d5242165f6476ffe100bb8255ec04ed45d76f313db15114f39dcf3dc06e31e0cb14f24654234570441c461fc9
7
+ data.tar.gz: d4758ca08c2ee5833eea692a50be68dfb4a57913fc94361b18bfe13ed05571a474a728297b83e8b8846357e1391fa074affae33c3d22ddd8e6184cccbd35a577
@@ -10,3 +10,6 @@ CHANGELOG
10
10
 
11
11
  ---- 0.8.11 / 2014-07-11 / merge-hotfixes-and-releases-into-master-and-production
12
12
  * hotfixes should merge into the development branch as well as the source branch
13
+
14
+ ---- 0.8.12 / 2014-08-12 / updates-for-github-enterprise-support
15
+ * updates for github enterprise support
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zenflow (0.8.11)
4
+ zenflow (0.8.12)
5
5
  colored (~> 1.2)
6
6
  httparty (~> 0.13.0)
7
7
  terminal-table (~> 1.4.5)
@@ -12,6 +12,7 @@
12
12
  * [Usage](#usage)
13
13
  * [Commands Quick Reference](#commands)
14
14
  * [Requirements](#requirements)
15
+ * [Enterprise Configuration](#enterprise)
15
16
 
16
17
  -------
17
18
 
@@ -89,6 +90,7 @@ To deploy to production, type `zenflow deploy production`. Hotfixes are not auto
89
90
  zenflow (feature|hotfix|release) review
90
91
  zenflow (feature|hotfix|release) finish
91
92
  zenflow deploy (qa|staging|production)
93
+ zenflow admin (list|current|describe|config|authorize)
92
94
 
93
95
  ### <a name="requirements"></a> Requirements/Assumptions
94
96
 
@@ -96,3 +98,9 @@ To deploy to production, type `zenflow deploy production`. Hotfixes are not auto
96
98
  * Ruby >= 1.9.3
97
99
  * Capistrano and cap-ext
98
100
  * A repository on GitHub
101
+
102
+ ### <a name="enterprise"></a> Enterpise Configuration
103
+
104
+ Zenflow now supports repositories hosted on enterprise github servers. `zenflow init` will automatically detect which server is hosting your repository by examining the remote string returned by `git remote -v`. If it is an enterprise server, Zenflow will ask for additional configuration parameters including the API base URL of the enterprise server and an optional over-ride for the User-Agent header that Zenflow submits to the server. All configuration parameters are stored in git config.
105
+
106
+ Zenflow can handle any number of enterprise github servers in addition to working with the primary github server at github.com. To examine the github server configurations of your Zenflow install use the `zenflow admin ...` set of commands.
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  major: 0
3
3
  minor: 8
4
- patch: 11
4
+ patch: 12
5
5
  pre:
@@ -26,10 +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/admin'
29
30
  require 'zenflow/commands/deploy'
30
31
  require 'zenflow/commands/feature'
31
32
  require 'zenflow/commands/hotfix'
32
- require 'zenflow/commands/hubs'
33
33
  require 'zenflow/commands/release'
34
34
  require 'zenflow/commands/reviews'
35
35
  require 'zenflow/cli'
@@ -20,8 +20,8 @@ module Zenflow
20
20
  super
21
21
  end
22
22
 
23
- desc "hubs SUBCOMMAND", "Manage Github server configurations."
24
- subcommand "hubs", Zenflow::Hubs
23
+ desc "admin SUBCOMMAND", "Manage Github server configurations."
24
+ subcommand "admin", Zenflow::Admin
25
25
 
26
26
  desc "feature SUBCOMMAND", "Manage feature branches."
27
27
  subcommand "feature", Zenflow::Feature
@@ -54,29 +54,6 @@ module Zenflow
54
54
  end
55
55
  end
56
56
 
57
- desc "set_up_github", "Set up GitHub user information"
58
- def set_up_github
59
- user = Zenflow::Github.user(Zenflow::Github::DEFAULT_HUB)
60
- if user.to_s != ''
61
- if Zenflow::Ask("Your GitHub user is currently #{user}. Do you want to use that?", :options => ["Y", "n"], :default => "y") == "n"
62
- Zenflow::Github.set_user(Zenflow::Github::DEFAULT_HUB)
63
- end
64
- else
65
- Zenflow::Github.set_user(Zenflow::Github::DEFAULT_HUB)
66
- end
67
- end
68
-
69
- desc "authorize_github", "Get an auth token from GitHub"
70
- def authorize_github
71
- if Zenflow::Github.zenflow_token(Zenflow::Github::DEFAULT_HUB)
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"
73
- Zenflow::Github.authorize(Zenflow::Github::DEFAULT_HUB)
74
- end
75
- else
76
- Zenflow::Github.authorize(Zenflow::Github::DEFAULT_HUB)
77
- end
78
- end
79
-
80
57
  no_commands do
81
58
 
82
59
  def already_configured
@@ -90,14 +67,12 @@ module Zenflow
90
67
  end
91
68
 
92
69
  def configure_github
93
- #TODO: consolidate these two paths
94
- if Zenflow::Repo.is_default_hub?
95
- set_up_github
96
- authorize_github
70
+ if Zenflow::Github::CURRENT.is_default_hub?
71
+ Zenflow::Github::CURRENT.set_user
97
72
  else
98
- Zenflow::Hubs.config
99
- Zenflow::Hubs.authorize
73
+ Zenflow::Github::CURRENT.config
100
74
  end
75
+ Zenflow::Github::CURRENT.authorize
101
76
  end
102
77
 
103
78
  def configure_project
@@ -0,0 +1,88 @@
1
+ module Zenflow
2
+ class Admin < 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::Github::CURRENT.hub)}")
16
+ end
17
+
18
+ desc "describe [HUB]", "Show configuration details for HUB (current project hub if none specified, or default if no current project)."
19
+ def describe(hub=nil)
20
+ hub = resolve_hub(hub)
21
+
22
+ Zenflow::Log("Configuration details for hub #{hub_label(hub.hub)}")
23
+
24
+ Zenflow::Log(Terminal::Table.new(
25
+ headings: ["Parameter", "Github Config Key", "Github Config Value", "Value (with system defaults)"],
26
+ rows: hub.describe
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 = resolve_hub(hub)
33
+
34
+ Zenflow::Log("Configuring #{hub_label(hub.hub)}")
35
+
36
+ hub.config
37
+ end
38
+
39
+ desc "authorize [HUB]", "Grab an auth token for HUB (current project hub if none specified, or default hub if no current project)."
40
+ def authorize(hub=nil)
41
+ hub = resolve_hub(hub)
42
+
43
+ Zenflow::Log("Authorizing #{hub_label(hub.hub)}")
44
+
45
+ hub.authorize
46
+ end
47
+
48
+ no_commands {
49
+ def resolve_hub(hub=nil)
50
+ hub = Zenflow::Github.new(hub) if hub
51
+ hub ||= Zenflow::Github::CURRENT
52
+ end
53
+
54
+ def get_list_of_hubs
55
+ hub_config_parameters = Zenflow::Shell.run("git config --get-regexp zenflow\.hub\..*", silent: true).split("\n")
56
+
57
+ # unique, sorted, list of hubs with at least one valid config key
58
+ configured_hubs = hub_config_parameters.inject([]) { |hubs, parameter|
59
+ if parameter =~ /^zenflow\.hub\.(.*)\.#{config_keys_regex}\s.*$/
60
+ hubs << [hub_label($1)]
61
+ end
62
+
63
+ hubs
64
+ }.sort.uniq
65
+
66
+ [
67
+ ["#{hub_label(Zenflow::Github::DEFAULT_HUB)}"]
68
+ ] + configured_hubs
69
+ end
70
+
71
+ def hub_label(hub)
72
+ "#{hub}#{default_hub_tag(hub)}#{current_hub_tag(hub)}"
73
+ end
74
+
75
+ def default_hub_tag(hub)
76
+ hub == Zenflow::Github::DEFAULT_HUB ? " [default]" : ""
77
+ end
78
+
79
+ def current_hub_tag(hub)
80
+ hub == Zenflow::Github::CURRENT.hub ? " [current]" : ""
81
+ end
82
+
83
+ def config_keys_regex
84
+ "(?:#{Zenflow::Github::CONFIG_KEYS.map { |s| s.gsub('.','\\.') }.join('|')})"
85
+ end
86
+ }
87
+ end
88
+ end
@@ -1,6 +1,6 @@
1
1
  module Zenflow
2
2
 
3
- module Github
3
+ class Github
4
4
  DEFAULT_HUB = 'github.com'
5
5
 
6
6
  DEFAULT_API_BASE_URL = 'https://api.github.com'
@@ -18,105 +18,148 @@ module Zenflow
18
18
  USER_AGENT_BASE_KEY
19
19
  ]
20
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
21
+ @hub = nil
22
+ def hub
23
+ @hub
24
+ end
25
+
26
+ def initialize(hub)
27
+ @hub = hub
28
+ end
29
+
30
+ def self.current
31
+ Github.new(Zenflow::Repo.hub || DEFAULT_HUB)
32
+ end
33
+
34
+ CURRENT = current
35
+
36
+ def config
37
+ set_api_base_url
38
+ set_user
39
+ set_user_agent_base
40
+ end
41
+
42
+ def api_base_url(use_default_when_value_is_nil=true)
43
+ api_base_url = get_config(API_BASE_URL_KEY)
44
+ api_base_url ||= DEFAULT_API_BASE_URL if use_default_when_value_is_nil
24
45
  api_base_url
25
46
  end
26
47
 
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)
48
+ def ask_should_update_base_api_url?
49
+ Zenflow::Ask("The GitHub API base URL for this hub is currently #{api_base_url(false)}. Do you want to use that?", :options => ["Y", "n"], :default => "y") == "n"
50
+ end
51
+
52
+ def set_api_base_url
53
+ if api_base_url(false).nil? || ask_should_update_base_api_url?
54
+ api_base_url = Zenflow::Ask("What is the base URL of your Github API?", {:default => DEFAULT_API_BASE_URL})
55
+ set_config(API_BASE_URL_KEY, api_base_url)
56
+ end
57
+ end
58
+
59
+ def user
60
+ get_config(USER_KEY)
61
+ end
62
+
63
+ def ask_should_update_user?
64
+ Zenflow::Ask("The GitHub user for this hub is currently #{user}. Do you want to use that?", :options => ["Y", "n"], :default => "y") == "n"
30
65
  end
31
66
 
32
- def self.user(hub=nil)
33
- get_config_for_hub(hub, USER_KEY)
67
+ def set_user
68
+ if user.nil? || ask_should_update_user?
69
+ username = Zenflow::Ask("What is your Github username?")
70
+ set_config(USER_KEY, username)
71
+ end
34
72
  end
35
73
 
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)
74
+ def zenflow_token
75
+ get_config(TOKEN_KEY)
39
76
  end
40
77
 
41
- def self.zenflow_token(hub=nil)
42
- get_config_for_hub(hub, TOKEN_KEY)
78
+ def ask_should_update_zenflow_token?
79
+ Zenflow::Ask("You already have a token from GitHub. Do you want to set a new one?", :options => ["y", "N"], :default => "n") == "y"
43
80
  end
44
81
 
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))
48
- if oauth_response['token']
49
- set_config_for_hub(hub, TOKEN_KEY, oauth_response['token'])
50
- Zenflow::Log("Authorized!")
51
- else
52
- Zenflow::Log("Something went wrong. Error from GitHub was: #{oauth_response['message']}")
53
- return
82
+ def authorize
83
+ if zenflow_token.nil? || ask_should_update_zenflow_token?
84
+ Zenflow::Log("Authorizing with GitHub (#{user}@#{@hub})... Enter your GitHub password.")
85
+ oauth_response = JSON.parse(Zenflow::Shell.run(%{curl -u "#{user}" #{api_base_url}/authorizations -d '{"scopes":["repo"], "note":"Zenflow"}' --silent}, silent: true))
86
+ if oauth_response['token']
87
+ set_config(TOKEN_KEY, oauth_response['token'])
88
+ Zenflow::Log("Authorized!")
89
+ else
90
+ Zenflow::Log("Something went wrong. Error from GitHub was: #{oauth_response['message']}")
91
+ return
92
+ end
54
93
  end
55
94
  end
56
95
 
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
96
+ def user_agent_base(use_default_when_value_is_nil=true)
97
+ user_agent_base = get_config(USER_AGENT_BASE_KEY)
98
+ user_agent_base ||= DEFAULT_USER_AGENT_BASE if use_default_when_value_is_nil
60
99
  user_agent_base
61
100
  end
62
101
 
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)
102
+ def ask_should_update_user_agent_base?
103
+ Zenflow::Ask("The GitHub User Agent base for this hub is currently #{user_agent_base(false)}. Do you want to use that?", :options => ["Y", "n"], :default => "y") == "n"
66
104
  end
67
105
 
68
- def self.resolve_hub(hub)
69
- hub || Zenflow::Repo.hub || DEFAULT_HUB
106
+ def set_user_agent_base
107
+ if user_agent_base(false).nil? || ask_should_update_user_agent_base?
108
+ 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})
109
+ set_config(USER_AGENT_BASE_KEY, user_agent_base)
110
+ end
70
111
  end
71
112
 
72
113
  # 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)
114
+ def parameter_key_for_hub(key)
74
115
  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}"
116
+ is_default_hub? ? "#{default_hub_key_prefix}#{key}" : "zenflow.hub.#{@hub}.#{key}"
76
117
  end
77
118
 
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)
119
+ def get_config(base_parameter_key)
120
+ parameter_key_for_hub = parameter_key_for_hub(base_parameter_key)
121
+ get_global_config(parameter_key_for_hub)
82
122
  end
83
123
 
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)
124
+ def set_config(base_parameter_key, value)
125
+ parameter_key_for_hub = parameter_key_for_hub(base_parameter_key)
126
+ set_global_config(parameter_key_for_hub, value)
88
127
  end
89
128
 
90
- def self.get_global_config(key)
129
+ def get_global_config(key)
91
130
  config = Zenflow::Shell.run("git config --get #{key.to_s}", silent: true)
92
131
  config = config.chomp unless config.nil?
93
132
  config.to_s == '' ? nil : config
94
133
  end
95
134
 
96
- def self.set_global_config(key, value)
135
+ def set_global_config(key, value)
97
136
  Zenflow::Shell.run("git config --global #{key} #{value}", silent: true)
98
137
  end
99
138
 
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]
139
+ def is_default_hub?
140
+ @hub == DEFAULT_HUB
141
+ end
142
+
143
+ def describe_parameter(name, parameter_key, value)
144
+ [name, parameter_key_for_hub(parameter_key), get_config(parameter_key), value]
102
145
  end
103
146
 
104
- def self.describe_hub(hub)
147
+ def describe
105
148
  [
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))
149
+ describe_parameter("API Base URL", API_BASE_URL_KEY, api_base_url),
150
+ describe_parameter("User", USER_KEY, user),
151
+ describe_parameter("Token", TOKEN_KEY, zenflow_token),
152
+ describe_parameter("User Agent Base", USER_AGENT_BASE_KEY, user_agent_base)
110
153
  ]
111
154
  end
112
155
  end
113
156
 
114
157
  class GithubRequest
115
158
  include HTTParty
116
- base_uri "#{Zenflow::Github.api_base_url}/repos/#{Zenflow::Repo.slug}"
159
+ base_uri "#{Github::CURRENT.api_base_url}/repos/#{Zenflow::Repo.slug}"
117
160
  format :json
118
- headers "Authorization" => "token #{Zenflow::Github.zenflow_token}"
119
- headers "User-Agent" => "#{Zenflow::Github.user_agent_base}/Zenflow-#{VERSION}"
161
+ headers "Authorization" => "token #{Github::CURRENT.zenflow_token}"
162
+ headers "User-Agent" => "#{Github::CURRENT.user_agent_base}/Zenflow-#{VERSION}"
120
163
  end
121
164
 
122
165
  end
@@ -12,14 +12,5 @@ module Zenflow
12
12
  def self.slug
13
13
  (url && url[/:(.*?)\.git/, 1]) || nil
14
14
  end
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
-
24
15
  end
25
16
  end