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 171e04c..f28dae2 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 @@ -24,11 +24,19 @@ class ServiceInfoFactory { 'travis_pull_request': env.get('TRAVIS_PULL_REQUEST')] ) } else if (envIsCircleci(env)) { + String prId = env.get('CI_PULL_REQUEST') + if (prId != null) { + // CircleCI CI_PULL_REQUEST is the full URL, so extract just the PR number + int lastSlashIdx = prId.lastIndexOf('/') + if (lastSlashIdx > -1 && lastSlashIdx + 1 < prId.length()) { + prId = prId.substring(lastSlashIdx + 1) + } + } return new ServiceInfo( serviceName: 'circleci', serviceNumber: env.get('CIRCLE_BUILD_NUM'), repoToken: env.get('COVERALLS_REPO_TOKEN'), - servicePullRequest: env.get('CI_PULL_REQUEST'), + servicePullRequest: prId, environment: [ 'circleci_build_num': env.get('CIRCLE_BUILD_NUM'), 'branch' : env.get('CIRCLE_BRANCH'), 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 36c4fa6..a175217 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 @@ -72,14 +72,14 @@ class ServiceInfoFactoryTest { CIRCLECI: 'true', CIRCLE_BUILD_NUM: '12345678', COVERALLS_REPO_TOKEN: 'ABCDEF', - CI_PULL_REQUEST: 'pullrequest111', + CI_PULL_REQUEST: 'https://github.com/kt3k/coveralls-gradle-plugin/pull/51', CIRCLE_BRANCH: 'branchX', CIRCLE_SHA1: '231asdfadsf424') assertEquals 'circleci', serviceInfo.serviceName assertEquals '12345678', serviceInfo.serviceNumber assertEquals 'ABCDEF', serviceInfo.repoToken - assertEquals 'pullrequest111', serviceInfo.servicePullRequest + assertEquals '51', serviceInfo.servicePullRequest assertEquals 'branchX', serviceInfo.environment['branch'] assertEquals '231asdfadsf424', serviceInfo.environment['commit_sha'] assertEquals '12345678', serviceInfo.environment['circleci_build_num']