capistrano-committed 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.codeclimate.yml +20 -0
- data/.gitignore +3 -0
- data/.rubocop.yml +1168 -0
- data/.travis.yml +8 -2
- data/Gemfile +4 -0
- data/README.md +25 -0
- data/icons/capricorn.png +0 -0
- data/icons/capricorn_equation.png +0 -0
- data/icons/capricorn_full.png +0 -0
- data/lib/capistrano/committed/github_api.rb +93 -36
- data/lib/capistrano/committed/i18n.rb +5 -0
- data/lib/capistrano/committed/version.rb +1 -1
- data/lib/capistrano/committed.rb +32 -11
- data/lib/capistrano/tasks/committed.rake +207 -168
- metadata +7 -2
data/.travis.yml
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
language: ruby
|
|
2
2
|
rvm:
|
|
3
|
-
- 2.2
|
|
4
|
-
|
|
3
|
+
- 2.2
|
|
4
|
+
- 2.1
|
|
5
|
+
- 2.0.0
|
|
6
|
+
- rbx-2
|
|
7
|
+
addons:
|
|
8
|
+
code_climate:
|
|
9
|
+
repo_token: c19f4a2a864567e4dbf3e325b4423d9478c3bf025d9e3f85c6e2ffc0c9fb960f
|
|
10
|
+
before_install: gem install bundler -v 1.11.2
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<a href="https://github.com/sambauers/capistrano-committed"><img width="136" src="https://github.com/sambauers/capistrano-committed/raw/master/icons/capricorn.png" alt="Capistrano Committed logo" /></a>
|
|
3
|
+
</div>
|
|
4
|
+
|
|
1
5
|
# Capistrano Committed
|
|
2
6
|
|
|
7
|
+
[](https://badge.fury.io/rb/capistrano-committed)
|
|
8
|
+
[](https://travis-ci.org/sambauers/capistrano-committed)
|
|
9
|
+
[](https://codeclimate.com/github/sambauers/capistrano-committed/coverage)
|
|
10
|
+
[](https://codeclimate.com/github/sambauers/capistrano-committed)
|
|
11
|
+
[](https://codeclimate.com/github/sambauers/capistrano-committed)
|
|
12
|
+
[](https://gemnasium.com/sambauers/capistrano-committed)
|
|
13
|
+
|
|
3
14
|
Capistrano Committed is an extension to Capistrano 3 which helps to determine what you are about to deploy.
|
|
4
15
|
|
|
5
16
|
It creates a report, which lets you know which GitHub commits and pull requests are not yet deployed to the target stage (server).
|
|
@@ -99,6 +110,9 @@ set :committed_issue_match, '\[\s?([A-Z0-9]+\-[0-9]+)\s?\]'
|
|
|
99
110
|
# "%s" will be replaced with the issue number. Setting this to `nil` will also
|
|
100
111
|
# disable issue matching altogether.
|
|
101
112
|
set :committed_issue_url, 'https://example.jira.com/browse/%s'
|
|
113
|
+
|
|
114
|
+
# Register deployments in GitHub via the GitHub Deployments API
|
|
115
|
+
set :committed_deployments, false
|
|
102
116
|
```
|
|
103
117
|
|
|
104
118
|
Once your required settings are all in place, you can generate a report by running:
|
|
@@ -106,3 +120,14 @@ Once your required settings are all in place, you can generate a report by runni
|
|
|
106
120
|
```shell
|
|
107
121
|
$ cap <stage> committed:generate
|
|
108
122
|
```
|
|
123
|
+
|
|
124
|
+
## What's with the unicorn?
|
|
125
|
+
|
|
126
|
+
<div align="center">
|
|
127
|
+
<a href="https://github.com/sambauers/capistrano-committed"><img width="640" src="https://github.com/sambauers/capistrano-committed/raw/master/icons/capricorn_equation.png" alt="Capistrano + GitHub API gem = Capistrano Committed gem" /></a>
|
|
128
|
+
</div>
|
|
129
|
+
|
|
130
|
+
* [Capistrano](http://capistranorb.com)
|
|
131
|
+
* [GitHub API gem](https://github.com/peter-murach/github)
|
|
132
|
+
|
|
133
|
+
|
data/icons/capricorn.png
ADDED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -4,65 +4,122 @@ module Capistrano
|
|
|
4
4
|
module Committed
|
|
5
5
|
class GithubApi
|
|
6
6
|
def initialize(config_options = {})
|
|
7
|
-
|
|
7
|
+
validate('config_options', config_options, Hash, __callee__)
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
:user_agent => 'Committed Ruby Gem (via Github API Ruby Gem)'
|
|
14
|
-
})
|
|
9
|
+
options = { adapter: :net_http,
|
|
10
|
+
ssl: { verify: false },
|
|
11
|
+
per_page: 100,
|
|
12
|
+
user_agent: 'Committed Ruby Gem (via Github API Ruby Gem)' }
|
|
15
13
|
|
|
16
|
-
|
|
14
|
+
options.merge! config_options
|
|
15
|
+
|
|
16
|
+
@client = ::Github.new options
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def client
|
|
20
|
+
@client
|
|
17
21
|
end
|
|
18
22
|
|
|
19
23
|
def get_commit(user, repo, sha)
|
|
20
|
-
validate_user_and_repo(user, repo)
|
|
21
|
-
|
|
24
|
+
validate_user_and_repo(user, repo, __callee__)
|
|
25
|
+
validate('sha', sha, String, __callee__)
|
|
22
26
|
|
|
23
|
-
|
|
24
|
-
@client.repos.commits.get(:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
api_call do
|
|
28
|
+
@client.repos.commits.get(user: user,
|
|
29
|
+
repo: repo,
|
|
30
|
+
sha: sha)
|
|
27
31
|
end
|
|
28
32
|
end
|
|
29
33
|
|
|
30
34
|
def get_commits_since(user, repo, date, branch = 'master')
|
|
31
|
-
validate_user_and_repo(user, repo)
|
|
35
|
+
validate_user_and_repo(user, repo, __callee__)
|
|
32
36
|
date = Time.parse(date) if date.is_a?(String)
|
|
33
|
-
|
|
34
|
-
|
|
37
|
+
validate('date', date, Time, __callee__)
|
|
38
|
+
validate('branch', branch, String, __callee__)
|
|
35
39
|
|
|
36
|
-
|
|
37
|
-
@client.repos.commits.list(:user
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
api_call do
|
|
41
|
+
@client.repos.commits.list(user: user,
|
|
42
|
+
repo: repo,
|
|
43
|
+
sha: branch,
|
|
44
|
+
since: date.iso8601)
|
|
40
45
|
end
|
|
41
46
|
end
|
|
42
47
|
|
|
43
48
|
def get_pull_request(user, repo, number)
|
|
44
|
-
validate_user_and_repo(user, repo)
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
info = @client.pull_requests.get(:user
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
validate_user_and_repo(user, repo, __callee__)
|
|
50
|
+
validate('number', number, Integer, __callee__)
|
|
51
|
+
|
|
52
|
+
api_call do
|
|
53
|
+
info = @client.pull_requests.get(user: user,
|
|
54
|
+
repo: repo,
|
|
55
|
+
number: number)
|
|
56
|
+
|
|
57
|
+
commits = @client.pull_requests.commits(user: user,
|
|
58
|
+
repo: repo,
|
|
59
|
+
number: number)
|
|
60
|
+
|
|
61
|
+
return { info: info, commits: commits }
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def register_deployment(user, repo, stage, branch = 'master')
|
|
66
|
+
validate_user_and_repo(user, repo, __callee__)
|
|
67
|
+
validate('stage', stage, String, __callee__)
|
|
68
|
+
validate('branch', branch, String, __callee__)
|
|
69
|
+
|
|
70
|
+
api_call do
|
|
71
|
+
@client.repos.deployments.create(user: user,
|
|
72
|
+
repo: repo,
|
|
73
|
+
environment: stage,
|
|
74
|
+
ref: branch,
|
|
75
|
+
auto_merge: false,
|
|
76
|
+
required_contexts: [])
|
|
53
77
|
end
|
|
54
78
|
end
|
|
55
79
|
|
|
56
|
-
def
|
|
57
|
-
|
|
58
|
-
|
|
80
|
+
def register_deployment_status(user, repo, id, state)
|
|
81
|
+
validate_user_and_repo(user, repo, __callee__)
|
|
82
|
+
validate('id', id, Integer, __callee__)
|
|
83
|
+
|
|
84
|
+
valid_states = %w(pending success error failure)
|
|
85
|
+
state = state.to_s
|
|
86
|
+
unless valid_states.include?(state)
|
|
87
|
+
message = t('committed.error.helpers.valid_param',
|
|
88
|
+
method: __callee__,
|
|
89
|
+
param: 'state')
|
|
90
|
+
fail TypeError, message
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
api_call do
|
|
94
|
+
@client.repos.deployments.create_status(user: user,
|
|
95
|
+
repo: repo,
|
|
96
|
+
id: id,
|
|
97
|
+
state: state)
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
private
|
|
102
|
+
|
|
103
|
+
def validate(param, value, type, method)
|
|
104
|
+
return if value.is_a?(type)
|
|
105
|
+
message = t('committed.error.helpers.valid_param',
|
|
106
|
+
method: method,
|
|
107
|
+
param: param)
|
|
108
|
+
fail TypeError, message
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def validate_user_and_repo(user, repo, method)
|
|
112
|
+
validate('GitHub user', user, String, method)
|
|
113
|
+
validate('GitHub repository', repo, String, method)
|
|
59
114
|
end
|
|
60
115
|
|
|
61
|
-
def
|
|
116
|
+
def api_call
|
|
117
|
+
yield
|
|
118
|
+
rescue ::Github::Error::GithubError => e
|
|
62
119
|
if e.is_a? ::Github::Error::ServiceError
|
|
63
|
-
raise e, '
|
|
120
|
+
raise e, t('committed.error.helpers.github_service_error')
|
|
64
121
|
elsif e.is_a? ::Github::Error::ClientError
|
|
65
|
-
raise e, '
|
|
122
|
+
raise e, t('committed.error.helpers.github_client_error')
|
|
66
123
|
end
|
|
67
124
|
end
|
|
68
125
|
end
|
|
@@ -2,6 +2,11 @@ require 'i18n'
|
|
|
2
2
|
|
|
3
3
|
en = {
|
|
4
4
|
error: {
|
|
5
|
+
helpers: {
|
|
6
|
+
valid_param: '`%{method}` requires a valid %{param}.',
|
|
7
|
+
github_service_error: 'There seems to be a problem with the GitHub service.',
|
|
8
|
+
github_client_error: 'There seems to be a problem with the request that was made to GitHub, check that your settings are correct.'
|
|
9
|
+
},
|
|
5
10
|
prerequisites: {
|
|
6
11
|
nil: '`:%{variable}` variable is `nil`, it needs to contain the %{name} name.',
|
|
7
12
|
empty: '`:%{variable}` variable is empty, it needs to contain the %{name} name.',
|
data/lib/capistrano/committed.rb
CHANGED
|
@@ -1,22 +1,43 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'capistrano/committed/version'
|
|
2
2
|
require 'capistrano/committed/i18n'
|
|
3
|
-
require
|
|
3
|
+
require 'capistrano/committed/github_api'
|
|
4
4
|
|
|
5
5
|
module Capistrano
|
|
6
6
|
module Committed
|
|
7
7
|
class << self
|
|
8
|
-
def
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
def get_issue_urls(issue_pattern, url_pattern, message)
|
|
9
|
+
fail TypeError, t('committed.error.helpers.valid_param',
|
|
10
|
+
method: __callee__,
|
|
11
|
+
param: 'issue_pattern') unless
|
|
12
|
+
issue_pattern.is_a?(String) ||
|
|
13
|
+
issue_pattern.is_a?(Regexp)
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
fail TypeError, t('committed.error.helpers.valid_param',
|
|
16
|
+
method: __callee__,
|
|
17
|
+
param: 'url_pattern') unless
|
|
18
|
+
url_pattern.is_a?(String)
|
|
19
|
+
|
|
20
|
+
fail TypeError, t('committed.error.helpers.valid_param',
|
|
21
|
+
method: __callee__,
|
|
22
|
+
param: 'message') unless
|
|
23
|
+
message.is_a?(String)
|
|
24
|
+
|
|
25
|
+
matches = message.scan(Regexp.new(issue_pattern))
|
|
26
|
+
return [] unless matches
|
|
27
|
+
matches.map { |m| format(url_pattern, m[0]) }
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def format_issue_urls(urls, pad = '')
|
|
31
|
+
return [] if urls.nil? || urls.empty?
|
|
32
|
+
output = []
|
|
33
|
+
output << format('%s %s', pad, t('committed.output.issue_links'))
|
|
34
|
+
urls.each do |url|
|
|
35
|
+
output << format('%s - %s', pad, url)
|
|
36
|
+
end
|
|
37
|
+
output << format('%s', pad)
|
|
17
38
|
end
|
|
18
39
|
end
|
|
19
40
|
end
|
|
20
41
|
end
|
|
21
42
|
|
|
22
|
-
load File.expand_path(
|
|
43
|
+
load File.expand_path('../tasks/committed.rake', __FILE__)
|