Skip to content

Commit

Permalink
Merge pull request github#289 from CodePorting/master
Browse files Browse the repository at this point in the history
Pull request to merge CodePorting service hook
  • Loading branch information
technoweenie committed Apr 27, 2012
2 parents b5d27dd + bc5c246 commit c52e07f
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 0 deletions.
24 changes: 24 additions & 0 deletions docs/CodePorting-C#2Java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
CodePorting-C#2Java
======

Allows you to setup a GitHub repository to port C# code to Java on git commit.

Install Notes
-------------

1. Signup for a CodePorting account at https://apps.codeporting.com/signup
2. You can find your "User name" and "Password" on www.codeporting.com

Developer Notes
---------------

data
- project_name
- repo_key
- target_repo_key
- username
- password
- active

payload
- refer to docs/github_payload
84 changes: 84 additions & 0 deletions services/CodePorting-C#2Java.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
class Service::CodePortingCSharp2Java < Service
string :project_name, :repo_key, :target_repo_key, :username, :password
boolean :active
string :userid

self.title = 'CodePorting-C#2Java'

def receive_push
response = ""

return if Array(payload['commits']).size == 0

check_configuration_options(data)

perform_login

if (token == "")
response = "Unable to login on codeporting.com at the moment :( "
raise_config_error "#{response}"
else
response = process_on_codeporting
if (response == "True")
#process successful
else
raise_config_error 'Porting performed with errors, porting will be performed again on next commit.'
end
end

response
end

def perform_login
http.ssl[:verify] = false
postdata = "LoginName=#{username}&Password=#{password}"
headers = {
'Content-Type' => 'application/x-www-form-urlencoded'
}
resp, data = http_post "https://apps.codeporting.com/csharp2java/v0/UserSignin", postdata, headers

doc = REXML::Document.new(data)
retValue = ""
doc.each_element('//return') { |item|
retValue = item.attributes['success']
}

if (retValue == "True")
doc.each_element('//Token') { |item|
token = item.text
}
else
token = ""
end
end

def process_on_codeporting
http.ssl[:verify] = false
postdata = "token=#{token}&ProjectName=#{project_name}&RepoKey=#{repo_key}&TarRepoKey=#{target_repo_key}&Username=#{username}&Password=#{password}&GithubUserId=#{userid}"
headers = {
'Content-Type' => 'application/x-www-form-urlencoded'
}
resp, data = http_post "https://apps.codeporting.com/csharp2java/v0/githubpluginsupport", postdata, headers

doc = REXML::Document.new(data)
retValue = ""
doc.each_element('//return') { |item|
retValue = item.attributes['success']
}
retValue
end

private

string :token

def check_configuration_options(data)
raise_config_error 'Project name must be set' if data['project_name'].blank?
raise_config_error 'Repository is required' if data['repo_key'].blank?
raise_config_error 'Target repository is required' if data['target_repo_key'].blank?
raise_config_error 'Codeporting username must be provided' if data['username'].blank?
raise_config_error 'Codeporting password must be provided' if data['password'].blank?
end


end
62 changes: 62 additions & 0 deletions test/CodePorting-C#2Java_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
require File.expand_path('../helper', __FILE__)

class CodePortingCSharp2JavaTest < Service::TestCase
def test_push
svc = service({'project_name' => 'Test_Project',
'repo_key' => 'Test',
'target_repo_key' => 'TestJava',
'username' => 'codeportingtest',
'password' => 'testpassword',
'active' => '1',
'userid' => 'CodePorting'}, payload)

assert_equal 1, @payload['commits'].size
response = svc.receive_push
if (response == "True")
raise "Service hook performed good"
else
raise "Service failure! #{response}"
end
end

def test_push_master_only_on_non_master
svc = service({'project_name' => 'Test_Project',
'repo_key' => 'Test',
'target_repo_key' => 'TestJava',
'username' => 'codeportingtest',
'password' => 'testpassword',
'active' => '1',
'userid' => 'CodePorting'}, payload)

assert_equal 1, @payload['commits'].size
response = svc.receive_push
if (response == "True")
raise "Service hook performed good"
else
raise "Service failure! #{response}"
end
end

def test_push_master_only_on_master
svc = service({'project_name' => 'Test_Project',
'repo_key' => 'Test',
'target_repo_key' => 'TestJava',
'username' => 'codeportingtest',
'password' => 'testpassword',
'active' => '1',
'userid' => 'CodePorting'}, payload)

assert_equal 1, @payload['commits'].size
response = svc.receive_push
if (response == "True")
raise "Service hook performed good"
else
raise "Service failure! #{response}"
end
end

def service(*args)
super Service::CodePortingCSharp2Java, *args
end
end

0 comments on commit c52e07f

Please sign in to comment.