perkins 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.env.example +4 -0
- data/.gitignore +19 -0
- data/.pryrc +3 -0
- data/.rspec +2 -0
- data/Gemfile +18 -0
- data/LICENSE.txt +22 -0
- data/README.md +71 -0
- data/Rakefile +28 -0
- data/TODO.md +4 -0
- data/bin/perkins +6 -0
- data/db/migrate/20150130143030_create_repo.rb +18 -0
- data/db/migrate/20150130143050_create_builds.rb +20 -0
- data/db/schema.rb +38 -0
- data/examples/config.rb +12 -0
- data/examples/database.yml +17 -0
- data/examples/mongo.yml +13 -0
- data/lib/core_ext/hash/compact.rb +8 -0
- data/lib/core_ext/hash/deep_merge.rb +15 -0
- data/lib/core_ext/hash/deep_symbolize_keys.rb +20 -0
- data/lib/core_ext/object/false.rb +5 -0
- data/lib/core_ext/string/indent.rb +5 -0
- data/lib/core_ext/string/unindent.rb +5 -0
- data/lib/perkins/.DS_Store +0 -0
- data/lib/perkins/application.rb +40 -0
- data/lib/perkins/assets/images/github.svg +4 -0
- data/lib/perkins/assets/images/spinner.svg +23 -0
- data/lib/perkins/assets/javascripts/app.js +9 -0
- data/lib/perkins/assets/javascripts/log_view.js.coffee +95 -0
- data/lib/perkins/assets/javascripts/perkings.js.coffee +40 -0
- data/lib/perkins/assets/javascripts/vendor/ansiparse.js +187 -0
- data/lib/perkins/assets/javascripts/vendor/jquery.timeago.js +189 -0
- data/lib/perkins/assets/javascripts/vendor/log.js +2 -0
- data/lib/perkins/assets/javascripts/vendor/minispade.js +55 -0
- data/lib/perkins/assets/stylesheets/app.css +2 -0
- data/lib/perkins/assets/stylesheets/log.css.scss +115 -0
- data/lib/perkins/assets/stylesheets/styles.css.scss +199 -0
- data/lib/perkins/auth/github.rb +181 -0
- data/lib/perkins/build/data/env.rb +84 -0
- data/lib/perkins/build/data/var.rb +60 -0
- data/lib/perkins/build/data.rb +167 -0
- data/lib/perkins/build/script/bundler.rb +76 -0
- data/lib/perkins/build/script/go.rb +100 -0
- data/lib/perkins/build/script/helpers.rb +39 -0
- data/lib/perkins/build/script/jdk.rb +43 -0
- data/lib/perkins/build/script/ruby.rb +31 -0
- data/lib/perkins/build/script/rvm.rb +73 -0
- data/lib/perkins/build/script/stages.rb +28 -0
- data/lib/perkins/build/script/templates/footer.sh +3 -0
- data/lib/perkins/build/script/templates/header.sh +201 -0
- data/lib/perkins/build/script/templates/xcode.sh +21 -0
- data/lib/perkins/build/script.rb +167 -0
- data/lib/perkins/build/shell/dsl.rb +104 -0
- data/lib/perkins/build/shell/node.rb +121 -0
- data/lib/perkins/build/shell.rb +16 -0
- data/lib/perkins/build.rb +27 -0
- data/lib/perkins/build_report.rb +11 -0
- data/lib/perkins/cli.rb +42 -0
- data/lib/perkins/commit.rb +30 -0
- data/lib/perkins/dsl/app_proxy.rb +23 -0
- data/lib/perkins/dsl.rb +12 -0
- data/lib/perkins/listener.rb +38 -0
- data/lib/perkins/logger.rb +12 -0
- data/lib/perkins/notifier.rb +5 -0
- data/lib/perkins/repo.rb +145 -0
- data/lib/perkins/runner.rb +124 -0
- data/lib/perkins/server.rb +314 -0
- data/lib/perkins/thor_utils.rb +79 -0
- data/lib/perkins/version.rb +3 -0
- data/lib/perkins/views/401.haml +1 -0
- data/lib/perkins/views/builds.haml +46 -0
- data/lib/perkins/views/index.haml +6 -0
- data/lib/perkins/views/layout.haml +53 -0
- data/lib/perkins/views/menu.haml +18 -0
- data/lib/perkins/views/orgs.haml +101 -0
- data/lib/perkins/views/profile.haml +31 -0
- data/lib/perkins/views/readme.md +20 -0
- data/lib/perkins/views/repos/config.haml +72 -0
- data/lib/perkins/views/repos/github.haml +76 -0
- data/lib/perkins/views/repos/menu.haml +17 -0
- data/lib/perkins/views/repos/repo.haml +64 -0
- data/lib/perkins/views/repos/spinner.haml +3 -0
- data/lib/perkins/webhooks/github.rb +12 -0
- data/lib/perkins/worker.rb +33 -0
- data/lib/perkins.rb +36 -0
- data/perkins.gemspec +52 -0
- data/spec/fixtures/.travis.yml +8 -0
- data/spec/fixtures/config.yml +6 -0
- data/spec/lib/build/build_spec.rb +58 -0
- data/spec/lib/commit_spec.rb +6 -0
- data/spec/lib/dsl_spec.rb +17 -0
- data/spec/lib/listener_spec.rb +30 -0
- data/spec/lib/repo_spec.rb +110 -0
- data/spec/lib/runner_spec.rb +76 -0
- data/spec/lib/server_spec.rb +108 -0
- data/spec/spec_helper.rb +67 -0
- data/spec/support/auth.rb +30 -0
- data/spec/support/github_api.rb +177 -0
- metadata +503 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '../../spec_helper')
|
2
|
+
|
3
|
+
require "perkins/dsl"
|
4
|
+
|
5
|
+
describe "Repo" do
|
6
|
+
|
7
|
+
let(:app){
|
8
|
+
perkins_app
|
9
|
+
}
|
10
|
+
|
11
|
+
it "app should be configured" do
|
12
|
+
expect($redis.class).to be == Redis::Namespace
|
13
|
+
expect(app.github_client_id).to_not be_blank
|
14
|
+
expect(app.github_client_secret).to_not be_blank
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '../../spec_helper')
|
2
|
+
|
3
|
+
require "perkins/dsl"
|
4
|
+
|
5
|
+
describe "Listener" do
|
6
|
+
|
7
|
+
let(:app){
|
8
|
+
Perkins.application() do |app|
|
9
|
+
app.redis = Redis.new
|
10
|
+
app.server = { host: "localhost", port:1234 }
|
11
|
+
end
|
12
|
+
}
|
13
|
+
|
14
|
+
context "runner config" do
|
15
|
+
|
16
|
+
it "should generate a redis build data" do
|
17
|
+
data = {name: "lazy_high_charts" , sha: "2eed41547227ac03113613a54e8d7305fce982f0"}.to_json
|
18
|
+
l = Perkins::Listener.new
|
19
|
+
l.app = app
|
20
|
+
$redis.flushdb
|
21
|
+
allow(Perkins::Repo).to receive(:find).and_return(true)
|
22
|
+
allow(Perkins::Worker).to receive(:perform).and_return(true)
|
23
|
+
|
24
|
+
#expect(l).to receive(:exec_runner).with("commits", data)
|
25
|
+
l.exec_runner("commits", data)
|
26
|
+
expect(Perkins::Worker).to have_received(:perform)
|
27
|
+
r = Perkins::Repo.create
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '../../spec_helper')
|
2
|
+
|
3
|
+
#require "fakeredis"
|
4
|
+
|
5
|
+
#$redis = Redis.new
|
6
|
+
|
7
|
+
describe "Repo" do
|
8
|
+
|
9
|
+
let(:user_api) {
|
10
|
+
Octokit::Client.new(
|
11
|
+
login: ENV['LOGIN'],
|
12
|
+
access_token: ENV['ACCESS_TOKEN']
|
13
|
+
)
|
14
|
+
}
|
15
|
+
|
16
|
+
let(:file){
|
17
|
+
f = File.expand_path(File.dirname(__FILE__) + '/../fixtures/.travis.yml')
|
18
|
+
Travis::Yaml.parse( File.open(f).read )
|
19
|
+
}
|
20
|
+
|
21
|
+
let(:github_user){
|
22
|
+
Warden::GitHub::User.new
|
23
|
+
}
|
24
|
+
|
25
|
+
before(:each) do
|
26
|
+
perkins_app
|
27
|
+
allow_any_instance_of(Warden::GitHub::User).to receive(:api).and_return(user_api)
|
28
|
+
@user = Warden::GitHub::User.new
|
29
|
+
Perkins::Repo.sync_github_repos(@user)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "all should return repos" do
|
33
|
+
expect(Perkins::Repo.all).to_not be_blank
|
34
|
+
expect(Perkins::Repo.all.size).to be == Perkins::Repo.synced_records.size
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
it "all should return repos" do
|
39
|
+
expect(Perkins::Repo.first).to_not be_blank
|
40
|
+
end
|
41
|
+
|
42
|
+
it "all should return repos" do
|
43
|
+
r = Perkins::Repo.first
|
44
|
+
expect(r.name).to_not be_blank
|
45
|
+
expect(r.id).to_not be_blank
|
46
|
+
expect(r.url).to_not be_blank
|
47
|
+
#expect(r.local_path).to_not be_blank
|
48
|
+
end
|
49
|
+
|
50
|
+
context "loaded repo" do
|
51
|
+
before :each do
|
52
|
+
@repo = Perkins::Repo.first
|
53
|
+
@repo.load_git
|
54
|
+
expect(@repo.git).to be_instance_of(Git::Base)
|
55
|
+
@path = @repo.git.dir.path
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should download repo" do
|
59
|
+
expect(File.exists?(@path)).to be_present
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should have a default runner" do
|
63
|
+
expect(@repo.runner).to_not be_blank
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should have branches" do
|
67
|
+
expect(@repo.runner_branch).to be == ["master"]
|
68
|
+
expect(@repo.branches).to include("master")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context "runner config" do
|
73
|
+
before :each do
|
74
|
+
@repo = Perkins::Repo.first
|
75
|
+
allow_any_instance_of(Perkins::Repo).to receive(:check_config_existence).and_return(file)
|
76
|
+
@repo.load_git
|
77
|
+
expect(@repo.git).to be_instance_of(Git::Base)
|
78
|
+
@path = @repo.git.dir.path
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should have a runner" do
|
82
|
+
expect(@repo.runner).to be_instance_of(Perkins::Runner)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "run run run" do
|
86
|
+
sha = @repo.git.log.map(&:sha).first
|
87
|
+
@repo.runner.run(sha)
|
88
|
+
#expect(@repo.runner.status).to be == true
|
89
|
+
#expect(@repo.runner.response).to_not be_blank
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context "receive commit" do
|
94
|
+
before :each do
|
95
|
+
allow_any_instance_of(Perkins::Repo).to receive(:check_config_existence).and_return(file)
|
96
|
+
@repo = Perkins::Repo.first
|
97
|
+
@repo.load_git
|
98
|
+
expect(@repo.git).to be_instance_of(Git::Base)
|
99
|
+
@path = @repo.git.dir.path
|
100
|
+
end
|
101
|
+
|
102
|
+
it "receive commit" do
|
103
|
+
sha = @repo.git.log.map(&:sha).first
|
104
|
+
@repo.add_commit(sha, "master")
|
105
|
+
expect(@repo.new_commit).to be_instance_of(Perkins::Commit)
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '../../spec_helper')
|
2
|
+
|
3
|
+
describe "Runner" do
|
4
|
+
|
5
|
+
let(:user_api) {
|
6
|
+
Octokit::Client.new(
|
7
|
+
login: ENV['LOGIN'],
|
8
|
+
access_token: ENV['ACCESS_TOKEN']
|
9
|
+
)
|
10
|
+
}
|
11
|
+
|
12
|
+
let(:file){
|
13
|
+
f = File.expand_path(File.dirname(__FILE__) + '/../fixtures/.travis.yml')
|
14
|
+
Travis::Yaml.parse( File.open(f).read )
|
15
|
+
}
|
16
|
+
|
17
|
+
let(:github_user){
|
18
|
+
Warden::GitHub::User.new
|
19
|
+
}
|
20
|
+
|
21
|
+
before(:each) do
|
22
|
+
perkins_app
|
23
|
+
Perkins::Repo.delete_all
|
24
|
+
allow_any_instance_of(Warden::GitHub::User).to receive(:api).and_return(user_api)
|
25
|
+
@user = Warden::GitHub::User.new
|
26
|
+
Perkins::Repo.sync_github_repos(@user)
|
27
|
+
|
28
|
+
to_add = Perkins::Repo.synced_records.where(name: "michelson/BigBroda").first
|
29
|
+
Perkins::Repo.add_from_github(to_add.gb_id)
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
context "in repo" do
|
34
|
+
let( :repo ){ Perkins::Repo.first }
|
35
|
+
before :each do
|
36
|
+
#expect(repo.load_git).to be_instance_of(Git::Base)
|
37
|
+
@runner = Perkins::Runner.new
|
38
|
+
@runner.config = file
|
39
|
+
@runner.repo = repo
|
40
|
+
#allow_any_instance_of(Perkins::Repo).to receive(:clone_or_load).and_return(true)
|
41
|
+
#allow_any_instance_of(Perkins::Repo).to receive(:git).and_return(Git::Base.new)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "runner should raise error in case it fails" do
|
45
|
+
|
46
|
+
expect{@runner.run!}.to raise_error
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should install bundler" do
|
50
|
+
#allow_any_instance_of(Git::Base).to receive(:chdir).and_return(true)
|
51
|
+
expect{@runner.run("master")}.to_not raise_error
|
52
|
+
#expect(Git::Base).to have_received(:chdir)
|
53
|
+
|
54
|
+
expect(@runner.duration).to be > 0
|
55
|
+
expect(@runner).to_not be_running
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "a go repo" do
|
61
|
+
let( :repo ){ Perkins::Repo.find_by(name: "michelson/godard") }
|
62
|
+
before :each do
|
63
|
+
repo.clone_or_load
|
64
|
+
@runner = repo.runner
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should install bundler" do
|
68
|
+
expect{@runner.run("master")}.to_not raise_error
|
69
|
+
expect(@runner.duration).to be > 0
|
70
|
+
expect(@runner).to_not be_running
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '../../spec_helper')
|
2
|
+
|
3
|
+
#require 'hello_world' # <-- your sinatra app
|
4
|
+
require 'rspec'
|
5
|
+
require 'rack/test'
|
6
|
+
|
7
|
+
require 'dotenv'
|
8
|
+
Dotenv.load
|
9
|
+
|
10
|
+
describe 'Server App' do
|
11
|
+
include Rack::Test::Methods
|
12
|
+
|
13
|
+
let(:body) { { :ref=>"refs/heads/another-branch" }.to_json }
|
14
|
+
|
15
|
+
let(:user_api) {
|
16
|
+
Octokit::Client.new(
|
17
|
+
login: ENV['LOGIN'],
|
18
|
+
access_token: ENV['ACCESS_TOKEN']
|
19
|
+
)
|
20
|
+
}
|
21
|
+
|
22
|
+
let(:file){
|
23
|
+
f = File.expand_path(File.dirname(__FILE__) + '/../fixtures/.travis.yml')
|
24
|
+
Travis::Yaml.parse( File.open(f).read )
|
25
|
+
}
|
26
|
+
|
27
|
+
def app
|
28
|
+
a = Perkins::Server
|
29
|
+
a.set :perkins_application, perkins_app
|
30
|
+
a.set :github_options, {
|
31
|
+
:scopes => "admin:repo_hook,repo,user:email",
|
32
|
+
:secret => perkins_app.github_client_secret,
|
33
|
+
:client_id => perkins_app.github_client_id,
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
context "with app" do
|
38
|
+
|
39
|
+
before do
|
40
|
+
@user = make_user('login' => 'michelson')
|
41
|
+
login_as @user
|
42
|
+
end
|
43
|
+
|
44
|
+
it "index" do
|
45
|
+
get '/'
|
46
|
+
expect(last_response).to be_ok
|
47
|
+
end
|
48
|
+
|
49
|
+
it "show config" do
|
50
|
+
get "/config"
|
51
|
+
expect(last_response).to be_ok
|
52
|
+
expect(last_response.body).to include("github_client_id")
|
53
|
+
end
|
54
|
+
|
55
|
+
it "profile" do
|
56
|
+
allow_any_instance_of(Warden::GitHub::User).to receive(:api).and_return(user_api)
|
57
|
+
get "/me"
|
58
|
+
#puts last_response.body
|
59
|
+
expect(last_response).to be_ok
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "github" do
|
63
|
+
|
64
|
+
it "sync" do
|
65
|
+
|
66
|
+
allow_any_instance_of(Warden::GitHub::User).to receive(:api).and_return(user_api)
|
67
|
+
|
68
|
+
get "/repos/sync"
|
69
|
+
|
70
|
+
follow_redirect!
|
71
|
+
|
72
|
+
expect("http://example.org/me").to be == last_request.url
|
73
|
+
|
74
|
+
expect(last_response).to be_ok
|
75
|
+
|
76
|
+
expect(Perkins::Repo.synced_records).to be_any
|
77
|
+
end
|
78
|
+
|
79
|
+
it "add repo" do
|
80
|
+
allow_any_instance_of(Warden::GitHub::User).to receive(:api).and_return(user_api)
|
81
|
+
a = Warden::GitHub::User.new
|
82
|
+
Perkins::Repo.sync_github_repos(a)
|
83
|
+
repo = Perkins::Repo.synced_records.first
|
84
|
+
get "/repos/add/#{repo.gb_id}"
|
85
|
+
follow_redirect!
|
86
|
+
expect("http://example.org/me").to be == last_request.url
|
87
|
+
expect(last_response).to be_ok
|
88
|
+
expect(Perkins::Repo.find(repo.id).github_data).to_not be_blank
|
89
|
+
end
|
90
|
+
|
91
|
+
it "find a repo" do
|
92
|
+
allow_any_instance_of(Warden::GitHub::User).to receive(:api).and_return(user_api)
|
93
|
+
a = Warden::GitHub::User.new
|
94
|
+
Perkins::Repo.sync_github_repos(a)
|
95
|
+
allow_any_instance_of(Perkins::Repo).to receive(:check_config_existence).and_return(file)
|
96
|
+
get "/repos/#{Perkins::Repo.last.github_data["full_name"]}"
|
97
|
+
expect(last_response.body).to include(Perkins::Repo.last.name)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "receive hook" do
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
end
|
108
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
ENV['RACK_ENV'] = 'test'
|
3
|
+
require 'rspec'
|
4
|
+
require 'database_cleaner'
|
5
|
+
#require 'webmock/rspec'
|
6
|
+
require 'debugger'
|
7
|
+
require File.join(File.dirname(__FILE__), '../lib', 'perkins')
|
8
|
+
require "pry"
|
9
|
+
require "git"
|
10
|
+
require 'rack/test'
|
11
|
+
|
12
|
+
require "support/auth"
|
13
|
+
require "support/github_api"
|
14
|
+
|
15
|
+
require 'dotenv'
|
16
|
+
Dotenv.load
|
17
|
+
|
18
|
+
RSpec.configure do |config|
|
19
|
+
|
20
|
+
config.include(Rack::Test::Methods)
|
21
|
+
config.include(SinatraAuthGithubTestHelper)
|
22
|
+
|
23
|
+
def perkins_app
|
24
|
+
Perkins.application() do |app|
|
25
|
+
config do |c|
|
26
|
+
c.redis = {namespace: "perkins:test"}
|
27
|
+
c.database = "./examples/database.yml"
|
28
|
+
#c.server = { host: "localhost", port:1234 }
|
29
|
+
c.github_client_id = ENV['GITHUB_CLIENT_ID']
|
30
|
+
c.github_client_secret = ENV['GITHUB_SECRET']
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
#WebMock.disable_net_connect!(:allow => 'coveralls.io')
|
36
|
+
|
37
|
+
config.raise_errors_for_deprecations!
|
38
|
+
|
39
|
+
config.before(:all) do
|
40
|
+
perkins_app
|
41
|
+
@test_repo = "#{test_github_login}/#{test_github_repository}"
|
42
|
+
@test_org_repo = "#{test_github_org}/#{test_github_repository}"
|
43
|
+
end
|
44
|
+
|
45
|
+
config.before(:suite) do
|
46
|
+
perkins_app
|
47
|
+
DatabaseCleaner.clean_with(:truncation)
|
48
|
+
end
|
49
|
+
|
50
|
+
# this runs before each *_spec.rb, not before ALL specs
|
51
|
+
config.before(:all) do
|
52
|
+
DatabaseCleaner.clean_with(:truncation)
|
53
|
+
end
|
54
|
+
|
55
|
+
config.before(:each) do
|
56
|
+
DatabaseCleaner.strategy = :transaction
|
57
|
+
end
|
58
|
+
|
59
|
+
config.before(:each) do
|
60
|
+
DatabaseCleaner.start
|
61
|
+
end
|
62
|
+
|
63
|
+
#config.after(:each) do
|
64
|
+
# DatabaseCleaner.clean
|
65
|
+
#end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'warden/test/helpers'
|
2
|
+
require 'warden/github/user'
|
3
|
+
|
4
|
+
require "warden"
|
5
|
+
|
6
|
+
module SinatraAuthGithubTestHelper
|
7
|
+
|
8
|
+
include(Warden::Test::Helpers)
|
9
|
+
|
10
|
+
Warden.test_mode!
|
11
|
+
def make_user(attrs = {})
|
12
|
+
User.make(attrs)
|
13
|
+
end
|
14
|
+
|
15
|
+
class User < Warden::GitHub::User
|
16
|
+
def self.make(attrs = {})
|
17
|
+
default_attrs = {
|
18
|
+
'login' => "test_user",
|
19
|
+
'name' => "Test User",
|
20
|
+
'email' => "test@example.com",
|
21
|
+
'company' => "GitHub",
|
22
|
+
'gravatar_id' => 'a'*32,
|
23
|
+
'avatar_url' => 'https://a249.e.akamai.net/assets.github.com/images/gravatars/gravatar-140.png?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png'
|
24
|
+
}
|
25
|
+
default_attrs.merge! attrs
|
26
|
+
User.new(default_attrs)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
@@ -0,0 +1,177 @@
|
|
1
|
+
=begin
|
2
|
+
require 'vcr'
|
3
|
+
VCR.configure do |c|
|
4
|
+
c.configure_rspec_metadata!
|
5
|
+
c.filter_sensitive_data("<GITHUB_LOGIN>") do
|
6
|
+
test_github_login
|
7
|
+
end
|
8
|
+
c.filter_sensitive_data("<GITHUB_PASSWORD>") do
|
9
|
+
test_github_password
|
10
|
+
end
|
11
|
+
c.filter_sensitive_data("<<ACCESS_TOKEN>>") do
|
12
|
+
test_github_token
|
13
|
+
end
|
14
|
+
c.filter_sensitive_data("<GITHUB_CLIENT_ID>") do
|
15
|
+
test_github_client_id
|
16
|
+
end
|
17
|
+
c.filter_sensitive_data("<GITHUB_CLIENT_SECRET>") do
|
18
|
+
test_github_client_secret
|
19
|
+
end
|
20
|
+
c.define_cassette_placeholder("<GITHUB_TEST_REPOSITORY>") do
|
21
|
+
test_github_repository
|
22
|
+
end
|
23
|
+
c.define_cassette_placeholder("<GITHUB_TEST_ORGANIZATION>") do
|
24
|
+
test_github_org
|
25
|
+
end
|
26
|
+
c.define_cassette_placeholder("<GITHUB_TEST_ORG_TEAM_ID>") do
|
27
|
+
"10050505050000"
|
28
|
+
end
|
29
|
+
|
30
|
+
c.before_http_request(:real?) do |request|
|
31
|
+
next if request.headers['X-Vcr-Test-Repo-Setup']
|
32
|
+
next unless request.uri.include? test_github_repository
|
33
|
+
|
34
|
+
options = {
|
35
|
+
:headers => {'X-Vcr-Test-Repo-Setup' => 'true'},
|
36
|
+
:auto_init => true
|
37
|
+
}
|
38
|
+
|
39
|
+
test_repo = "#{test_github_login}/#{test_github_repository}"
|
40
|
+
if !oauth_client.repository?(test_repo, options)
|
41
|
+
Octokit.octokit_warn "NOTICE: Creating #{test_repo} test repository."
|
42
|
+
oauth_client.create_repository(test_github_repository, options)
|
43
|
+
end
|
44
|
+
|
45
|
+
test_org_repo = "#{test_github_org}/#{test_github_repository}"
|
46
|
+
if !oauth_client.repository?(test_org_repo, options)
|
47
|
+
Octokit.octokit_warn "NOTICE: Creating #{test_org_repo} test repository."
|
48
|
+
options[:organization] = test_github_org
|
49
|
+
oauth_client.create_repository(test_github_repository, options)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
c.ignore_request do |request|
|
54
|
+
!!request.headers['X-Vcr-Test-Repo-Setup']
|
55
|
+
end
|
56
|
+
|
57
|
+
c.default_cassette_options = {
|
58
|
+
:serialize_with => :json,
|
59
|
+
# TODO: Track down UTF-8 issue and remove
|
60
|
+
:preserve_exact_body_bytes => true,
|
61
|
+
:decode_compressed_response => true,
|
62
|
+
:record => ENV['TRAVIS'] ? :none : :once
|
63
|
+
}
|
64
|
+
c.cassette_library_dir = 'spec/cassettes'
|
65
|
+
c.hook_into :webmock
|
66
|
+
end
|
67
|
+
=end
|
68
|
+
|
69
|
+
def test_github_login
|
70
|
+
ENV.fetch 'OCTOKIT_TEST_GITHUB_LOGIN', 'api-padawan'
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_github_password
|
74
|
+
ENV.fetch 'OCTOKIT_TEST_GITHUB_PASSWORD', 'wow_such_password'
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_github_token
|
78
|
+
ENV.fetch 'OCTOKIT_TEST_GITHUB_TOKEN', 'x' * 40
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_github_client_id
|
82
|
+
ENV.fetch 'OCTOKIT_TEST_GITHUB_CLIENT_ID', 'x' * 21
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_github_client_secret
|
86
|
+
ENV.fetch 'OCTOKIT_TEST_GITHUB_CLIENT_SECRET', 'x' * 40
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_github_repository
|
90
|
+
ENV.fetch 'OCTOKIT_TEST_GITHUB_REPOSITORY', 'api-sandbox'
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_github_org
|
94
|
+
ENV.fetch 'OCTOKIT_TEST_GITHUB_ORGANIZATION', 'api-playground'
|
95
|
+
end
|
96
|
+
|
97
|
+
def stub_delete(url)
|
98
|
+
stub_request(:delete, github_url(url))
|
99
|
+
end
|
100
|
+
|
101
|
+
def stub_get(url)
|
102
|
+
stub_request(:get, github_url(url))
|
103
|
+
end
|
104
|
+
|
105
|
+
def stub_head(url)
|
106
|
+
stub_request(:head, github_url(url))
|
107
|
+
end
|
108
|
+
|
109
|
+
def stub_patch(url)
|
110
|
+
stub_request(:patch, github_url(url))
|
111
|
+
end
|
112
|
+
|
113
|
+
def stub_post(url)
|
114
|
+
stub_request(:post, github_url(url))
|
115
|
+
end
|
116
|
+
|
117
|
+
def stub_put(url)
|
118
|
+
stub_request(:put, github_url(url))
|
119
|
+
end
|
120
|
+
|
121
|
+
def fixture_path
|
122
|
+
File.expand_path("../fixtures", __FILE__)
|
123
|
+
end
|
124
|
+
|
125
|
+
def fixture(file)
|
126
|
+
File.new(fixture_path + '/' + file)
|
127
|
+
end
|
128
|
+
|
129
|
+
def json_response(file)
|
130
|
+
{
|
131
|
+
:body => fixture(file),
|
132
|
+
:headers => {
|
133
|
+
:content_type => 'application/json; charset=utf-8'
|
134
|
+
}
|
135
|
+
}
|
136
|
+
end
|
137
|
+
|
138
|
+
def github_url(url)
|
139
|
+
return url if url =~ /^http/
|
140
|
+
|
141
|
+
url = File.join(Octokit.api_endpoint, url)
|
142
|
+
uri = Addressable::URI.parse(url)
|
143
|
+
uri.path.gsub!("v3//", "v3/")
|
144
|
+
|
145
|
+
uri.to_s
|
146
|
+
end
|
147
|
+
|
148
|
+
def basic_github_url(path, options = {})
|
149
|
+
url = File.join(Octokit.api_endpoint, path)
|
150
|
+
uri = Addressable::URI.parse(url)
|
151
|
+
uri.path.gsub!("v3//", "v3/")
|
152
|
+
|
153
|
+
uri.user = options.fetch(:login, test_github_login)
|
154
|
+
uri.password = options.fetch(:password, test_github_password)
|
155
|
+
|
156
|
+
uri.to_s
|
157
|
+
end
|
158
|
+
|
159
|
+
def basic_auth_client(login = test_github_login, password = test_github_password )
|
160
|
+
client = Octokit.client
|
161
|
+
client.login = test_github_login
|
162
|
+
client.password = test_github_password
|
163
|
+
|
164
|
+
client
|
165
|
+
end
|
166
|
+
|
167
|
+
def oauth_client
|
168
|
+
Octokit::Client.new(:access_token => test_github_token)
|
169
|
+
end
|
170
|
+
|
171
|
+
def use_vcr_placeholder_for(text, replacement)
|
172
|
+
VCR.configure do |c|
|
173
|
+
c.define_cassette_placeholder(replacement) do
|
174
|
+
text
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|