github-rundeck 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -12
- data/Gemfile.lock +42 -35
- data/README.md +1 -1
- data/{config.json → config/config.json} +0 -0
- data/exe/github-rundeck +5 -72
- data/github-rundeck.gemspec +1 -1
- data/lib/github-rundeck.rb +5 -134
- data/lib/github-rundeck/api.rb +154 -0
- data/lib/github-rundeck/cli.rb +85 -0
- data/lib/github-rundeck/config.rb +78 -0
- data/lib/github-rundeck/git.rb +51 -0
- data/lib/github-rundeck/helpers/configuration.rb +57 -0
- data/lib/github-rundeck/util.rb +64 -0
- data/lib/github-rundeck/version.rb +3 -0
- metadata +11 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c22589f9897857c2ab82a2fa78a699e80f56f286
|
4
|
+
data.tar.gz: fd0d2db2e364a4bb4a4958e3bb92f6475b0faaf3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33e0165857fcc814954f92c71378afad328c245b933553951e6f91a554843cdf8e56164dbc0f8331e057e5be8aa64435c3dd433672708350521f233f9a0d81fd
|
7
|
+
data.tar.gz: d319b4720817de27b937ed2b035fe06b08790106ae96f1cbabb31dc3daa5c44ffb0a9b955592e8d8f648fecd1ec954384a4fe21c56321834110bba5a1aa5c855
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
github-rundeck (0.1.3)
|
5
|
+
github_api (~> 0.14)
|
6
|
+
mixlib-cli (~> 1.6)
|
7
|
+
rack-cache (~> 1.6)
|
8
|
+
sinatra (~> 1.4)
|
9
|
+
sinatra-contrib (~> 1.4)
|
10
|
+
|
1
11
|
GEM
|
2
12
|
remote: https://rubygems.org/
|
3
13
|
specs:
|
@@ -9,51 +19,51 @@ GEM
|
|
9
19
|
diff-lcs (1.2.5)
|
10
20
|
faraday (0.9.2)
|
11
21
|
multipart-post (>= 1.2, < 3)
|
12
|
-
github_api (0.14.
|
22
|
+
github_api (0.14.5)
|
13
23
|
addressable (~> 2.4.0)
|
14
24
|
descendants_tracker (~> 0.0.4)
|
15
25
|
faraday (~> 0.8, < 0.10)
|
16
26
|
hashie (>= 3.4)
|
17
|
-
oauth2
|
18
|
-
hashie (3.4.
|
19
|
-
jwt (1.5.
|
20
|
-
mixlib-cli (1.
|
27
|
+
oauth2 (~> 1.0)
|
28
|
+
hashie (3.4.6)
|
29
|
+
jwt (1.5.6)
|
30
|
+
mixlib-cli (1.7.0)
|
21
31
|
multi_json (1.12.1)
|
22
|
-
multi_xml (0.
|
32
|
+
multi_xml (0.6.0)
|
23
33
|
multipart-post (2.0.0)
|
24
|
-
oauth2 (1.
|
25
|
-
faraday (>= 0.8, < 0.
|
26
|
-
jwt (~> 1.0
|
34
|
+
oauth2 (1.3.0)
|
35
|
+
faraday (>= 0.8, < 0.11)
|
36
|
+
jwt (~> 1.0)
|
27
37
|
multi_json (~> 1.3)
|
28
38
|
multi_xml (~> 0.5)
|
29
39
|
rack (>= 1.2, < 3)
|
30
|
-
parser (2.3.1
|
40
|
+
parser (2.3.3.1)
|
31
41
|
ast (~> 2.2)
|
32
42
|
powerpack (0.1.1)
|
33
|
-
rack (1.6.
|
43
|
+
rack (1.6.5)
|
34
44
|
rack-cache (1.6.1)
|
35
45
|
rack (>= 0.4)
|
36
46
|
rack-protection (1.5.3)
|
37
47
|
rack
|
38
48
|
rack-test (0.6.3)
|
39
49
|
rack (>= 1.0)
|
40
|
-
rainbow (2.1
|
41
|
-
rake (
|
42
|
-
rspec (3.
|
43
|
-
rspec-core (~> 3.
|
44
|
-
rspec-expectations (~> 3.
|
45
|
-
rspec-mocks (~> 3.
|
46
|
-
rspec-core (3.
|
47
|
-
rspec-support (~> 3.
|
48
|
-
rspec-expectations (3.
|
50
|
+
rainbow (2.2.1)
|
51
|
+
rake (10.5.0)
|
52
|
+
rspec (3.5.0)
|
53
|
+
rspec-core (~> 3.5.0)
|
54
|
+
rspec-expectations (~> 3.5.0)
|
55
|
+
rspec-mocks (~> 3.5.0)
|
56
|
+
rspec-core (3.5.4)
|
57
|
+
rspec-support (~> 3.5.0)
|
58
|
+
rspec-expectations (3.5.0)
|
49
59
|
diff-lcs (>= 1.2.0, < 2.0)
|
50
|
-
rspec-support (~> 3.
|
51
|
-
rspec-mocks (3.
|
60
|
+
rspec-support (~> 3.5.0)
|
61
|
+
rspec-mocks (3.5.0)
|
52
62
|
diff-lcs (>= 1.2.0, < 2.0)
|
53
|
-
rspec-support (~> 3.
|
54
|
-
rspec-support (3.
|
55
|
-
rubocop (0.
|
56
|
-
parser (>= 2.3.1
|
63
|
+
rspec-support (~> 3.5.0)
|
64
|
+
rspec-support (3.5.0)
|
65
|
+
rubocop (0.47.1)
|
66
|
+
parser (>= 2.3.3.1, < 3.0)
|
57
67
|
powerpack (~> 0.1)
|
58
68
|
rainbow (>= 1.99.1, < 3.0)
|
59
69
|
ruby-progressbar (~> 1.7)
|
@@ -72,20 +82,17 @@ GEM
|
|
72
82
|
tilt (>= 1.3, < 3)
|
73
83
|
thread_safe (0.3.5)
|
74
84
|
tilt (2.0.5)
|
75
|
-
unicode-display_width (1.
|
85
|
+
unicode-display_width (1.1.3)
|
76
86
|
|
77
87
|
PLATFORMS
|
78
88
|
ruby
|
79
89
|
|
80
90
|
DEPENDENCIES
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
rspec
|
91
|
+
bundler (~> 1.12)
|
92
|
+
github-rundeck!
|
93
|
+
rake (~> 10.0)
|
94
|
+
rspec (~> 3.0)
|
86
95
|
rubocop
|
87
|
-
sinatra
|
88
|
-
sinatra-contrib
|
89
96
|
|
90
97
|
BUNDLED WITH
|
91
|
-
1.
|
98
|
+
1.13.7
|
data/README.md
CHANGED
@@ -8,7 +8,7 @@ This gem delivers RunDeck options in the supported JSON format
|
|
8
8
|
* List of Branch/Tag Names for a Repo - `GET` - *http://localhost:9125/github/v1/revisions/${ORGNAME}/${REPONAME}*
|
9
9
|
|
10
10
|
### OAuth Key
|
11
|
-
You can feed a GitHub OAuth key via local configuration, or as the Query Parameter `
|
11
|
+
You can feed a GitHub OAuth key via local configuration, or as the Query Parameter `gh_oauth_token`
|
12
12
|
|
13
13
|
|
14
14
|
## Installation
|
File without changes
|
data/exe/github-rundeck
CHANGED
@@ -1,82 +1,15 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# encoding: UTF-8
|
3
|
-
# rubocop: disable LineLength
|
4
3
|
# RunDeck Options Provider - GitHub Repositories
|
5
4
|
# Brian Dwyer - Intelligent Digital Services - 5/14/16
|
6
5
|
|
7
6
|
lib = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
8
7
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
require 'mixlib/cli'
|
13
|
-
require 'json'
|
14
|
-
|
15
|
-
# => Github-RunDeck Launcher
|
16
|
-
class GithubRunDeckCLI
|
17
|
-
include Mixlib::CLI
|
18
|
-
|
19
|
-
option :github_oauth_token,
|
20
|
-
short: '-o TOKEN',
|
21
|
-
long: '--github-oauth-token TOKEN',
|
22
|
-
description: 'OAuth Token to use for querying GitHub',
|
23
|
-
default: nil
|
24
|
-
|
25
|
-
option :cache_timeout,
|
26
|
-
short: '-t CACHE_TIMEOUT',
|
27
|
-
long: '--timeout CACHE_TIMEOUT',
|
28
|
-
description: 'Sets the response timeout in seconds for the query data.',
|
29
|
-
default: 30
|
30
|
-
|
31
|
-
option :config_file,
|
32
|
-
short: '-c CONFIG',
|
33
|
-
long: '--config CONFIG',
|
34
|
-
description: 'The configuration file to use, as opposed to command-line parameters (optional)',
|
35
|
-
default: nil
|
36
|
-
|
37
|
-
option :host,
|
38
|
-
short: '-h HOST',
|
39
|
-
long: '--host HOST',
|
40
|
-
description: 'Listen on HOST (default: localhost)',
|
41
|
-
default: 'localhost'
|
42
|
-
|
43
|
-
option :port,
|
44
|
-
short: '-p PORT',
|
45
|
-
long: '--port PORT',
|
46
|
-
description: 'The port to run on, default 9123',
|
47
|
-
default: 9123
|
9
|
+
# => Catch Ctrl+C's to avoid stack traces
|
10
|
+
Signal.trap('INT') { abort }
|
48
11
|
|
49
|
-
|
50
|
-
short: '-e ENV',
|
51
|
-
long: '--env ENV',
|
52
|
-
description: 'Sets the environment for chef-rundeck to execute under. Use "development" for more logging.',
|
53
|
-
default: 'production'
|
54
|
-
end
|
55
|
-
|
56
|
-
cli = GithubRunDeckCLI.new
|
57
|
-
cli.parse_options
|
58
|
-
|
59
|
-
# => Define JSON Parser
|
60
|
-
def parse_json_config(file = nil)
|
61
|
-
return unless file && ::File.exist?(file.to_s)
|
62
|
-
begin
|
63
|
-
::JSON.parse(::File.read(file.to_s), symbolize_names: true)
|
64
|
-
rescue JSON::ParserError
|
65
|
-
return
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
# => Parse JSON Config File
|
70
|
-
json_config = parse_json_config(cli.config[:config_file])
|
71
|
-
|
72
|
-
# => Merge Configuration (JSON File Wins)
|
73
|
-
config = [cli.config, json_config].compact.reduce(:merge)
|
74
|
-
|
75
|
-
# => Apply Configuration
|
76
|
-
GithubRunDeck.github_oauth_token = config[:github_oauth_token]
|
77
|
-
GithubRunDeck.cache_timeout = config[:cache_timeout].to_i
|
78
|
-
GithubRunDeck.config_file = config[:config_file] if json_config
|
79
|
-
GithubRunDeck.environment = config[:env].to_sym
|
12
|
+
require 'github-rundeck'
|
80
13
|
|
81
|
-
# => Launch the
|
82
|
-
GithubRunDeck.run
|
14
|
+
# => Launch the Plugin
|
15
|
+
GithubRunDeck::CLI.run(ARGV)
|
data/github-rundeck.gemspec
CHANGED
data/lib/github-rundeck.rb
CHANGED
@@ -3,139 +3,10 @@
|
|
3
3
|
# GitHub Repo Poller for RunDeck
|
4
4
|
# Brian Dwyer - Intelligent Digital Services - 5/14/16
|
5
5
|
|
6
|
-
require '
|
7
|
-
require 'sinatra/namespace'
|
8
|
-
require 'github_api'
|
9
|
-
require 'json'
|
10
|
-
require 'rack/cache'
|
6
|
+
require 'github-rundeck/cli'
|
11
7
|
|
12
|
-
# => GitHub RunDeck
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
class << self
|
17
|
-
attr_accessor :config_file
|
18
|
-
attr_accessor :cache_timeout
|
19
|
-
attr_accessor :github_oauth_token
|
20
|
-
end
|
21
|
-
|
22
|
-
if development?
|
23
|
-
require 'sinatra/reloader'
|
24
|
-
register Sinatra::Reloader
|
25
|
-
end
|
26
|
-
|
27
|
-
VERSION = '0.1.2'.freeze
|
28
|
-
|
29
|
-
######################
|
30
|
-
# => Definitions <=#
|
31
|
-
######################
|
32
|
-
|
33
|
-
def ghclient
|
34
|
-
# => Instantiate a new GitHub Client
|
35
|
-
Github::Client.new
|
36
|
-
end
|
37
|
-
|
38
|
-
def serialize(response)
|
39
|
-
# => Serialize Object into JSON Array
|
40
|
-
JSON.pretty_generate(response.map(&:name).sort_by(&:downcase))
|
41
|
-
end
|
42
|
-
|
43
|
-
def serialize_revisions(branches, tags)
|
44
|
-
# => Serialize Branches/Tags into JSON Array
|
45
|
-
# => Branches = String, Tags = Key/Value
|
46
|
-
branches = branches.map(&:name).sort_by(&:downcase)
|
47
|
-
tags = tags.map(&:name).sort_by(&:downcase).reverse.map { |tag| { name: "Tag: #{tag}", value: tag } }
|
48
|
-
JSON.pretty_generate(branches + tags)
|
49
|
-
end
|
50
|
-
|
51
|
-
######################
|
52
|
-
# => Sinatra <=#
|
53
|
-
######################
|
54
|
-
|
55
|
-
use Rack::Cache do
|
56
|
-
set :verbose, true
|
57
|
-
set :metastore, 'file:' + File.join(Dir.tmpdir, 'rack', 'meta')
|
58
|
-
set :entitystore, 'file:' + File.join(Dir.tmpdir, 'rack', 'body')
|
59
|
-
end
|
60
|
-
|
61
|
-
# => Current Configuration & Healthcheck Endpoint
|
62
|
-
get '/' do
|
63
|
-
content_type 'application/json'
|
64
|
-
JSON.pretty_generate(
|
65
|
-
Status: "#{self.class} is up and running!",
|
66
|
-
ConfigFile: GithubRunDeck.config_file,
|
67
|
-
CacheTimeout: GithubRunDeck.cache_timeout,
|
68
|
-
GithubOAuthToken: GithubRunDeck.github_oauth_token,
|
69
|
-
Params: params.inspect
|
70
|
-
)
|
71
|
-
end
|
72
|
-
|
73
|
-
#######################
|
74
|
-
# => JSON API <=#
|
75
|
-
#######################
|
76
|
-
|
77
|
-
namespace '/github/v1' do
|
78
|
-
# => Define our common namespace parameters
|
79
|
-
before do
|
80
|
-
# => This is a JSON API
|
81
|
-
content_type 'application/json'
|
82
|
-
|
83
|
-
# => Cache GitHub Responses
|
84
|
-
cache_control :public, max_age: GithubRunDeck.cache_timeout || 30
|
85
|
-
|
86
|
-
# => Parameter Overrides
|
87
|
-
Github.configure do |cfg|
|
88
|
-
cfg.oauth_token = params['oauth_token'] || GithubRunDeck.github_oauth_token
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
# => Get Organization Repo List
|
93
|
-
get '/repos/org/:org' do |org|
|
94
|
-
ghresponse = ghclient.repos.list(org: org, per_page: 100)
|
95
|
-
etag ghresponse.headers.etag
|
96
|
-
body serialize(ghresponse)
|
97
|
-
end
|
98
|
-
|
99
|
-
# => Get User Repo List
|
100
|
-
get '/repos/user/:user' do |user|
|
101
|
-
ghresponse = ghclient.repos.list(user: user, per_page: 100)
|
102
|
-
etag ghresponse.headers.etag
|
103
|
-
body serialize(ghresponse)
|
104
|
-
end
|
105
|
-
|
106
|
-
# => Get Branch/Tag Names
|
107
|
-
get '/revisions/:user/:repo' do |user, repo|
|
108
|
-
branches = ghclient.repos.branches(user: user, repo: repo)
|
109
|
-
tags = ghclient.repos.tags(user: user, repo: repo)
|
110
|
-
body serialize_revisions(branches, tags)
|
111
|
-
end
|
112
|
-
|
113
|
-
# => Compare Branch/Tags
|
114
|
-
get '/compare/:user/:repo' do |user, repo|
|
115
|
-
# => Check Parameters - Default to Master
|
116
|
-
refs = [
|
117
|
-
{ 'target' => params['ref1'] || 'master' },
|
118
|
-
{ 'target' => params['ref2'] || 'master' }
|
119
|
-
]
|
120
|
-
|
121
|
-
begin
|
122
|
-
refs.each do |ref|
|
123
|
-
# => Pull the SHA
|
124
|
-
ref['sha'] = ghclient.git_data.trees.get(user, repo, ref['target']).first[1]
|
125
|
-
end
|
126
|
-
|
127
|
-
if refs[0]['sha'] == refs[1]['sha']
|
128
|
-
return "ref1(#{user}/#{repo}/#{refs[0]['target']}) is the same as ref2(#{user}/#{repo}/#{refs[1]['target']})".to_json
|
129
|
-
else
|
130
|
-
status 500 unless params['errorok'] == '1'
|
131
|
-
return "ALERT!!! - ref1(#{user}/#{repo}/#{refs[0]['target']}) is different than ref2(#{user}/#{repo}/#{refs[1]['target']})".to_json
|
132
|
-
end
|
133
|
-
|
134
|
-
# => Catch any GitHub Errors
|
135
|
-
rescue Github::Error::GithubError => e
|
136
|
-
status 500 unless params['errorok'] == '1'
|
137
|
-
e.message.to_json
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
8
|
+
# => GitHub RunDeck Options Provider API
|
9
|
+
module GithubRunDeck
|
10
|
+
# => The Sinatra API should be Lazily-Loaded, such that the CLI arguments and/or configuration files are respected
|
11
|
+
autoload :API, 'github-rundeck/api'
|
141
12
|
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
# Encoding: UTF-8
|
2
|
+
# rubocop: disable LineLength
|
3
|
+
#
|
4
|
+
# Gem Name:: github-rundeck
|
5
|
+
# GithubRunDeck:: API
|
6
|
+
#
|
7
|
+
# Copyright (C) 2017 Brian Dwyer - Intelligent Digital Services
|
8
|
+
#
|
9
|
+
# All rights reserved - Do Not Redistribute
|
10
|
+
#
|
11
|
+
|
12
|
+
# => NOTE: Anything other than a STATUS 200 will trigger an error in the RunDeck plugin due to a hardcode in org.boon.HTTP
|
13
|
+
|
14
|
+
require 'sinatra/base'
|
15
|
+
require 'sinatra/namespace'
|
16
|
+
require 'json'
|
17
|
+
require 'rack/cache'
|
18
|
+
require 'github-rundeck/config'
|
19
|
+
require 'github-rundeck/git'
|
20
|
+
require 'github-rundeck/util'
|
21
|
+
|
22
|
+
# => Deployment Information Provider for RunDeck
|
23
|
+
module GithubRunDeck
|
24
|
+
# => HTTP API
|
25
|
+
class API < Sinatra::Base
|
26
|
+
#######################
|
27
|
+
# => Sinatra <= #
|
28
|
+
#######################
|
29
|
+
|
30
|
+
# => Configure Sinatra
|
31
|
+
enable :logging, :static, :raise_errors # => disable :dump_errors, :show_exceptions
|
32
|
+
set :port, Config.port || 8080
|
33
|
+
set :bind, Config.bind || 'localhost'
|
34
|
+
set :environment, Config.environment.to_sym.downcase || :production
|
35
|
+
|
36
|
+
# => Enable NameSpace Support
|
37
|
+
register Sinatra::Namespace
|
38
|
+
|
39
|
+
if development?
|
40
|
+
require 'sinatra/reloader'
|
41
|
+
register Sinatra::Reloader
|
42
|
+
end
|
43
|
+
|
44
|
+
use Rack::Cache do
|
45
|
+
set :verbose, true
|
46
|
+
set :metastore, 'file:' + File.join(Dir.tmpdir, 'rack', 'meta')
|
47
|
+
set :entitystore, 'file:' + File.join(Dir.tmpdir, 'rack', 'body')
|
48
|
+
end
|
49
|
+
|
50
|
+
########################
|
51
|
+
# => JSON API <= #
|
52
|
+
########################
|
53
|
+
|
54
|
+
# => Current Configuration & Healthcheck Endpoint
|
55
|
+
if development?
|
56
|
+
get '/config' do
|
57
|
+
content_type 'application/json'
|
58
|
+
JSON.pretty_generate(
|
59
|
+
[
|
60
|
+
DeployInfo.inspect + ' is up and running!',
|
61
|
+
'Author: ' + Config.author,
|
62
|
+
'Environment: ' + Config.environment.to_s,
|
63
|
+
'Root: ' + Config.root.to_s,
|
64
|
+
'Config File: ' + (Config.config_file if File.exist?(Config.config_file)).to_s,
|
65
|
+
'Params: ' + params.inspect,
|
66
|
+
'Cache Timeout: ' + Config.cache_timeout.to_s,
|
67
|
+
{ AppConfig: Config.options },
|
68
|
+
{ 'Sinatra Info' => env }
|
69
|
+
].compact
|
70
|
+
)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
get '/state' do
|
75
|
+
content_type 'application/json'
|
76
|
+
State.state.to_json
|
77
|
+
end
|
78
|
+
|
79
|
+
########################
|
80
|
+
# => JSON API <= #
|
81
|
+
########################
|
82
|
+
|
83
|
+
namespace '/github/v1' do # rubocop: disable BlockLength
|
84
|
+
# => Define our common namespace parameters
|
85
|
+
before do
|
86
|
+
# => This is a JSON API
|
87
|
+
content_type 'application/json'
|
88
|
+
|
89
|
+
# => Make the Params Globally Accessible
|
90
|
+
Config.define_setting :query_params, params
|
91
|
+
|
92
|
+
# => Parameter Overrides
|
93
|
+
Github.configure do |cfg|
|
94
|
+
cfg.oauth_token = params['gh_oauth_token'] || Config.github_oauth_token
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# => Clean Up
|
99
|
+
after do
|
100
|
+
# => Reset the API Client to Default Values
|
101
|
+
# => Notifier.reset!
|
102
|
+
end
|
103
|
+
|
104
|
+
# => Get Organization Repo List
|
105
|
+
get '/repos/org/:org' do |org|
|
106
|
+
ghresponse = Git.repos.list(org: org, per_page: 100)
|
107
|
+
etag ghresponse.headers.etag
|
108
|
+
body Util.serialize(ghresponse)
|
109
|
+
end
|
110
|
+
|
111
|
+
# => Get User Repo List
|
112
|
+
get '/repos/user/:user' do |user|
|
113
|
+
ghresponse = Git.repos.list(user: user, per_page: 100)
|
114
|
+
etag ghresponse.headers.etag
|
115
|
+
body Util.serialize(ghresponse)
|
116
|
+
end
|
117
|
+
|
118
|
+
# => Get Branch/Tag Names
|
119
|
+
get '/revisions/:user/:repo' do |user, repo|
|
120
|
+
branches = Git.repos.branches(user: user, repo: repo, per_page: 100)
|
121
|
+
tags = Git.repos.tags(user: user, repo: repo, per_page: 100)
|
122
|
+
body Util.serialize_revisions(branches, tags)
|
123
|
+
end
|
124
|
+
|
125
|
+
# => Compare Branch/Tags
|
126
|
+
get '/compare/:user/:repo' do |user, repo|
|
127
|
+
# => Check Parameters - Default to Master
|
128
|
+
refs = [
|
129
|
+
{ 'target' => params['ref1'] || 'master' },
|
130
|
+
{ 'target' => params['ref2'] || 'master' }
|
131
|
+
]
|
132
|
+
|
133
|
+
begin
|
134
|
+
refs.each do |ref|
|
135
|
+
# => Pull the SHA
|
136
|
+
ref['sha'] = ghclient.git_data.trees.get(user, repo, ref['target']).first[1]
|
137
|
+
end
|
138
|
+
|
139
|
+
if refs[0]['sha'] == refs[1]['sha']
|
140
|
+
return "ref1(#{user}/#{repo}/#{refs[0]['target']}) is the same as ref2(#{user}/#{repo}/#{refs[1]['target']})".to_json
|
141
|
+
else
|
142
|
+
status 500 unless params['errorok'] == '1'
|
143
|
+
return "ALERT!!! - ref1(#{user}/#{repo}/#{refs[0]['target']}) is different than ref2(#{user}/#{repo}/#{refs[1]['target']})".to_json
|
144
|
+
end
|
145
|
+
|
146
|
+
# => Catch any GitHub Errors
|
147
|
+
rescue Github::Error::GithubError => e
|
148
|
+
status 500 unless params['errorok'] == '1'
|
149
|
+
e.message.to_json
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# Encoding: UTF-8
|
2
|
+
# rubocop: disable LineLength
|
3
|
+
#
|
4
|
+
# Gem Name:: github-rundeck
|
5
|
+
# GithubRunDeck:: CLI
|
6
|
+
#
|
7
|
+
# Copyright (C) 2017 Brian Dwyer - Intelligent Digital Services
|
8
|
+
#
|
9
|
+
# All rights reserved - Do Not Redistribute
|
10
|
+
#
|
11
|
+
|
12
|
+
require 'mixlib/cli'
|
13
|
+
require 'github-rundeck/config'
|
14
|
+
require 'github-rundeck/util'
|
15
|
+
|
16
|
+
module GithubRunDeck
|
17
|
+
#
|
18
|
+
# => GitHub-RunDeck Launcher
|
19
|
+
#
|
20
|
+
module CLI
|
21
|
+
module_function
|
22
|
+
|
23
|
+
#
|
24
|
+
# => Options Parser
|
25
|
+
#
|
26
|
+
class Options
|
27
|
+
# => Mix-In the CLI Option Parser
|
28
|
+
include Mixlib::CLI
|
29
|
+
|
30
|
+
option :github_oauth_token,
|
31
|
+
short: '-g TOKEN',
|
32
|
+
long: '--github-oauth-token TOKEN',
|
33
|
+
description: 'OAuth Token to use for querying GitHub'
|
34
|
+
|
35
|
+
option :cache_timeout,
|
36
|
+
short: '-t CACHE_TIMEOUT',
|
37
|
+
long: '--timeout CACHE_TIMEOUT',
|
38
|
+
description: 'Sets the cache timeout in seconds for API query response data.'
|
39
|
+
|
40
|
+
option :config_file,
|
41
|
+
short: '-c CONFIG',
|
42
|
+
long: '--config CONFIG',
|
43
|
+
description: 'The configuration file to use, as opposed to command-line parameters (optional)'
|
44
|
+
|
45
|
+
option :bind,
|
46
|
+
short: '-b HOST',
|
47
|
+
long: '--bind HOST',
|
48
|
+
description: "Listen on Interface or IP (Default: #{Config.bind})"
|
49
|
+
|
50
|
+
option :port,
|
51
|
+
short: '-p PORT',
|
52
|
+
long: '--port PORT',
|
53
|
+
description: "The port to run on. (Default: #{Config.port})"
|
54
|
+
|
55
|
+
option :environment,
|
56
|
+
short: '-e ENV',
|
57
|
+
long: '--env ENV',
|
58
|
+
description: "Sets the environment for deploy-info to execute under. Use 'development' for more logging. (Default: #{Config.environment})"
|
59
|
+
end
|
60
|
+
|
61
|
+
def configure(argv = ARGV)
|
62
|
+
# => Parse CLI Configuration
|
63
|
+
cli = Options.new
|
64
|
+
cli.parse_options(argv)
|
65
|
+
|
66
|
+
# => Parse JSON Config File (If Specified & Exists)
|
67
|
+
json_config = Util.parse_json(cli.config[:config_file] || Config.config_file)
|
68
|
+
|
69
|
+
# => Merge Configuration (CLI Wins)
|
70
|
+
config = [json_config, cli.config].compact.reduce(:merge)
|
71
|
+
|
72
|
+
# => Apply Configuration
|
73
|
+
config.each { |k, v| Config.send("#{k}=", v) }
|
74
|
+
end
|
75
|
+
|
76
|
+
# => Launch the Application
|
77
|
+
def run(argv = ARGV)
|
78
|
+
# => Parse the Params
|
79
|
+
configure(argv)
|
80
|
+
|
81
|
+
# => Launch the API
|
82
|
+
API.run!
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# Encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Gem Name:: github-rundeck
|
4
|
+
# GithubRunDeck:: Config
|
5
|
+
#
|
6
|
+
# Copyright (C) 2017 Brian Dwyer - Intelligent Digital Services
|
7
|
+
#
|
8
|
+
# All rights reserved - Do Not Redistribute
|
9
|
+
#
|
10
|
+
|
11
|
+
require 'github-rundeck/helpers/configuration'
|
12
|
+
require 'pathname'
|
13
|
+
|
14
|
+
module GithubRunDeck
|
15
|
+
# => This is the Configuration module.
|
16
|
+
module Config
|
17
|
+
module_function
|
18
|
+
|
19
|
+
extend Configuration
|
20
|
+
|
21
|
+
# => Gem Root Directory
|
22
|
+
define_setting :root, Pathname.new(File.expand_path('../../../', __FILE__))
|
23
|
+
|
24
|
+
# => My Name
|
25
|
+
define_setting :author, 'Brian Dwyer - Intelligent Digital Services'
|
26
|
+
|
27
|
+
# => Application Environment
|
28
|
+
define_setting :environment, :production
|
29
|
+
|
30
|
+
# => Sinatra Configuration
|
31
|
+
define_setting :port, '9123'
|
32
|
+
define_setting :bind, 'localhost'
|
33
|
+
define_setting :cache_timeout, 30
|
34
|
+
|
35
|
+
# => Config File
|
36
|
+
define_setting :config_file, File.join(root, 'config', 'config.json')
|
37
|
+
|
38
|
+
#
|
39
|
+
# => API Configuration
|
40
|
+
#
|
41
|
+
# => Github OAuth Token
|
42
|
+
define_setting :github_oauth_token
|
43
|
+
|
44
|
+
#
|
45
|
+
# => Facilitate Dynamic Addition of Configuration Values
|
46
|
+
#
|
47
|
+
# => @return [class_variable]
|
48
|
+
#
|
49
|
+
def add(config = {})
|
50
|
+
config.each do |key, value|
|
51
|
+
define_setting key.to_sym, value
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
#
|
56
|
+
# => Facilitate Dynamic Removal of Configuration Values
|
57
|
+
#
|
58
|
+
# => @return nil
|
59
|
+
#
|
60
|
+
def clear(config)
|
61
|
+
Array(config).each do |setting|
|
62
|
+
delete_setting setting
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
#
|
67
|
+
# => List the Configurable Keys as a Hash
|
68
|
+
#
|
69
|
+
# @return [Hash]
|
70
|
+
#
|
71
|
+
def options
|
72
|
+
map = Config.class_variables.map do |key|
|
73
|
+
[key.to_s.tr('@', '').to_sym, class_variable_get(:"#{key}")]
|
74
|
+
end
|
75
|
+
Hash[map]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# Encoding: UTF-8
|
2
|
+
# rubocop: disable LineLength
|
3
|
+
#
|
4
|
+
# Gem Name:: github-rundeck
|
5
|
+
# GithubRunDeck:: Git
|
6
|
+
#
|
7
|
+
# Copyright (C) 2017 Brian Dwyer - Intelligent Digital Services
|
8
|
+
#
|
9
|
+
# All rights reserved - Do Not Redistribute
|
10
|
+
#
|
11
|
+
|
12
|
+
require 'github-rundeck/config'
|
13
|
+
require 'github_api'
|
14
|
+
|
15
|
+
module GithubRunDeck
|
16
|
+
# => This is the Git Module. It interacts with Git resources.
|
17
|
+
module Git
|
18
|
+
extend self
|
19
|
+
|
20
|
+
def ghclient
|
21
|
+
# => Instantiate a new GitHub Client
|
22
|
+
Github::Client.new
|
23
|
+
end
|
24
|
+
|
25
|
+
def repos
|
26
|
+
ghclient.repos
|
27
|
+
end
|
28
|
+
|
29
|
+
def tags
|
30
|
+
ghclient.tags
|
31
|
+
end
|
32
|
+
|
33
|
+
def revision # rubocop: disable AbcSize
|
34
|
+
# => Grab the Supplied Revision
|
35
|
+
rev = Config.query_params['revision'] || return
|
36
|
+
return rev unless Config.query_params['gh_repo']
|
37
|
+
|
38
|
+
# => Break down the Params
|
39
|
+
org, repo = Config.query_params['gh_repo'].split('/').map { |r| String(r) }
|
40
|
+
return rev unless org && repo
|
41
|
+
|
42
|
+
begin
|
43
|
+
# => Pull the Shorthand SHA
|
44
|
+
ghclient.git_data.trees.get(org, repo, rev).first[1][0, 7]
|
45
|
+
rescue Github::Error::NotFound
|
46
|
+
# => Return the Supplied Revision if Github Borks
|
47
|
+
rev
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# Encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Gem Name:: github-rundeck
|
4
|
+
# Helper:: Configuration
|
5
|
+
#
|
6
|
+
# Author: Eli Fatsi - https://www.viget.com/articles/easy-gem-configuration-variables-with-defaults
|
7
|
+
# Contributor: Brian Dwyer - Intelligent Digital Services
|
8
|
+
#
|
9
|
+
|
10
|
+
# => Configuration Helper Module
|
11
|
+
module Configuration
|
12
|
+
#
|
13
|
+
# => Provides a method to configure an Application
|
14
|
+
# => Example:
|
15
|
+
# DeployInfo::Config.setup do |cfg|
|
16
|
+
# cfg.config_file = 'abc.json'
|
17
|
+
# cfg.app_name = 'GemBase'
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
def setup
|
21
|
+
yield self
|
22
|
+
end
|
23
|
+
|
24
|
+
def define_setting(name, default = nil)
|
25
|
+
class_variable_set("@@#{name}", default)
|
26
|
+
|
27
|
+
define_class_method "#{name}=" do |value|
|
28
|
+
class_variable_set("@@#{name}", value)
|
29
|
+
end
|
30
|
+
|
31
|
+
define_class_method name do
|
32
|
+
class_variable_get("@@#{name}")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def delete_setting(name)
|
37
|
+
remove_class_variable("@@#{name}")
|
38
|
+
|
39
|
+
delete_class_method(name)
|
40
|
+
rescue NameError # => Handle Non-Existent Settings
|
41
|
+
return
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def define_class_method(name, &block)
|
47
|
+
(class << self; self; end).instance_eval do
|
48
|
+
define_method name, &block
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def delete_class_method(name)
|
53
|
+
(class << self; self; end).instance_eval do
|
54
|
+
undef_method name
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# Encoding: UTF-8
|
2
|
+
# rubocop: disable LineLength
|
3
|
+
#
|
4
|
+
# Gem Name:: github-rundeck
|
5
|
+
# GithubRunDeck:: Util
|
6
|
+
#
|
7
|
+
# Copyright (C) 2017 Brian Dwyer - Intelligent Digital Services
|
8
|
+
#
|
9
|
+
# All rights reserved - Do Not Redistribute
|
10
|
+
#
|
11
|
+
|
12
|
+
require 'json'
|
13
|
+
|
14
|
+
module GithubRunDeck
|
15
|
+
# => Utility Methods
|
16
|
+
module Util
|
17
|
+
extend self
|
18
|
+
|
19
|
+
########################
|
20
|
+
# => File I/O <= #
|
21
|
+
########################
|
22
|
+
|
23
|
+
# => Define JSON Parser
|
24
|
+
def parse_json(file = nil, symbolize = true)
|
25
|
+
return unless file && ::File.exist?(file.to_s)
|
26
|
+
begin
|
27
|
+
::JSON.parse(::File.read(file.to_s), symbolize_names: symbolize)
|
28
|
+
rescue JSON::ParserError
|
29
|
+
return
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# => Define JSON Writer
|
34
|
+
def write_json(file, object)
|
35
|
+
return unless file && object
|
36
|
+
begin
|
37
|
+
File.open(file, 'w') { |f| f.write(JSON.pretty_generate(object)) }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
#############################
|
42
|
+
# => Serialization <= #
|
43
|
+
#############################
|
44
|
+
|
45
|
+
def serialize(response)
|
46
|
+
# => Serialize Object into JSON Array
|
47
|
+
JSON.pretty_generate(response.map(&:name).sort_by(&:downcase))
|
48
|
+
end
|
49
|
+
|
50
|
+
def serialize_csv(csv)
|
51
|
+
# => Serialize a CSV String into an Array
|
52
|
+
return unless csv && csv.is_a?(String)
|
53
|
+
csv.split(',')
|
54
|
+
end
|
55
|
+
|
56
|
+
def serialize_revisions(branches, tags)
|
57
|
+
# => Serialize Branches/Tags into JSON Array
|
58
|
+
# => Branches = String, Tags = Key/Value
|
59
|
+
branches = branches.map(&:name).sort_by(&:downcase)
|
60
|
+
tags = tags.map(&:name).sort_by(&:downcase).reverse.map { |tag| { name: "Tag: #{tag}", value: tag } }
|
61
|
+
JSON.pretty_generate(branches + tags)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: github-rundeck
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Dwyer
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: github_api
|
@@ -154,10 +154,17 @@ files:
|
|
154
154
|
- Rakefile
|
155
155
|
- bin/console
|
156
156
|
- bin/setup
|
157
|
-
- config.json
|
157
|
+
- config/config.json
|
158
158
|
- exe/github-rundeck
|
159
159
|
- github-rundeck.gemspec
|
160
160
|
- lib/github-rundeck.rb
|
161
|
+
- lib/github-rundeck/api.rb
|
162
|
+
- lib/github-rundeck/cli.rb
|
163
|
+
- lib/github-rundeck/config.rb
|
164
|
+
- lib/github-rundeck/git.rb
|
165
|
+
- lib/github-rundeck/helpers/configuration.rb
|
166
|
+
- lib/github-rundeck/util.rb
|
167
|
+
- lib/github-rundeck/version.rb
|
161
168
|
homepage: https://github.com/bdwyertech/github-rundeck
|
162
169
|
licenses:
|
163
170
|
- MIT
|
@@ -179,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
179
186
|
version: '0'
|
180
187
|
requirements: []
|
181
188
|
rubyforge_project:
|
182
|
-
rubygems_version: 2.6.
|
189
|
+
rubygems_version: 2.6.12
|
183
190
|
signing_key:
|
184
191
|
specification_version: 4
|
185
192
|
summary: Github Options Provider for RunDeck
|