Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Pull request to merge CodePorting service hook #289

Merged
merged 8 commits into from

2 participants

@CodePorting

Please merge changes into guthub/github-services.

@technoweenie

Needs tests. The unindented code isn't ideal, but I can fix that if you want to be a rebel :)

@CodePorting

yeah, sure :)
To test we need the service to be active/live, don't we? Please suggest

@CodePorting

Please have a look now, I have updated the service hook and uploaded test. Please merge changes or suggest what else is required.

@technoweenie

Wow, this is intense. The services use Faraday, so you can probably delete most of that code. It should handle things like multipart for you.

@technoweenie

This service needs to be dramatically simplified. GitHub Services typically don't do much work at all. At most, they parse the hook from GitHub.com and format a message to a 3rd party service. This is actually downloading the code locally, and then sending it to your service?

We do support other similar services, and they take the notification from GitHub Services and handle the code downloading/installing on their end.

@CodePorting

Please check the service code, I have simplified the logic in service hook and placed rest of the functionality on our end. Please merge the changes if they are appropriate now, or suggest otherwise :)

@technoweenie

I'd really appreciate it if you'd use Faraday. This keeps us from being tied to a single http adapter (net/http), and lets us run fast tests without hitting external services. Basically every server uses it.

CodeClimate is a great example. Most hooks just take the payload and send it on -- or mash it into a format for some existing API. Here's the documentation for sending a POST: #http_post.

@CodePorting

Please have a look at code now, I have used the Faraday to make calls this time, Please let me know if anything is off the standards and I will update it according to your suggestions :)

@technoweenie technoweenie merged commit c52e07f into from
@technoweenie

Dang, accidentally merged this. This code was really bad and far from working. I got it passing tests though.

@CodePorting

Please suggest so that I can make necessary changes to make the code perfectly acceptable for merging into github:master. I would really appreciate any help in this regard.

@technoweenie

It's merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
24 docs/CodePorting-C#2Java
@@ -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
View
84 services/CodePorting-C#2Java.rb
@@ -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
View
62 test/CodePorting-C#2Java_test.rb
@@ -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
+
Something went wrong with that request. Please try again.