hubstats 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGELOG.markdown +3 -0
- data/README.md +1 -1
- data/app/controllers/hubstats/deploys_controller.rb +20 -5
- data/app/models/hubstats/deploy.rb +8 -0
- data/app/models/hubstats/label.rb +1 -1
- data/config/routes.rb +1 -1
- data/lib/hubstats/version.rb +1 -1
- data/spec/controllers/hubstats/deploys_controller_spec.rb +95 -0
- data/spec/controllers/hubstats/events_controller_spec.rb +1 -1
- data/spec/factories/deploys.rb +8 -0
- data/spec/factories/repo.rb +1 -2
- data/spec/lib/hubstats/events_handler_spec.rb +10 -10
- data/spec/lib/hubstats/github_api_spec.rb +9 -9
- data/spec/models/hubstats/comment_spec.rb +16 -29
- data/spec/models/hubstats/deploy_spec.rb +110 -0
- data/spec/models/hubstats/label_spec.rb +11 -1
- data/spec/models/hubstats/pull_request_spec.rb +3 -2
- data/spec/models/hubstats/repo_spec.rb +19 -3
- data/spec/models/hubstats/user_spec.rb +8 -9
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NzRkMWM1NzQyOWY2YWMxZDdmZGZlMGIyZTgzMGU2YjQ0MjQ2OTFhZg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZjVhMDgwNTRmYmNlMGM1M2I0M2IwNDQ3NTQ0ODg5ZjRmNDk5MzhlYw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MzZjMzZhYmM2ODg3ODQ0OTYxYzMyMWRmOTlmNTlmMTAyZGU0MjRmMzExMWY2
|
10
|
+
MjMxNzNkMTFhODE0YmYwYTIyNzkyYjcyMTAyYTlhYmE0ZTA1MzMyZjU3ZTU4
|
11
|
+
NTM2NzBjZTgwNDhlYTcyNTY2NzFkZWUzOThmZmVkNThlYzU1ZmM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OGNhMDc2ZGNhYzg4NWQ5NzZhODc2MWU4MzIwMmUyOTQ2NTUwZDI5Y2JhYmVh
|
14
|
+
ZjY0MGJjMGEwYzY0NjZkMzk3YjRiMzdjZDUwNDFjMzVjZjBjMGQwNjZkM2U1
|
15
|
+
YTQ5ZmUzY2M5MzYyMWVhMDNhMjY3MTZjOTY2YmE5NjdiNTQ0NDI=
|
data/CHANGELOG.markdown
CHANGED
data/README.md
CHANGED
@@ -46,7 +46,7 @@ Set the endpoint to be:
|
|
46
46
|
|
47
47
|
Hubstats needs to know what repos for it to watch. You can set it to watch either an entire organization or a list of specific repos in octokit.yml.
|
48
48
|
|
49
|
-
|
49
|
+
## Testing
|
50
50
|
|
51
51
|
All of the automated tests are written in RSpec. Since hubstats is a plugin, not an application, we need to install the plugin into a Rails application to run. The `test` directory is a dummy rails application for manually testing the UI by serving hubstats locally. When developing and using the `test/dummy` locally, then the test will automatically sync with any updated code, so it doesn't need to be re-served when changes are made with the normal Rails application. When in the development process, one just needs to run `rails s` once from the command line (while in `test/dummy`) to serve the plugin. http://guides.rubyonrails.org/plugins.html will give more information on the implementation of a Rails plugin.
|
52
52
|
|
@@ -12,7 +12,7 @@ module Hubstats
|
|
12
12
|
# .map(&:id)
|
13
13
|
|
14
14
|
# sets to include user and repo, and sorts data
|
15
|
-
@deploys = Hubstats::Deploy.includes(:
|
15
|
+
@deploys = Hubstats::Deploy.includes(:repo)
|
16
16
|
.order_with_timespan(@timespan, params[:order])
|
17
17
|
# .belonging_to_users(params[:users]).belonging_to_repos(params[:repos])
|
18
18
|
# .paginate(:page => params[:page], :per_page => 15).order("deployed_at DESC")
|
@@ -30,11 +30,26 @@ module Hubstats
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def create
|
33
|
-
|
34
|
-
|
35
|
-
redirect_to :action => 'index'
|
33
|
+
if params[:deployed_by].nil? || params[:git_revision].nil? || params[:repo_name].nil?
|
34
|
+
render text: "Missing a necessary parameter: deployer, git revision, or repository name.", :status => 400 and return
|
36
35
|
else
|
37
|
-
|
36
|
+
@deploy = Deploy.new
|
37
|
+
@deploy.deployed_at = params[:deployed_at]
|
38
|
+
@deploy.deployed_by = params[:deployed_by]
|
39
|
+
@deploy.git_revision = params[:git_revision]
|
40
|
+
@repo = Hubstats::Repo.where(full_name: params[:repo_name])
|
41
|
+
|
42
|
+
if @repo.empty?
|
43
|
+
render text: "Repository name is invalid.", :status => 400 and return
|
44
|
+
else
|
45
|
+
@deploy.repo_id = @repo.first.id.to_i
|
46
|
+
end
|
47
|
+
|
48
|
+
if @deploy.save
|
49
|
+
render :nothing =>true, :status => 200 and return
|
50
|
+
else
|
51
|
+
render :nothing => true, :status => 400 and return
|
52
|
+
end
|
38
53
|
end
|
39
54
|
end
|
40
55
|
|
@@ -1,6 +1,14 @@
|
|
1
1
|
module Hubstats
|
2
2
|
class Deploy < ActiveRecord::Base
|
3
3
|
|
4
|
+
before_validation :check_time, on: :create
|
5
|
+
validates :git_revision, :deployed_at, :deployed_by, :repo_id, presence: true
|
6
|
+
#validates_associated :repo
|
7
|
+
|
8
|
+
def check_time
|
9
|
+
self.deployed_at = Time.now.getutc if deployed_at.nil?
|
10
|
+
end
|
11
|
+
|
4
12
|
scope :deployed_since, lambda {|time| where("hubstats_deploys.deployed_at > ?", time) }
|
5
13
|
scope :belonging_to_repo, lambda {|repo_id| where(repo_id: repo_id)}
|
6
14
|
scope :belonging_to_user, lambda {|user_id| where(user_id: user_id)}
|
@@ -21,7 +21,7 @@ module Hubstats
|
|
21
21
|
if exists = Hubstats::Label.where(name: label[:name]).first
|
22
22
|
return exists
|
23
23
|
else
|
24
|
-
|
24
|
+
Label.new(name: label[:name], url: label[:url], color: label[:color])
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
data/config/routes.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Hubstats::Engine.routes.draw do
|
2
2
|
root to: "pull_requests#index" #sets default root to be the pulls page
|
3
3
|
post "/handler" => "events#handler", :as => :handler
|
4
|
-
resources :deploys, :only => [:
|
4
|
+
resources :deploys, :only => [:create, :index] #routes to both index and to create method
|
5
5
|
get "/metrics" => "repos#dashboard", :as => :metrics #routes to list of repos and stats
|
6
6
|
get "/pulls" => "pull_requests#index", :as => :pulls #routes to list of pulls
|
7
7
|
get "/users" => "users#index", :as => :users #routes to list of users
|
data/lib/hubstats/version.rb
CHANGED
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Hubstats
|
4
|
+
describe DeploysController, :type => :controller do
|
5
|
+
routes { Hubstats::Engine.routes }
|
6
|
+
describe "#create" do
|
7
|
+
|
8
|
+
before :each do
|
9
|
+
create(:repo, :full_name => "sportngin/ngin")
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should create a deploy' do
|
13
|
+
post(:create, {"git_revision" => "c1a2b37",
|
14
|
+
"repo_name" => "sportngin/ngin",
|
15
|
+
"deployed_at" => "2009-02-03 03:00:00 -0500",
|
16
|
+
"deployed_by" => "emmasax1"})
|
17
|
+
expect(assigns(:deploy).git_revision).to eq("c1a2b37")
|
18
|
+
expect(assigns(:deploy).deployed_at).to eq("2009-02-03 03:00:00 -0500")
|
19
|
+
expect(assigns(:deploy).deployed_by).to eq("emmasax1")
|
20
|
+
expect(assigns(:deploy).repo_id).to eq(101010)
|
21
|
+
expect(response).to have_http_status(200)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should create a deploy without a deployed_at because nil time turns into current time' do
|
25
|
+
post(:create, {"git_revision" => "c1a2b37",
|
26
|
+
"repo_name" => "sportngin/ngin",
|
27
|
+
"deployed_at" => nil,
|
28
|
+
"deployed_by" => "emmasax1"})
|
29
|
+
expect(assigns(:deploy).git_revision).to eq("c1a2b37")
|
30
|
+
expect(assigns(:deploy).deployed_by).to eq("emmasax1")
|
31
|
+
expect(assigns(:deploy).repo_id).to eq(101010)
|
32
|
+
expect(response).to have_http_status(200)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should NOT create a deploy without a git_revision' do
|
36
|
+
post(:create, {"git_revision" => nil,
|
37
|
+
"repo_name" => "sportngin/ngin",
|
38
|
+
"deployed_at" => "2009-02-03 03:00:00 -0500",
|
39
|
+
"deployed_by" => "emmasax1"})
|
40
|
+
expect(response).to have_http_status(400)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should NOT create a deploy without a deployed_by' do
|
44
|
+
post(:create, {"git_revision" => "c1a2b37",
|
45
|
+
"repo_name" => "sportngin/ngin",
|
46
|
+
"deployed_at" => "2009-02-03 03:00:00 -0500",
|
47
|
+
"deployed_by" => nil})
|
48
|
+
expect(response).to have_http_status(400)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should NOT create a deploy without a repo_name' do
|
52
|
+
post(:create, {"git_revision" => "c1a2b37",
|
53
|
+
"repo_name" => nil,
|
54
|
+
"deployed_at" => "2009-02-03 03:00:00 -0500",
|
55
|
+
"deployed_by" => "emmasax1"})
|
56
|
+
expect(response).to have_http_status(400)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should NOT create a deploy when given a non existing repo_name' do
|
60
|
+
post(:create, {"git_revision" => "c1a2b37",
|
61
|
+
"repo_name" => "sportngin/make_resourceful",
|
62
|
+
"deployed_at" => "2009-02-03 03:00:00 -0500",
|
63
|
+
"deployed_by" => "emmasax1"})
|
64
|
+
expect(response).to have_http_status(400)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "#index" do
|
69
|
+
|
70
|
+
before :each do
|
71
|
+
create(:repo, :full_name => "sportngin/ngin")
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should correctly order all of the deploys" do
|
75
|
+
deploy1 = create(:deploy, :git_revision => "c1a2b37",
|
76
|
+
:repo_id => 101010,
|
77
|
+
:deployed_at => "2009-02-03 03:00:00 -0500",
|
78
|
+
:deployed_by => "emmasax1")
|
79
|
+
deploy2 = create(:deploy, :git_revision => "kd9c102",
|
80
|
+
:repo_id => 101010,
|
81
|
+
:deployed_at => "2015-02-03 03:00:00 -0500",
|
82
|
+
:deployed_by => "emmasax1")
|
83
|
+
deploy3 = create(:deploy, :git_revision => "owk19sf",
|
84
|
+
:repo_id => 101010,
|
85
|
+
:deployed_at => "2011-02-03 03:00:00 -0500",
|
86
|
+
:deployed_by => "emmasax1")
|
87
|
+
deploys_ordered = [deploy2, deploy3, deploy1]
|
88
|
+
expect(Hubstats::Deploy).to receive(:order_with_timespan).and_return(deploys_ordered)
|
89
|
+
get :index
|
90
|
+
expect(response).to have_http_status(200)
|
91
|
+
expect(response).to render_template(:index)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
data/spec/factories/repo.rb
CHANGED
@@ -8,30 +8,30 @@ module Hubstats
|
|
8
8
|
let(:payload) {build(:pull_request_payload_hash)}
|
9
9
|
|
10
10
|
subject {Hubstats::EventsHandler.new()}
|
11
|
-
it 'successfully
|
11
|
+
it 'should successfully route the event' do
|
12
12
|
expect(subject).to receive(:pull_processor)
|
13
13
|
subject.route(payload,payload[:type])
|
14
14
|
end
|
15
15
|
|
16
|
-
it '
|
17
|
-
allow(
|
18
|
-
allow(
|
19
|
-
allow(
|
16
|
+
it 'should add labels to pull request' do
|
17
|
+
allow(PullRequest).to receive(:create_or_update) {pull}
|
18
|
+
allow(Repo).to receive(:where) {[repo,repo]}
|
19
|
+
allow(GithubAPI).to receive(:get_labels_for_pull) {['low','high']}
|
20
20
|
expect(pull).to receive(:add_labels).with(['low','high'])
|
21
21
|
subject.route(payload,payload[:type])
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
context "CommentEvent" do
|
26
|
-
it 'successfully
|
27
|
-
ehandler =
|
26
|
+
it 'should successfully route the event' do
|
27
|
+
ehandler = EventsHandler.new()
|
28
28
|
payload = build(:comment_payload_hash)
|
29
29
|
expect(ehandler).to receive(:comment_processor)
|
30
30
|
|
31
31
|
ehandler.route(payload,payload[:type])
|
32
32
|
end
|
33
33
|
|
34
|
-
it 'successfully
|
34
|
+
it 'should successfully process the event' do
|
35
35
|
ehandler = Hubstats::EventsHandler.new()
|
36
36
|
payload = build(:comment_payload_hash)
|
37
37
|
expect(Hubstats::Comment).to receive(:create_or_update)
|
@@ -39,7 +39,7 @@ module Hubstats
|
|
39
39
|
ehandler.route(payload,payload[:type])
|
40
40
|
end
|
41
41
|
|
42
|
-
it 'successfully creates_or_updates the event' do
|
42
|
+
it 'should successfully creates_or_updates the event' do
|
43
43
|
ehandler = Hubstats::EventsHandler.new()
|
44
44
|
payload = build(:comment_payload_hash)
|
45
45
|
expect(ehandler.route(payload,payload[:type]).class).to eq(Hubstats::Comment)
|
@@ -47,4 +47,4 @@ module Hubstats
|
|
47
47
|
end
|
48
48
|
|
49
49
|
end
|
50
|
-
end
|
50
|
+
end
|
@@ -20,7 +20,7 @@ module Hubstats
|
|
20
20
|
allow(ENV).to receive(:[]).and_return(nil)
|
21
21
|
end
|
22
22
|
|
23
|
-
it '
|
23
|
+
it 'should initialize client with options param' do
|
24
24
|
Hubstats::GithubAPI.configure({"access_token" => access_token})
|
25
25
|
expect(Octokit::Client).to receive(:new).with(access_token: access_token).and_return(client)
|
26
26
|
expect(Hubstats::GithubAPI.client).to eq(client)
|
@@ -32,7 +32,7 @@ module Hubstats
|
|
32
32
|
allow(ENV).to receive(:[]).with("GITHUB_API_TOKEN").and_return("github_api_token")
|
33
33
|
end
|
34
34
|
|
35
|
-
it '
|
35
|
+
it 'should initialize client with environment variables' do
|
36
36
|
Hubstats::GithubAPI.configure({"access_token" => access_token})
|
37
37
|
expect(Octokit::Client).to receive(:new).with(access_token: "github_api_token").and_return(client)
|
38
38
|
expect(Hubstats::GithubAPI.client()).to eq(client)
|
@@ -46,7 +46,7 @@ module Hubstats
|
|
46
46
|
allow(ENV).to receive(:[]).with("CLIENT_SECRET").and_return("client_secret")
|
47
47
|
end
|
48
48
|
|
49
|
-
it '
|
49
|
+
it 'should intialize client with client-id environment variables' do
|
50
50
|
Hubstats::GithubAPI.configure()
|
51
51
|
expect(Octokit::Client).to receive(:new).with(client_id: "client_id", client_secret: "client_secret").and_return(client)
|
52
52
|
expect(Hubstats::GithubAPI.client).to eq(client)
|
@@ -59,9 +59,9 @@ module Hubstats
|
|
59
59
|
allow(ENV).to receive(:[]).and_return(nil)
|
60
60
|
end
|
61
61
|
|
62
|
-
it '
|
62
|
+
it 'should fail to initialize at all' do
|
63
63
|
Hubstats::GithubAPI.configure()
|
64
|
-
expect
|
64
|
+
expect{Hubstats::GithubAPI.client}.to raise_error Octokit::Unauthorized
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
@@ -71,7 +71,7 @@ module Hubstats
|
|
71
71
|
let(:repo) {'hubstats'}
|
72
72
|
context "with old_endpoint" do
|
73
73
|
let(:old_endpoint) {'www.hubstats.com'}
|
74
|
-
it '
|
74
|
+
it 'should call delete_hook' do
|
75
75
|
allow(subject).to receive(:create_hook)
|
76
76
|
expect(subject).to receive(:delete_hook).with(repo,old_endpoint)
|
77
77
|
subject.update_hook('hubstats','www.hubstats.com')
|
@@ -79,7 +79,7 @@ module Hubstats
|
|
79
79
|
end
|
80
80
|
|
81
81
|
context "without old_point" do
|
82
|
-
it '
|
82
|
+
it 'should not call delete_hook' do
|
83
83
|
allow(subject).to receive(:create_hook)
|
84
84
|
expect(subject).to_not receive(:delete_hook).with(repo)
|
85
85
|
subject.update_hook('hubstats')
|
@@ -97,12 +97,12 @@ module Hubstats
|
|
97
97
|
allow(subject).to receive(:client) {client}
|
98
98
|
end
|
99
99
|
|
100
|
-
it "
|
100
|
+
it "should call octokit create_hook" do
|
101
101
|
expect(client).to receive(:create_hook)
|
102
102
|
subject.create_hook(repo)
|
103
103
|
end
|
104
104
|
|
105
|
-
it "
|
105
|
+
it "should rescue unprocessable entity" do
|
106
106
|
allow(client).to receive(:create_hook) { raise Octokit::UnprocessableEntity }
|
107
107
|
subject.create_hook(repo)
|
108
108
|
end
|
@@ -2,35 +2,22 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module Hubstats
|
4
4
|
describe Comment, :type => :model do
|
5
|
-
it '
|
6
|
-
github_user = {
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
}
|
22
|
-
|
23
|
-
pull_request = {
|
24
|
-
:id => 1000,
|
25
|
-
:url => "www.pull.com",
|
26
|
-
:repository => github_repo,
|
27
|
-
:user => github_user
|
28
|
-
}
|
29
|
-
|
30
|
-
repo = Hubstats::Repo.create_or_update(github_repo)
|
31
|
-
pull = Hubstats::PullRequest.create_or_update(pull_request)
|
32
|
-
comment = Hubstats::Comment.create_or_update(github_comment)
|
33
|
-
|
5
|
+
it 'should create and return a comment and user' do
|
6
|
+
github_user = {:login => "elliothursh",
|
7
|
+
:id => 10,
|
8
|
+
:type => "User"}
|
9
|
+
github_comment = {:user => github_user,
|
10
|
+
:pull_request_url => "www.pull.com",
|
11
|
+
:id => 100}
|
12
|
+
github_repo = {:id => 151,
|
13
|
+
:name => "HelloWorld"}
|
14
|
+
pull_request = {:id => 1000,
|
15
|
+
:url => "www.pull.com",
|
16
|
+
:repository => github_repo,
|
17
|
+
:user => github_user}
|
18
|
+
repo = Repo.create_or_update(github_repo)
|
19
|
+
pull = PullRequest.create_or_update(pull_request)
|
20
|
+
comment = Comment.create_or_update(github_comment)
|
34
21
|
expect(comment.id).to eq(github_comment[:id])
|
35
22
|
expect(comment.user_id).to eq(github_user[:id])
|
36
23
|
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Hubstats
|
4
|
+
describe Deploy, :type => :model do
|
5
|
+
it 'should create a deploy and check validations' do
|
6
|
+
repo = build(:repo)
|
7
|
+
deploy_hash = {git_revision: "c1a2b37",
|
8
|
+
repo_id: repo.id,
|
9
|
+
deployed_at: "2009-02-03 03:00:00 -0500",
|
10
|
+
deployed_by: "emmasax1"}
|
11
|
+
deploy = Deploy.create(deploy_hash)
|
12
|
+
expect(Deploy.count).to eq(1)
|
13
|
+
expect(deploy.git_revision).to eq(deploy_hash[:git_revision])
|
14
|
+
expect(deploy.repo_id).to eq(deploy_hash[:repo_id])
|
15
|
+
expect(deploy.deployed_at).to eq(deploy_hash[:deployed_at])
|
16
|
+
expect(deploy.deployed_by).to eq(deploy_hash[:deployed_by])
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should order deploys based on timespan ASC' do
|
20
|
+
repo = build(:repo)
|
21
|
+
deploy1 = Deploy.create(git_revision: "c1a2b37",
|
22
|
+
repo_id: repo.id,
|
23
|
+
deployed_at: "2009-12-03 23:00:00",
|
24
|
+
deployed_by: "emmasax1")
|
25
|
+
deploy2 = Deploy.create(git_revision: "kd92h10",
|
26
|
+
repo_id: repo.id,
|
27
|
+
deployed_at: "2010-05-26 22:00:00",
|
28
|
+
deployed_by: "odelltuttle")
|
29
|
+
deploy3 = Deploy.create(git_revision: "k10d8as",
|
30
|
+
repo_id: repo.id,
|
31
|
+
deployed_at: "2015-08-21 12:00:00",
|
32
|
+
deployed_by: "EvaMartinuzzi")
|
33
|
+
deploy4 = Deploy.create(git_revision: "917d9ss",
|
34
|
+
repo_id: repo.id,
|
35
|
+
deployed_at: "2014-12-19 08:00:00",
|
36
|
+
deployed_by: "panderson74")
|
37
|
+
deploys_ordered = [deploy1, deploy2, deploy4, deploy3]
|
38
|
+
new_ordered_deploys = Deploy.order_with_timespan(520.weeks, "ASC")
|
39
|
+
expect(Deploy.count).to eq(4)
|
40
|
+
expect(new_ordered_deploys).to eq(deploys_ordered)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should order deploys based on timespan DESC' do
|
44
|
+
repo = build(:repo)
|
45
|
+
deploy1 = Deploy.create(git_revision: "c1a2b37",
|
46
|
+
repo_id: repo.id,
|
47
|
+
deployed_at: "2009-12-03 23:00:00",
|
48
|
+
deployed_by: "emmasax1")
|
49
|
+
deploy2 = Deploy.create(git_revision: "kd92h10",
|
50
|
+
repo_id: repo.id,
|
51
|
+
deployed_at: "2010-05-26 22:00:00",
|
52
|
+
deployed_by: "odelltuttle")
|
53
|
+
deploy3 = Deploy.create(git_revision: "k10d8as",
|
54
|
+
repo_id: repo.id,
|
55
|
+
deployed_at: "2015-08-21 12:00:00",
|
56
|
+
deployed_by: "EvaMartinuzzi")
|
57
|
+
deploy4 = Deploy.create(git_revision: "917d9ss",
|
58
|
+
repo_id: repo.id,
|
59
|
+
deployed_at: "2014-12-19 08:00:00",
|
60
|
+
deployed_by: "panderson74")
|
61
|
+
deploys_ordered = [deploy3, deploy4, deploy2, deploy1]
|
62
|
+
new_ordered_deploys = Deploy.order_with_timespan(520.weeks, "DESC")
|
63
|
+
expect(Deploy.count).to eq(4)
|
64
|
+
expect(new_ordered_deploys).to eq(deploys_ordered)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should NOT create a deploy without a git_revision' do
|
68
|
+
repo = build(:repo)
|
69
|
+
expect(Deploy.create(git_revision: nil,
|
70
|
+
repo_id: repo.id,
|
71
|
+
deployed_at: "2009-02-03 03:00:00 -0500",
|
72
|
+
deployed_by: "emmasax1")).not_to be_valid
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should NOT create a deploy without a repo_id' do
|
76
|
+
repo = build(:repo)
|
77
|
+
expect(Deploy.create(git_revision: "c1a2b37",
|
78
|
+
repo_id: nil,
|
79
|
+
deployed_at: "2009-02-03 03:00:00 -0500",
|
80
|
+
deployed_by: "emmasax1")).not_to be_valid
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
it 'should NOT create a deploy without a deployed_by' do
|
85
|
+
repo = build(:repo)
|
86
|
+
expect(Deploy.create(git_revision: "c1a2b37",
|
87
|
+
repo_id: repo.id,
|
88
|
+
deployed_at: "2009-02-03 03:00:00 -0500",
|
89
|
+
deployed_by: nil)).not_to be_valid
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'should create a deploy wihtout a deployed_at because nil time turns into current time' do
|
93
|
+
repo = build(:repo)
|
94
|
+
expect(Deploy.create(git_revision: "c1a2b37",
|
95
|
+
repo_id: repo.id,
|
96
|
+
deployed_at: nil,
|
97
|
+
deployed_by: "emmasax1")).to be_valid
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'should NOT create a deploy without an already valid repo_id' do
|
101
|
+
repo = build(:repo, :id => nil,
|
102
|
+
:name => nil,
|
103
|
+
:full_name => nil)
|
104
|
+
expect(Deploy.create(git_revision: "c1a2b37",
|
105
|
+
repo_id: repo.id,
|
106
|
+
deployed_at: "2009-02-03 03:00:00 -0500",
|
107
|
+
deployed_by: "emmasax1")).not_to be_valid
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -1,6 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Hubstats
|
4
|
-
|
4
|
+
describe Label, :type => :model do
|
5
|
+
it 'should create a label' do
|
6
|
+
label_hash = {name: "Feature request",
|
7
|
+
color: "FCEC7F",
|
8
|
+
url: "https://api.github.com/repos/sportngin/ngin/labels/feature-request"}
|
9
|
+
label = Label.create(label_hash)
|
10
|
+
expect(Label.count).to eq(1)
|
11
|
+
expect(label.name).to eq(label_hash[:name])
|
12
|
+
expect(label.color).to eq(label_hash[:color])
|
13
|
+
expect(label.url).to eq(label_hash[:url])
|
14
|
+
end
|
5
15
|
end
|
6
16
|
end
|
@@ -2,12 +2,13 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module Hubstats
|
4
4
|
describe PullRequest, :type => :model do
|
5
|
-
it '
|
5
|
+
it 'should create and return a Pull Request' do
|
6
6
|
pull = build(:pull_request_hash)
|
7
|
-
pull_request =
|
7
|
+
pull_request = PullRequest.create_or_update(pull)
|
8
8
|
expect(pull_request.id).to eq(pull[:id])
|
9
9
|
expect(pull_request.user_id).to eq(pull[:user][:id])
|
10
10
|
expect(pull_request.repo_id).to eq(pull[:repository][:id])
|
11
|
+
expect(pull_request.number).to eq(pull[:number])
|
11
12
|
end
|
12
13
|
end
|
13
14
|
end
|
@@ -1,7 +1,23 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Hubstats
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
describe Repo, :type => :model do
|
5
|
+
it 'should create a repo' do
|
6
|
+
repo_hash = {id: 131242,
|
7
|
+
owner_id: 3728684,
|
8
|
+
name: "example_name",
|
9
|
+
full_name: "sportngin/example_name",
|
10
|
+
pushed_at: "2015-05-27 13:51:21 -0500",
|
11
|
+
created_at: "2009-05-27 06:27:04 -0500",
|
12
|
+
updated_at: "2015-03-26 16:17:19 -0500"}
|
13
|
+
repo = Repo.create(repo_hash)
|
14
|
+
expect(repo.id).to eq(repo_hash[:id])
|
15
|
+
expect(repo.owner).to eq(repo_hash[:owner])
|
16
|
+
expect(repo.name).to eq(repo_hash[:name])
|
17
|
+
expect(repo.full_name).to eq(repo_hash[:full_name])
|
18
|
+
expect(repo.pushed_at).to eq(repo_hash[:pushed_at])
|
19
|
+
expect(repo.created_at).to eq(repo_hash[:created_at])
|
20
|
+
expect(repo.updated_at).to eq(repo_hash[:updated_at])
|
21
|
+
end
|
22
|
+
end
|
7
23
|
end
|
@@ -2,22 +2,21 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module Hubstats
|
4
4
|
describe User, :type => :model do
|
5
|
-
|
6
5
|
before do
|
7
|
-
|
6
|
+
User.destroy_all()
|
8
7
|
end
|
9
8
|
|
10
|
-
|
11
|
-
it 'creates and returns a user' do
|
9
|
+
it 'should create and return a user' do
|
12
10
|
user = build(:user_hash, id: 10)
|
13
|
-
expect(
|
11
|
+
expect(User.create_or_update(user).id).to eq(10)
|
14
12
|
end
|
15
13
|
|
16
|
-
it '
|
17
|
-
user1 =
|
18
|
-
user2 =
|
14
|
+
it 'should update a user based off id' do
|
15
|
+
user1 = User.create_or_update(build(:user_hash, login: 'johnappleseed', id: 10))
|
16
|
+
user2 = User.create_or_update(build(:user_hash, login: 'johndoe', id: 10))
|
19
17
|
expect(user1).to eq(user2)
|
18
|
+
expect(user2.login).to eq("johndoe")
|
19
|
+
expect(user2.login).not_to eq("johnapplesdeed")
|
20
20
|
end
|
21
|
-
|
22
21
|
end
|
23
22
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hubstats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elliot Hursh
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-06-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -232,11 +232,13 @@ files:
|
|
232
232
|
- lib/tasks/hubstats_tasks.rake
|
233
233
|
- lib/tasks/populate_task.rake
|
234
234
|
- script/rails
|
235
|
+
- spec/controllers/hubstats/deploys_controller_spec.rb
|
235
236
|
- spec/controllers/hubstats/events_controller_spec.rb
|
236
237
|
- spec/controllers/hubstats/pull_requests_controller_spec.rb
|
237
238
|
- spec/controllers/hubstats/repos_controller_spec.rb
|
238
239
|
- spec/controllers/hubstats/users_controller_spec.rb
|
239
240
|
- spec/factories/comment.rb
|
241
|
+
- spec/factories/deploys.rb
|
240
242
|
- spec/factories/pull_requests.rb
|
241
243
|
- spec/factories/repo.rb
|
242
244
|
- spec/factories/users.rb
|
@@ -247,6 +249,7 @@ files:
|
|
247
249
|
- spec/lib/hubstats/events_handler_spec.rb
|
248
250
|
- spec/lib/hubstats/github_api_spec.rb
|
249
251
|
- spec/models/hubstats/comment_spec.rb
|
252
|
+
- spec/models/hubstats/deploy_spec.rb
|
250
253
|
- spec/models/hubstats/label_spec.rb
|
251
254
|
- spec/models/hubstats/pull_request_spec.rb
|
252
255
|
- spec/models/hubstats/repo_spec.rb
|
@@ -312,11 +315,13 @@ signing_key:
|
|
312
315
|
specification_version: 4
|
313
316
|
summary: Github Statistics
|
314
317
|
test_files:
|
318
|
+
- spec/controllers/hubstats/deploys_controller_spec.rb
|
315
319
|
- spec/controllers/hubstats/events_controller_spec.rb
|
316
320
|
- spec/controllers/hubstats/pull_requests_controller_spec.rb
|
317
321
|
- spec/controllers/hubstats/repos_controller_spec.rb
|
318
322
|
- spec/controllers/hubstats/users_controller_spec.rb
|
319
323
|
- spec/factories/comment.rb
|
324
|
+
- spec/factories/deploys.rb
|
320
325
|
- spec/factories/pull_requests.rb
|
321
326
|
- spec/factories/repo.rb
|
322
327
|
- spec/factories/users.rb
|
@@ -327,6 +332,7 @@ test_files:
|
|
327
332
|
- spec/lib/hubstats/events_handler_spec.rb
|
328
333
|
- spec/lib/hubstats/github_api_spec.rb
|
329
334
|
- spec/models/hubstats/comment_spec.rb
|
335
|
+
- spec/models/hubstats/deploy_spec.rb
|
330
336
|
- spec/models/hubstats/label_spec.rb
|
331
337
|
- spec/models/hubstats/pull_request_spec.rb
|
332
338
|
- spec/models/hubstats/repo_spec.rb
|