git-semaphore 0.0.9 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +9 -19
- data/.pryrc +6 -0
- data/.ruby-version +1 -1
- data/CODE_OF_CONDUCT.md +49 -0
- data/LICENSE.txt +17 -18
- data/README.md +166 -40
- data/Rakefile +8 -9
- data/bin/console +14 -0
- data/bin/setup +10 -0
- data/exe/git-semaphore +79 -0
- data/git-semaphore.gemspec +15 -19
- data/lib/git/semaphore/api.rb +133 -0
- data/lib/git/semaphore/api_cache.rb +59 -0
- data/lib/git/semaphore/api_enrich.rb +40 -0
- data/lib/git/semaphore/app.rb +121 -0
- data/lib/{git-semaphore → git/semaphore}/banner.rb +0 -0
- data/lib/{git-semaphore → git/semaphore}/copyright.rb +1 -1
- data/lib/{git-semaphore → git/semaphore}/version.rb +1 -1
- data/lib/git/semaphore.rb +77 -0
- metadata +55 -181
- data/.bundle/config +0 -3
- data/.irbrc +0 -13
- data/bin/git-semaphore +0 -115
- data/features/cassettes/cucumber_tags/api_branch_status.json +0 -20
- data/features/cassettes/cucumber_tags/api_project_branches.json +0 -14
- data/features/cassettes/cucumber_tags/api_projects.json +0 -46
- data/features/cassettes/cucumber_tags/vcr_api_branches.yml +0 -70
- data/features/cassettes/cucumber_tags/vcr_api_projects.yml +0 -102
- data/features/cassettes/cucumber_tags/vcr_api_rebuild_last_revision.yml +0 -55
- data/features/cassettes/cucumber_tags/vcr_api_status.yml +0 -76
- data/features/coming_soon.feature +0 -13
- data/features/env_config.feature +0 -11
- data/features/git_config.feature +0 -11
- data/features/help_and_version.feature +0 -33
- data/features/semaphore_app_api.feature +0 -29
- data/features/semaphore_app_config.feature +0 -37
- data/features/semaphore_auth_token.feature +0 -32
- data/features/semaphore_project_token.feature +0 -32
- data/features/step_definitions/git-semaphore_steps.rb +0 -121
- data/features/step_definitions/patch_methadone_steps.rb +0 -5
- data/features/step_definitions/vcr_semaphore_steps.rb +0 -25
- data/features/support/env.rb +0 -7
- data/features/support/semaphoreapp.rb +0 -2
- data/features/support/vcr.rb +0 -14
- data/features/working_directory.feature +0 -22
- data/lib/git-semaphore/api.rb +0 -60
- data/lib/git-semaphore/app.rb +0 -123
- data/lib/git-semaphore.rb +0 -15
- data/spec_helper.rb +0 -6
- data/vendor/bundle/.gitignore +0 -2
data/lib/git-semaphore/api.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'uri'
|
2
|
-
require 'net/http'
|
3
|
-
require 'openssl'
|
4
|
-
|
5
|
-
module Git
|
6
|
-
module Semaphore
|
7
|
-
class Api
|
8
|
-
|
9
|
-
# https://semaphoreci.com/docs/
|
10
|
-
|
11
|
-
SEMAPHORE_API_HOST = 'semaphoreci.com'
|
12
|
-
SEMAPHORE_API_URI = '/api/v1'
|
13
|
-
|
14
|
-
def self.projects_uri auth_token
|
15
|
-
request_uri(auth_token, :path => File.join(SEMAPHORE_API_URI, 'projects'))
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.branches_uri project_hash_id, auth_token
|
19
|
-
request_uri(auth_token, :path => File.join(SEMAPHORE_API_URI, 'projects', project_hash_id, 'branches'))
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.status_uri project_hash_id, branch_id, auth_token
|
23
|
-
request_uri(auth_token, :path => File.join(SEMAPHORE_API_URI, 'projects', project_hash_id, branch_id, 'status'))
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.history_uri project_hash_id, branch_id, auth_token
|
27
|
-
request_uri(auth_token, :path => File.join(SEMAPHORE_API_URI, 'projects', project_hash_id, branch_id))
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.last_revision_uri project_hash_id, branch_id, auth_token
|
31
|
-
request_uri(auth_token, :path => File.join(SEMAPHORE_API_URI, 'projects', project_hash_id, branch_id, 'build'))
|
32
|
-
end
|
33
|
-
|
34
|
-
# helper functions
|
35
|
-
|
36
|
-
def self.get_response uri, action=:get
|
37
|
-
::Net::HTTP.start(uri.host, uri.port, :use_ssl => (uri.scheme == 'https'), :verify_mode => ::OpenSSL::SSL::VERIFY_NONE) do |net_http|
|
38
|
-
case action
|
39
|
-
when :get
|
40
|
-
net_http.get uri.request_uri
|
41
|
-
when :post
|
42
|
-
net_http.post uri.request_uri, uri.query
|
43
|
-
else
|
44
|
-
raise 'Unsupported action'
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.request_uri auth_token, options={}
|
50
|
-
URI::HTTPS.build(
|
51
|
-
{ :host => SEMAPHORE_API_HOST,
|
52
|
-
:query => "auth_token=#{auth_token}"
|
53
|
-
}.merge(options)
|
54
|
-
)
|
55
|
-
end
|
56
|
-
private_class_method(:request_uri)
|
57
|
-
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
data/lib/git-semaphore/app.rb
DELETED
@@ -1,123 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
|
3
|
-
class Git::Semaphore::App
|
4
|
-
|
5
|
-
attr_accessor :env_auth_token
|
6
|
-
attr_accessor :env_project_token
|
7
|
-
|
8
|
-
attr_accessor :working_dir
|
9
|
-
attr_writer :branch_name
|
10
|
-
attr_accessor :commit
|
11
|
-
attr_writer :project_name
|
12
|
-
|
13
|
-
def initialize working_dir, config = ENV
|
14
|
-
self.working_dir = working_dir
|
15
|
-
|
16
|
-
self.project_name = config['PROJECT']
|
17
|
-
self.branch_name = config['BRANCH']
|
18
|
-
self.commit = config['COMMIT']
|
19
|
-
|
20
|
-
self.env_auth_token = config['SEMAPHORE_AUTH_TOKEN']
|
21
|
-
self.env_project_token = config['SEMAPHORE_PROJECT_TOKEN']
|
22
|
-
end
|
23
|
-
|
24
|
-
def git_auth_token
|
25
|
-
git_repo.config['semaphore.authtoken']
|
26
|
-
end
|
27
|
-
|
28
|
-
def git_project_token
|
29
|
-
git_repo.config['semaphore.projecttoken']
|
30
|
-
end
|
31
|
-
|
32
|
-
def git_repo
|
33
|
-
@git_repo ||= Grit::Repo.new(working_dir)
|
34
|
-
end
|
35
|
-
|
36
|
-
def validate
|
37
|
-
'' != branch_name.to_s.gsub(/\s+/, '')
|
38
|
-
rescue
|
39
|
-
false
|
40
|
-
end
|
41
|
-
|
42
|
-
def auth_token
|
43
|
-
git_auth_token || env_auth_token
|
44
|
-
end
|
45
|
-
|
46
|
-
def project_token
|
47
|
-
git_project_token || env_project_token
|
48
|
-
end
|
49
|
-
|
50
|
-
def project_name
|
51
|
-
return @project_name unless @project_name.nil?
|
52
|
-
File.basename working_dir
|
53
|
-
end
|
54
|
-
|
55
|
-
def branch_name
|
56
|
-
return @branch_name unless @branch_name.nil?
|
57
|
-
git_repo.head.name
|
58
|
-
end
|
59
|
-
|
60
|
-
def projects
|
61
|
-
@projects ||= begin
|
62
|
-
uri = Git::Semaphore::Api.projects_uri(auth_token)
|
63
|
-
Git::Semaphore::Api.get_response(uri).body
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def branches
|
68
|
-
@branches ||= begin
|
69
|
-
uri = Git::Semaphore::Api.branches_uri(project_hash_id, auth_token)
|
70
|
-
Git::Semaphore::Api.get_response(uri).body
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def status
|
75
|
-
@status ||= begin
|
76
|
-
uri = Git::Semaphore::Api.status_uri(project_hash_id, branch_id, auth_token)
|
77
|
-
Git::Semaphore::Api.get_response(uri).body
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def commit_status
|
82
|
-
uri = Git::Semaphore::Api.history_uri(project_hash_id, branch_id, auth_token)
|
83
|
-
j = Git::Semaphore::Api.get_response(uri).body
|
84
|
-
builds = JSON.parse(j)['builds']
|
85
|
-
build = builds.detect { |b| b['commit']['id'] == commit }
|
86
|
-
end
|
87
|
-
|
88
|
-
def rebuild_last_revision
|
89
|
-
uri = Git::Semaphore::Api.last_revision_uri(project_hash_id, branch_id, auth_token)
|
90
|
-
Git::Semaphore::Api.get_response(uri, :post).body
|
91
|
-
end
|
92
|
-
|
93
|
-
private
|
94
|
-
|
95
|
-
def project_hash_for project_name
|
96
|
-
JSON::parse(projects).find { |project_hash|
|
97
|
-
project_hash['name'] == project_name
|
98
|
-
}
|
99
|
-
end
|
100
|
-
|
101
|
-
def project_hash_id_for project_name
|
102
|
-
project_hash_for(project_name)['hash_id']
|
103
|
-
end
|
104
|
-
|
105
|
-
def project_hash_id
|
106
|
-
project_hash_id_for(project_name)
|
107
|
-
end
|
108
|
-
|
109
|
-
def branch_hash_for branch_name
|
110
|
-
JSON::parse(branches).find { |branch_hash|
|
111
|
-
branch_hash['name'] == branch_name
|
112
|
-
}
|
113
|
-
end
|
114
|
-
|
115
|
-
def branch_id_for branch_name
|
116
|
-
branch_hash_for(branch_name)['id']
|
117
|
-
end
|
118
|
-
|
119
|
-
def branch_id
|
120
|
-
branch_id_for(branch_name).to_s
|
121
|
-
end
|
122
|
-
|
123
|
-
end
|
data/lib/git-semaphore.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'grit'
|
2
|
-
require 'trollop'
|
3
|
-
|
4
|
-
require 'git-semaphore/version'
|
5
|
-
require 'git-semaphore/banner'
|
6
|
-
require 'git-semaphore/copyright'
|
7
|
-
|
8
|
-
require 'git-semaphore/app'
|
9
|
-
require 'git-semaphore/api'
|
10
|
-
|
11
|
-
module Git
|
12
|
-
module Semaphore
|
13
|
-
# Your code goes here...
|
14
|
-
end
|
15
|
-
end
|
data/spec_helper.rb
DELETED
data/vendor/bundle/.gitignore
DELETED