diff --git a/src/main/groovy/org/kt3k/gradle/plugin/coveralls/domain/ServiceInfoFactory.groovy b/src/main/groovy/org/kt3k/gradle/plugin/coveralls/domain/ServiceInfoFactory.groovy index 89ec9ed..711db16 100644 --- a/src/main/groovy/org/kt3k/gradle/plugin/coveralls/domain/ServiceInfoFactory.groovy +++ b/src/main/groovy/org/kt3k/gradle/plugin/coveralls/domain/ServiceInfoFactory.groovy @@ -130,6 +130,17 @@ class ServiceInfoFactory { 'commit_sha' : env.get('GITHUB_SHA') ] ) + } else if (envIsDrone(env)) { + return new ServiceInfo( + serviceName: 'drone', + serviceNumber: env.get('DRONE_BUILD_NUMBER'), + serviceBranch: env.get('DRONE_BRANCH'), + repoToken: env.get('COVERALLS_REPO_TOKEN'), + servicePullRequest: env.get('DRONE_PULL_REQUEST'), + environment: [ + 'branch' : env.get('DRONE_BRANCH'), + 'commit_sha': env.get('DRONE_COMMIT_SHA')] + ) } else { return new ServiceInfo( serviceName: env['CI_NAME'] ?: 'other', @@ -182,6 +193,11 @@ class ServiceInfoFactory { env.get('GITHUB_ACTIONS') != null } + private static boolean envIsDrone(Map env) { + env.get('DRONE') != null + } + + private static boolean repoTokenIsSet(Map env) { env.get('COVERALLS_REPO_TOKEN') != null } diff --git a/src/test/groovy/org/kt3k/gradle/plugin/coveralls/domain/ServiceInfoFactoryTest.groovy b/src/test/groovy/org/kt3k/gradle/plugin/coveralls/domain/ServiceInfoFactoryTest.groovy index 6c242d7..e698c1e 100644 --- a/src/test/groovy/org/kt3k/gradle/plugin/coveralls/domain/ServiceInfoFactoryTest.groovy +++ b/src/test/groovy/org/kt3k/gradle/plugin/coveralls/domain/ServiceInfoFactoryTest.groovy @@ -255,4 +255,26 @@ class ServiceInfoFactoryTest { assertEquals '8eee24aac46ace5cd156d351062dfce68e57e49e', serviceInfo.environment['commit_sha'] } + @Test + void testCreateFromEnvVarDrone() { + // test the case of drone + ServiceInfo serviceInfo = ServiceInfoFactory.createFromEnvVar( + DRONE: "true", + DRONE_BUILD_NUMBER: "123456789", + DRONE_BRANCH: "branchX", + DRONE_PULL_REQUEST: "11", + DRONE_COMMIT_SHA: "231asdfadsf424", + COVERALLS_REPO_TOKEN: 'ABCDEF' + ) + + assertEquals 'drone', serviceInfo.serviceName + assertEquals '123456789', serviceInfo.serviceNumber + assertEquals 'branchX', serviceInfo.serviceBranch + assertEquals 'ABCDEF', serviceInfo.repoToken + assertEquals '11', serviceInfo.servicePullRequest + + assertEquals 'branchX', serviceInfo.environment['branch'] + assertEquals '231asdfadsf424', serviceInfo.environment['commit_sha'] + } + }