git-semaphore 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.irbrc +13 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/Guardfile +15 -0
- data/LICENSE.txt +22 -0
- data/README.md +82 -0
- data/Rakefile +20 -0
- data/bin/git-semaphore +114 -0
- data/features/cassettes/cucumber_tags/api_branch_status.json +20 -0
- data/features/cassettes/cucumber_tags/api_project_branches.json +14 -0
- data/features/cassettes/cucumber_tags/api_projects.json +46 -0
- data/features/cassettes/cucumber_tags/vcr_api_branches.yml +70 -0
- data/features/cassettes/cucumber_tags/vcr_api_projects.yml +102 -0
- data/features/cassettes/cucumber_tags/vcr_api_status.yml +76 -0
- data/features/coming_soon.feature +13 -0
- data/features/env_config.feature +11 -0
- data/features/git_config.feature +11 -0
- data/features/help_and_version.feature +31 -0
- data/features/semaphore_app_api.feature +22 -0
- data/features/semaphore_app_config.feature +37 -0
- data/features/semaphore_auth_token.feature +32 -0
- data/features/semaphore_project_token.feature +32 -0
- data/features/step_definitions/git-semaphore_steps.rb +121 -0
- data/features/step_definitions/vcr_semaphore_steps.rb +21 -0
- data/features/support/env.rb +8 -0
- data/features/support/semaphoreapp.rb +2 -0
- data/features/support/vcr.rb +13 -0
- data/features/working_directory.feature +22 -0
- data/git-semaphore.gemspec +40 -0
- data/lib/git-semaphore/api.rb +55 -0
- data/lib/git-semaphore/app.rb +118 -0
- data/lib/git-semaphore/banner.rb +13 -0
- data/lib/git-semaphore/copyright.rb +6 -0
- data/lib/git-semaphore/version.rb +5 -0
- data/lib/git-semaphore.rb +17 -0
- data/spec_helper.rb +6 -0
- metadata +367 -0
@@ -0,0 +1,11 @@
|
|
1
|
+
Feature: Configuration, Configuration, Configuration
|
2
|
+
|
3
|
+
Scenario: run the main script with tokens set in the git configuration
|
4
|
+
|
5
|
+
Given a git repo in directory "blegga" with config:
|
6
|
+
| semaphore.authtoken | foo |
|
7
|
+
| semaphore.projecttoken | bar |
|
8
|
+
When I run `git-semaphore --git-config` in "blegga" directory
|
9
|
+
Then the exit status should be 0
|
10
|
+
And the output should match /git config --local --replace-all semaphore.authtoken "foo"/
|
11
|
+
And the output should match /git config --local --replace-all semaphore.projecttoken "bar"/
|
@@ -0,0 +1,31 @@
|
|
1
|
+
Feature: Help Me I've Got Versionitis
|
2
|
+
|
3
|
+
Scenario: get help for the main script
|
4
|
+
|
5
|
+
When I get help for "git-semaphore"
|
6
|
+
Then the exit status should be 0
|
7
|
+
And the banner should be present
|
8
|
+
And the banner should include the version
|
9
|
+
And the banner should document that this app takes options
|
10
|
+
And the following options should be documented:
|
11
|
+
| --version, -v: |
|
12
|
+
| --help, -h: |
|
13
|
+
| --working-dir, -w: |
|
14
|
+
| --project-name, -p: |
|
15
|
+
| --branch-name, -b: |
|
16
|
+
| --check-auth, -x: |
|
17
|
+
| --check-project, -y: |
|
18
|
+
| --check-branch, -z: |
|
19
|
+
| --env-config, -e: |
|
20
|
+
| --git-config, -g: |
|
21
|
+
| --projects, -r: |
|
22
|
+
| --branches, -a: |
|
23
|
+
| --status, -s: |
|
24
|
+
|
25
|
+
Scenario: get the version of the main script
|
26
|
+
|
27
|
+
When I get the version of "git-semaphore"
|
28
|
+
Then the exit status should be 0
|
29
|
+
And the output should include the version
|
30
|
+
And the output should include the app name
|
31
|
+
And the output should include a copyright notice
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Feature: Show Me What You've Got
|
2
|
+
|
3
|
+
@vcr_api_projects
|
4
|
+
Scenario: user's projects
|
5
|
+
|
6
|
+
Given I am an authenticated user on semaphoreapp.com
|
7
|
+
And get the list of all my projects via their API
|
8
|
+
Then the JSON should be an array
|
9
|
+
|
10
|
+
@vcr_api_branches
|
11
|
+
Scenario: project's branches
|
12
|
+
|
13
|
+
Given I am an authenticated user on semaphoreapp.com
|
14
|
+
And get the list of all the branches for one of my projects via their API
|
15
|
+
Then the JSON should be an array
|
16
|
+
|
17
|
+
@vcr_api_status
|
18
|
+
Scenario: branch status
|
19
|
+
|
20
|
+
Given I am an authenticated user on semaphoreapp.com
|
21
|
+
And get the build status of one of the branches for one of my projects via their API
|
22
|
+
Then the JSON should be a hash
|
@@ -0,0 +1,37 @@
|
|
1
|
+
Feature: Configuration, Configuration, Configuration
|
2
|
+
|
3
|
+
Scenario: create an app instance inside a git repo without config
|
4
|
+
|
5
|
+
Given a git repo in directory "blegga"
|
6
|
+
And the "SEMAPHORE_AUTH_TOKEN" env variable is not set
|
7
|
+
And the "SEMAPHORE_PROJECT_TOKEN" env variable is not set
|
8
|
+
Then the application doesn't have an auth token
|
9
|
+
And the application doesn't have a project token
|
10
|
+
|
11
|
+
Scenario: create an app instance inside a git repo with config
|
12
|
+
|
13
|
+
Given a git repo in directory "blegga" with config:
|
14
|
+
| semaphore.authtoken | foo |
|
15
|
+
| semaphore.projecttoken | bar |
|
16
|
+
Then the application uses "foo" as the auth token
|
17
|
+
And the application uses "bar" as the project token
|
18
|
+
|
19
|
+
Scenario: create an app instance inside a git repo without config
|
20
|
+
|
21
|
+
Given a git repo in directory "blegga"
|
22
|
+
And a runtime environment with config:
|
23
|
+
| SEMAPHORE_AUTH_TOKEN | foofoo |
|
24
|
+
| SEMAPHORE_PROJECT_TOKEN | barbar |
|
25
|
+
Then the application uses "foofoo" as the auth token
|
26
|
+
And the application uses "barbar" as the project token
|
27
|
+
|
28
|
+
Scenario: create an app instance inside a git repo with config
|
29
|
+
|
30
|
+
Given a git repo in directory "blegga" with config:
|
31
|
+
| semaphore.authtoken | foo |
|
32
|
+
| semaphore.projecttoken | bar |
|
33
|
+
And a runtime environment with config:
|
34
|
+
| SEMAPHORE_AUTH_TOKEN | foofoo |
|
35
|
+
| SEMAPHORE_PROJECT_TOKEN | barbar |
|
36
|
+
Then the application uses "foo" as the auth token
|
37
|
+
And the application uses "bar" as the project token
|
@@ -0,0 +1,32 @@
|
|
1
|
+
Feature: How to Overcome Your Fear of Authority
|
2
|
+
|
3
|
+
Scenario: run the main script with the auth token set in the env
|
4
|
+
|
5
|
+
Given the "SEMAPHORE_AUTH_TOKEN" env variable is set
|
6
|
+
When I run `git-semaphore --check-auth` in a git working dir
|
7
|
+
Then the exit status should be 0
|
8
|
+
And the stderr should contain exactly:
|
9
|
+
"""
|
10
|
+
"""
|
11
|
+
|
12
|
+
Scenario: run the main script with the auth token set in git config
|
13
|
+
|
14
|
+
Given "semaphore.authtoken" git config is set for git repo "blegga"
|
15
|
+
When I run `git-semaphore --check-auth` in "blegga" directory
|
16
|
+
Then the exit status should be 0
|
17
|
+
And the stderr should contain exactly:
|
18
|
+
"""
|
19
|
+
"""
|
20
|
+
|
21
|
+
Scenario: run the main script with the auth token not set in the env
|
22
|
+
|
23
|
+
Given the "SEMAPHORE_AUTH_TOKEN" env variable is not set
|
24
|
+
And "semaphore.authtoken" git config is not set for git repo "blegga"
|
25
|
+
When I run `git-semaphore --check-auth` in "blegga" directory
|
26
|
+
Then the exit status should be 255
|
27
|
+
And the stderr should contain exactly:
|
28
|
+
"""
|
29
|
+
Please set - and export - the SEMAPHORE_AUTH_TOKEN env variable
|
30
|
+
Alternatively, set semaphore.authtoken in your local git config
|
31
|
+
|
32
|
+
"""
|
@@ -0,0 +1,32 @@
|
|
1
|
+
Feature: Always Carry Identification Wherever You Go
|
2
|
+
|
3
|
+
Scenario: run the main script with the project token set in the env
|
4
|
+
|
5
|
+
Given the "SEMAPHORE_PROJECT_TOKEN" env variable is set
|
6
|
+
When I run `git-semaphore --check-project` in a git working dir
|
7
|
+
Then the exit status should be 0
|
8
|
+
And the stderr should contain exactly:
|
9
|
+
"""
|
10
|
+
"""
|
11
|
+
|
12
|
+
Scenario: run the main script with the project token set in git config
|
13
|
+
|
14
|
+
Given "semaphore.projecttoken" git config is set for git repo "blegga"
|
15
|
+
When I run `git-semaphore --check-project` in "blegga" directory
|
16
|
+
Then the exit status should be 0
|
17
|
+
And the stderr should contain exactly:
|
18
|
+
"""
|
19
|
+
"""
|
20
|
+
|
21
|
+
Scenario: run the main script with the project token not set in the env
|
22
|
+
|
23
|
+
Given the "SEMAPHORE_PROJECT_TOKEN" env variable is not set
|
24
|
+
And "semaphore.projecttoken" git config is not set for git repo "blegga"
|
25
|
+
When I run `git-semaphore --check-project` in "blegga" directory
|
26
|
+
Then the exit status should be 255
|
27
|
+
And the stderr should contain exactly:
|
28
|
+
"""
|
29
|
+
Please set - and export - the SEMAPHORE_PROJECT_TOKEN env variable
|
30
|
+
Alternatively, set semaphore.projecttoken in your local git config
|
31
|
+
|
32
|
+
"""
|
@@ -0,0 +1,121 @@
|
|
1
|
+
#
|
2
|
+
# Steps that interact with ENV
|
3
|
+
#
|
4
|
+
|
5
|
+
Before do
|
6
|
+
set_env('SEMAPHORE_AUTH_TOKEN', nil)
|
7
|
+
set_env('SEMAPHORE_PROJECT_TOKEN', nil)
|
8
|
+
end
|
9
|
+
|
10
|
+
After do
|
11
|
+
restore_env
|
12
|
+
end
|
13
|
+
|
14
|
+
Given /^the "([A-Z_]+)" env variable is set(?: to "([^"]*)")?$/ do |key, value|
|
15
|
+
set_env(key, value || 'blegga')
|
16
|
+
end
|
17
|
+
|
18
|
+
Given /^the "([A-Z_]+)" env variable is not set$/ do |key|
|
19
|
+
set_env(key, nil)
|
20
|
+
end
|
21
|
+
|
22
|
+
Given /^a runtime environment with config:$/ do |config_table|
|
23
|
+
config_table.rows_hash.each do |key, value|
|
24
|
+
set_env(key, value)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
#
|
29
|
+
# Steps that interact with git
|
30
|
+
#
|
31
|
+
|
32
|
+
Given /^a git repo in directory "([^"]*)"$/ do |project_name|
|
33
|
+
@pwd = File.join(current_dir, project_name)
|
34
|
+
@repo = Grit::Repo.init(@pwd)
|
35
|
+
end
|
36
|
+
|
37
|
+
Given /^a git repo in directory "([^"]*)" with config:$/ do |project_name, config_table|
|
38
|
+
step %(a git repo in directory "#{project_name}")
|
39
|
+
config_table.rows_hash.each do |key, value|
|
40
|
+
@repo.config[key] = value
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
Given /^"([^"]*)" git config is (not set|set) for git repo "([^"]*)"$/ do |key, is_or_isnt_set, project_name|
|
45
|
+
step %(a git repo in directory "#{project_name}")
|
46
|
+
@repo.config[key] = 'blegga' unless is_or_isnt_set == "not set"
|
47
|
+
end
|
48
|
+
|
49
|
+
#
|
50
|
+
# Steps that interact with Dir.pwd
|
51
|
+
#
|
52
|
+
|
53
|
+
When /^I run `([^`]*)` in a git working dir$/ do |cmd|
|
54
|
+
working_dir = "foo/bar/qux_blegga"
|
55
|
+
step %(a git repo in directory "#{working_dir}")
|
56
|
+
step %(I run `#{cmd}` in "#{working_dir}" directory)
|
57
|
+
end
|
58
|
+
|
59
|
+
When /^I run `([^`]*)` in "([^"]*)" directory$/ do |cmd, working_dir|
|
60
|
+
step %(a directory named "#{working_dir}")
|
61
|
+
cd working_dir
|
62
|
+
step %(I run `#{cmd}`)
|
63
|
+
@dirs = ['tmp', 'aruba'] # reset Aruba::API.current_dir
|
64
|
+
end
|
65
|
+
|
66
|
+
#
|
67
|
+
# Methodane/Aruba "extensions"/"customizations"
|
68
|
+
#
|
69
|
+
|
70
|
+
When /^I get the version of "([^"]*)"$/ do |app_name|
|
71
|
+
@app_name = app_name
|
72
|
+
step %(I run `#{app_name} --version`)
|
73
|
+
end
|
74
|
+
|
75
|
+
Then /^the output should include the version$/ do
|
76
|
+
step %(the output should match /v\\d+\\.\\d+\\.\\d+/)
|
77
|
+
end
|
78
|
+
|
79
|
+
Then /^the output should include the app name$/ do
|
80
|
+
step %(the output should match /#{Regexp.escape(@app_name)}/)
|
81
|
+
end
|
82
|
+
|
83
|
+
Then /^the output should include a copyright notice$/ do
|
84
|
+
step %(the output should match /Copyright \\(c\\) [\\d]{4} [[\\w]+]+/)
|
85
|
+
end
|
86
|
+
|
87
|
+
#
|
88
|
+
# Steps that check config expectations
|
89
|
+
#
|
90
|
+
|
91
|
+
# Then /^the application uses "([^"]+)" as the git auth token$/ do |auth_token|
|
92
|
+
# (@app || Git::Semaphore::App.new(@repo, ENV)).git_auth_token.should eq auth_token
|
93
|
+
# end
|
94
|
+
|
95
|
+
# Then /^the application uses "([^"]+)" as the git project token$/ do |project_token|
|
96
|
+
# (@app || Git::Semaphore::App.new(@repo, ENV)).git_project_token.should eq project_token
|
97
|
+
# end
|
98
|
+
|
99
|
+
# Then /^the application uses "([^"]+)" as the env auth token$/ do |auth_token|
|
100
|
+
# (@app || Git::Semaphore::App.new(@repo, ENV)).env_auth_token.should eq auth_token
|
101
|
+
# end
|
102
|
+
|
103
|
+
# Then /^the application uses "([^"]+)" as the env project token$/ do |project_token|
|
104
|
+
# (@app || Git::Semaphore::App.new(@repo, ENV)).env_project_token.should eq project_token
|
105
|
+
# end
|
106
|
+
|
107
|
+
Then /^the application doesn't have an auth token$/ do
|
108
|
+
(@app || Git::Semaphore::App.new(@pwd, ENV)).auth_token.should be_nil
|
109
|
+
end
|
110
|
+
|
111
|
+
Then /^the application doesn't have a project token$/ do
|
112
|
+
(@app || Git::Semaphore::App.new(@pwd, ENV)).project_token.should be_nil
|
113
|
+
end
|
114
|
+
|
115
|
+
Then /^the application uses "([^"]+)" as the auth token$/ do |auth_token|
|
116
|
+
(@app || Git::Semaphore::App.new(@pwd, ENV)).auth_token.should eq auth_token
|
117
|
+
end
|
118
|
+
|
119
|
+
Then /^the application uses "([^"]+)" as the project token$/ do |project_token|
|
120
|
+
(@app || Git::Semaphore::App.new(@pwd, ENV)).project_token.should eq project_token
|
121
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
Given /^I am an authenticated user on semaphoreapp\.com$/ do
|
2
|
+
@auth_token = SEMAPHORE_TEST_TOKEN
|
3
|
+
@project = '649e584dc507ca4b73e1374d3125ef0b567a949c'
|
4
|
+
@branch = '89'
|
5
|
+
end
|
6
|
+
|
7
|
+
Given /^get the list of all my projects via their API$/ do
|
8
|
+
@response = Git::Semaphore::Api.get_response Git::Semaphore::Api.projects_uri(@auth_token)
|
9
|
+
end
|
10
|
+
|
11
|
+
Given /^get the list of all the branches for one of my projects via their API$/ do
|
12
|
+
@response = Git::Semaphore::Api.get_response Git::Semaphore::Api.branches_uri(@project, @auth_token)
|
13
|
+
end
|
14
|
+
|
15
|
+
Given /^get the build status of one of the branches for one of my projects via their API$/ do
|
16
|
+
@response = Git::Semaphore::Api.get_response Git::Semaphore::Api.status_uri(@project, @branch, @auth_token)
|
17
|
+
end
|
18
|
+
|
19
|
+
def last_json
|
20
|
+
@response.body
|
21
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'vcr'
|
2
|
+
|
3
|
+
VCR.configure do |c|
|
4
|
+
c.hook_into :webmock # or :fakeweb
|
5
|
+
c.cassette_library_dir = 'features/cassettes'
|
6
|
+
c.debug_logger = File.open('vcr_debug.log', 'w')
|
7
|
+
end
|
8
|
+
|
9
|
+
VCR.cucumber_tags do |t|
|
10
|
+
t.tag '@vcr_api_projects'
|
11
|
+
t.tag '@vcr_api_branches'
|
12
|
+
t.tag '@vcr_api_status'
|
13
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Feature: It's Where You Can Find Me
|
2
|
+
|
3
|
+
Scenario: print out the working directory
|
4
|
+
|
5
|
+
Given a git repo in directory "foo/bar/qux_blegga"
|
6
|
+
When I run `git-semaphore --working-dir` in "foo/bar/qux_blegga" directory
|
7
|
+
Then the exit status should be 0
|
8
|
+
And the output should contain "foo/bar"
|
9
|
+
|
10
|
+
Scenario: print out the project name
|
11
|
+
|
12
|
+
Given a git repo in directory "foo/bar/qux_blegga"
|
13
|
+
When I run `git-semaphore --project-name` in "foo/bar/qux_blegga" directory
|
14
|
+
Then the exit status should be 0
|
15
|
+
And the output should contain "qux_blegga"
|
16
|
+
|
17
|
+
Scenario: print out the branch name
|
18
|
+
|
19
|
+
Given a git repo in directory "foo/bar/qux_blegga"
|
20
|
+
When I run `git-semaphore --branch-name` in "foo/bar/qux_blegga" directory
|
21
|
+
Then the exit status should be 0
|
22
|
+
And the output should contain "master"
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'git-semaphore/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "git-semaphore"
|
8
|
+
gem.version = Git::Semaphore::VERSION
|
9
|
+
gem.authors = ["Peter Vandenberk"]
|
10
|
+
gem.email = ["pvandenberk@mac.com"]
|
11
|
+
gem.description = ["git integration with https://semaphoreapp.com"]
|
12
|
+
gem.summary = ["git integration with https://semaphoreapp.com"]
|
13
|
+
gem.homepage = "https://github.com/pvdb/git-semaphore"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency('grit')
|
21
|
+
gem.add_dependency('trollop')
|
22
|
+
|
23
|
+
gem.add_development_dependency('pry')
|
24
|
+
gem.add_development_dependency('rake')
|
25
|
+
gem.add_development_dependency('awesome_print')
|
26
|
+
gem.add_development_dependency('cucumber')
|
27
|
+
gem.add_development_dependency('rspec')
|
28
|
+
gem.add_development_dependency('aruba')
|
29
|
+
gem.add_development_dependency('methadone')
|
30
|
+
gem.add_development_dependency('guard-rspec')
|
31
|
+
gem.add_development_dependency('guard-cucumber')
|
32
|
+
gem.add_development_dependency('rb-fsevent')
|
33
|
+
gem.add_development_dependency('growl')
|
34
|
+
gem.add_development_dependency('rspec-pride')
|
35
|
+
gem.add_development_dependency('cucumber-pride')
|
36
|
+
gem.add_development_dependency('vcr')
|
37
|
+
gem.add_development_dependency('webmock')
|
38
|
+
gem.add_development_dependency('jazor')
|
39
|
+
gem.add_development_dependency('json_spec')
|
40
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
module Git
|
5
|
+
module Semaphore
|
6
|
+
class Api
|
7
|
+
|
8
|
+
# http://docs.semaphoreapp.com/api
|
9
|
+
|
10
|
+
SEMAPHORE_API_HOST = 'semaphoreapp.com'
|
11
|
+
SEMAPHORE_API_URI = '/api/v1'
|
12
|
+
|
13
|
+
def self.projects_uri auth_token
|
14
|
+
URI::HTTPS.build(
|
15
|
+
:host => SEMAPHORE_API_HOST,
|
16
|
+
:path => File.join(SEMAPHORE_API_URI, 'projects'),
|
17
|
+
:query => "auth_token=#{auth_token}"
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.branches_uri project_hash_id, auth_token
|
22
|
+
URI::HTTPS.build(
|
23
|
+
:host => SEMAPHORE_API_HOST,
|
24
|
+
:path => File.join(SEMAPHORE_API_URI, 'projects', project_hash_id, 'branches'),
|
25
|
+
:query => "auth_token=#{auth_token}"
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.status_uri project_hash_id, branch_id, auth_token
|
30
|
+
URI::HTTPS.build(
|
31
|
+
:host => SEMAPHORE_API_HOST,
|
32
|
+
:path => File.join(SEMAPHORE_API_URI, 'projects', project_hash_id, branch_id, 'status'),
|
33
|
+
:query => "auth_token=#{auth_token}"
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.history_uri project_hash_id, branch_id, auth_token
|
38
|
+
URI::HTTPS.build(
|
39
|
+
:host => SEMAPHORE_API_HOST,
|
40
|
+
:path => File.join(SEMAPHORE_API_URI, 'projects', project_hash_id, branch_id),
|
41
|
+
:query => "auth_token=#{auth_token}"
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
# helper functions
|
46
|
+
|
47
|
+
def self.get_response uri
|
48
|
+
::Net::HTTP.start(uri.host, uri.port, :use_ssl => (uri.scheme == 'https'), :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |net_http|
|
49
|
+
net_http.get(uri.request_uri)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,118 @@
|
|
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
|
+
private
|
89
|
+
|
90
|
+
def project_hash_for project_name
|
91
|
+
JSON::parse(projects).find { |project_hash|
|
92
|
+
project_hash['name'] == project_name
|
93
|
+
}
|
94
|
+
end
|
95
|
+
|
96
|
+
def project_hash_id_for project_name
|
97
|
+
project_hash_for(project_name)['hash_id']
|
98
|
+
end
|
99
|
+
|
100
|
+
def project_hash_id
|
101
|
+
project_hash_id_for(project_name)
|
102
|
+
end
|
103
|
+
|
104
|
+
def branch_hash_for branch_name
|
105
|
+
JSON::parse(branches).find { |branch_hash|
|
106
|
+
branch_hash['name'] == branch_name
|
107
|
+
}
|
108
|
+
end
|
109
|
+
|
110
|
+
def branch_id_for branch_name
|
111
|
+
branch_hash_for(branch_name)['id']
|
112
|
+
end
|
113
|
+
|
114
|
+
def branch_id
|
115
|
+
branch_id_for(branch_name).to_s
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
require 'grit'
|
4
|
+
require 'trollop'
|
5
|
+
|
6
|
+
require 'git-semaphore/version'
|
7
|
+
require 'git-semaphore/banner'
|
8
|
+
require 'git-semaphore/copyright'
|
9
|
+
|
10
|
+
require 'git-semaphore/app'
|
11
|
+
require 'git-semaphore/api'
|
12
|
+
|
13
|
+
module Git
|
14
|
+
module Semaphore
|
15
|
+
# Your code goes here...
|
16
|
+
end
|
17
|
+
end
|