Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds https proxy support. #67

Merged
merged 4 commits into from
Nov 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ If you need to customize something or support a different CI service, you can co

If you have `COVERALLS_REPO_TOKEN` set and you're using Travis-CI not Travis-Pro, you need to set `CI_NAME=travis-ci`.

### HTTPS proxy settings
You can set https proxy if needed.
Environment variables to configure:
- `https.proxyHost`
- `https.proxyPort` (default value is **443**)

## Examples

- https://github.com/strawjs/straw-android
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CoverallsTask extends DefaultTask {
void postJsonToUrl(String json, String url) {

HTTPBuilder http = new HTTPBuilder(url)

setProxy(http)
http.request(POST) { req ->

req.entity = MultipartEntityBuilder.create().addBinaryBody('json_file', json.getBytes('UTF-8'), ContentType.APPLICATION_JSON, 'json_file').build()
Expand All @@ -57,6 +57,13 @@ class CoverallsTask extends DefaultTask {
}
}

private setProxy(HTTPBuilder http) {
def proxyInfo = ProxyInfoFactory.createFromEnvVar this.env
if (proxyInfo) {
http.setProxy(proxyInfo.httpsProxyHost, proxyInfo.httpsProxyPort, "https")
}
}

void saveJsonToFile(String json, String saveFilePath) {
try {
File reportFile = new File(saveFilePath)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.kt3k.gradle.plugin.coveralls.domain

import groovy.transform.TupleConstructor

@TupleConstructor
class ProxyInfo {
String httpsProxyHost
Integer httpsProxyPort

boolean equals(o) {
if (this.is(o)) return true
if (getClass() != o.class) return false

ProxyInfo proxyInfo = (ProxyInfo) o

if (httpsProxyHost != proxyInfo.httpsProxyHost) return false
if (httpsProxyPort != proxyInfo.httpsProxyPort) return false

return true
}

int hashCode() {
int result
result = 31 * result + (httpsProxyHost != null ? httpsProxyHost.hashCode() : 0)
result = 31 * result + (httpsProxyPort != null ? httpsProxyPort.hashCode() : 0)
return result
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.kt3k.gradle.plugin.coveralls.domain

import org.gradle.api.logging.Logger
import org.gradle.api.logging.Logging


class ProxyInfoFactory {

public static ProxyInfo createFromEnvVar(Map<String, String> env) {
Logger logger = Logging.getLogger('coveralls-logger')
if (httpsProxySet(env)) {
def host = env.get('https.proxyHost')
def port = env.get('https.proxyPort', "443").toInteger()
logger.info 'Using HTTPS proxy $host:$port'
return new ProxyInfo(
httpsProxyHost: host,
httpsProxyPort: port
)
}
}

private static boolean httpsProxySet(Map<String, String> env) {
env.get('https.proxyHost') != null
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.kt3k.gradle.plugin.coveralls.domain

import org.junit.Test

import static org.junit.Assert.assertEquals

public class ProxyInfoFactoryTest {

@Test
void testCreateFromEnvVarHostAndPort() {
ProxyInfo proxyInfo = ProxyInfoFactory
.createFromEnvVar('https.proxyHost': 'some host',
'https.proxyPort': '8080')
assertEquals 'some host', proxyInfo.httpsProxyHost
assertEquals 8080, proxyInfo.httpsProxyPort
}

@Test
void testCreateFromEnvVarHostAndDefaultPort() {
ProxyInfo proxyInfo = ProxyInfoFactory
.createFromEnvVar('https.proxyHost': 'some host')
assertEquals 'some host', proxyInfo.httpsProxyHost
assertEquals 443, proxyInfo.httpsProxyPort
}

@Test
void testCreateFromEnvVarNoHost() {
ProxyInfo proxyInfo = ProxyInfoFactory
.createFromEnvVar [:]
assert proxyInfo == null
}

@Test
void testCreateFromEnvVarOnlyPort() {
ProxyInfo proxyInfo = ProxyInfoFactory
.createFromEnvVar('https.proxyPort': '8080')
assert proxyInfo == null
}
}