This repository has been archived by the owner on Nov 9, 2023. It is now read-only.
forked from github/github-services
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from reillyse/master
Adding circleci services
- Loading branch information
Showing
3 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
CircleCI continuous integration | ||
|
||
[CircleCi](https://circleci.com) will add this hook automatically to projects which you test using CircleCi. To sign up, go to https://circleci.com, sign in, and start testing! | ||
|
||
Install Notes | ||
------------- | ||
|
||
1. Sign up at https://circleci.com with your github credentials | ||
2. Follow your repository | ||
3. You're done! | ||
|
||
For more details about CircleCI go to https://circleci.com | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class Service::Circleci < Service | ||
|
||
url "https://circleci.com" | ||
logo_url "https://circleci.com/favicon.ico" | ||
|
||
maintained_by :github => 'circleci' | ||
supported_by :web => 'https://circleci.com/about', | ||
:email => 'sayhi@circleci.com' | ||
|
||
default_events Service::ALL_EVENTS | ||
|
||
|
||
def receive_event | ||
|
||
http.headers['content-type'] = 'application/x-www-form-urlencoded' | ||
http.params.merge!(:payload => JSON.generate(payload) , :event_type => JSON.generate({ :event_type => self.event })) | ||
http_post circleci_url, payload.to_json | ||
|
||
end | ||
|
||
|
||
private | ||
|
||
def circleci_url | ||
"https://circleci.com/hooks/github" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
require File.expand_path('../helper', __FILE__) | ||
|
||
class CircleciTest < Service::TestCase | ||
|
||
|
||
def setup | ||
@stubs = Faraday::Adapter::Test::Stubs.new | ||
end | ||
|
||
|
||
# currently supported events | ||
|
||
# commit_comment create delete download follow fork fork_apply gist gollum | ||
# issue_comment issues member public pull_request push team_add watch | ||
# pull_request_review_comment status | ||
|
||
def test_commit_comment | ||
post_to_service(:commit_comment) | ||
end | ||
|
||
def test_create | ||
post_to_service(:create) | ||
end | ||
|
||
def test_delete | ||
post_to_service(:delete) | ||
end | ||
|
||
def test_download | ||
post_to_service(:download) | ||
end | ||
|
||
def test_follow | ||
post_to_service(:follow) | ||
end | ||
|
||
def test_fork | ||
post_to_service(:fork) | ||
end | ||
|
||
def test_fork_apply | ||
post_to_service(:fork_apply) | ||
end | ||
|
||
def test_gist | ||
post_to_service(:gist) | ||
end | ||
|
||
def test_gollum | ||
post_to_service(:gollum) | ||
end | ||
|
||
def test_issue_comment | ||
post_to_service(:issue_comment) | ||
end | ||
|
||
def test_issues | ||
post_to_service(:issues) | ||
end | ||
|
||
def test_member | ||
post_to_service(:member) | ||
end | ||
|
||
def test_public | ||
post_to_service(:public) | ||
end | ||
|
||
|
||
|
||
def test_push | ||
post_to_service(:push) | ||
end | ||
|
||
|
||
def test_team_add | ||
post_to_service(:team_add) | ||
end | ||
|
||
def test_watch | ||
post_to_service(:watch) | ||
end | ||
|
||
def test_pull_request_review_comment | ||
post_to_service(:pull_request_review_comment) | ||
end | ||
|
||
def test_status | ||
post_to_service(:status) | ||
end | ||
|
||
def test_supported_events | ||
assert_equal Service::Circleci.supported_events.sort , Service::ALL_EVENTS.sort | ||
end | ||
|
||
|
||
private | ||
|
||
def service(*args) | ||
super Service::Circleci, *args | ||
end | ||
|
||
def post_to_service(event_name) | ||
assert Service::ALL_EVENTS.include? event_name.to_s | ||
svc = service(event_name, {'token' => 'abc'},payload) | ||
|
||
@stubs.post "/hooks/github" do |env| | ||
assert_match "https://circleci.com/hooks/github", env[:url].to_s | ||
assert_match 'application/x-www-form-urlencoded', env[:request_headers]['content-type'] | ||
assert_equal payload, JSON.parse(env[:params]["payload"]) | ||
assert_equal event_name.to_s, JSON.parse(env[:params]["event_type"])["event_type"] | ||
end | ||
|
||
svc.receive_event | ||
|
||
end | ||
|
||
end | ||
|