git-semaphore 0.0.9 → 1.0.0

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.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +9 -19
  3. data/.pryrc +6 -0
  4. data/.ruby-version +1 -1
  5. data/CODE_OF_CONDUCT.md +49 -0
  6. data/LICENSE.txt +17 -18
  7. data/README.md +166 -40
  8. data/Rakefile +8 -9
  9. data/bin/console +14 -0
  10. data/bin/setup +10 -0
  11. data/exe/git-semaphore +79 -0
  12. data/git-semaphore.gemspec +15 -19
  13. data/lib/git/semaphore/api.rb +133 -0
  14. data/lib/git/semaphore/api_cache.rb +59 -0
  15. data/lib/git/semaphore/api_enrich.rb +40 -0
  16. data/lib/git/semaphore/app.rb +121 -0
  17. data/lib/{git-semaphore → git/semaphore}/banner.rb +0 -0
  18. data/lib/{git-semaphore → git/semaphore}/copyright.rb +1 -1
  19. data/lib/{git-semaphore → git/semaphore}/version.rb +1 -1
  20. data/lib/git/semaphore.rb +77 -0
  21. metadata +55 -181
  22. data/.bundle/config +0 -3
  23. data/.irbrc +0 -13
  24. data/bin/git-semaphore +0 -115
  25. data/features/cassettes/cucumber_tags/api_branch_status.json +0 -20
  26. data/features/cassettes/cucumber_tags/api_project_branches.json +0 -14
  27. data/features/cassettes/cucumber_tags/api_projects.json +0 -46
  28. data/features/cassettes/cucumber_tags/vcr_api_branches.yml +0 -70
  29. data/features/cassettes/cucumber_tags/vcr_api_projects.yml +0 -102
  30. data/features/cassettes/cucumber_tags/vcr_api_rebuild_last_revision.yml +0 -55
  31. data/features/cassettes/cucumber_tags/vcr_api_status.yml +0 -76
  32. data/features/coming_soon.feature +0 -13
  33. data/features/env_config.feature +0 -11
  34. data/features/git_config.feature +0 -11
  35. data/features/help_and_version.feature +0 -33
  36. data/features/semaphore_app_api.feature +0 -29
  37. data/features/semaphore_app_config.feature +0 -37
  38. data/features/semaphore_auth_token.feature +0 -32
  39. data/features/semaphore_project_token.feature +0 -32
  40. data/features/step_definitions/git-semaphore_steps.rb +0 -121
  41. data/features/step_definitions/patch_methadone_steps.rb +0 -5
  42. data/features/step_definitions/vcr_semaphore_steps.rb +0 -25
  43. data/features/support/env.rb +0 -7
  44. data/features/support/semaphoreapp.rb +0 -2
  45. data/features/support/vcr.rb +0 -14
  46. data/features/working_directory.feature +0 -22
  47. data/lib/git-semaphore/api.rb +0 -60
  48. data/lib/git-semaphore/app.rb +0 -123
  49. data/lib/git-semaphore.rb +0 -15
  50. data/spec_helper.rb +0 -6
  51. data/vendor/bundle/.gitignore +0 -2
@@ -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
@@ -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
@@ -1,6 +0,0 @@
1
- $:.unshift File.realpath File.join(File.dirname(__FILE__), '..', 'lib')
2
-
3
- require 'git-command'
4
-
5
- require 'pry'
6
- require 'awesome_print'
@@ -1,2 +0,0 @@
1
- *
2
- !.gitignore