Skip to content

Commit

Permalink
Merge pull request #37 from kevmoo/i34_coveralls_service_name_travis
Browse files Browse the repository at this point in the history
Populate service_name and service_job_id for Travis
  • Loading branch information
adracus committed May 29, 2015
2 parents eeb6c39 + 888e820 commit cc0b4c3
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 41 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,13 @@
### 0.3.0

* `serviceName` was removed from `CommandLineClient`.

* `serviceName` and `serviceJobId` are now named paramaters on `CoverallsReport`
– constructor and `parse`.

* `service_name` and `service_job_id` are correctly populated form Travis and
Coveralls.

### 0.2.0

* A number of (breaking) changes to clarify and correctly distinguish between
Expand Down
30 changes: 13 additions & 17 deletions lib/src/cli_client.dart
Expand Up @@ -12,15 +12,14 @@ import 'coveralls_endpoint.dart';
import 'coveralls_entities.dart';
import 'log.dart';
import 'process_system.dart';
import 'services/travis.dart' as travis;

class CommandLineClient {
final String projectDirectory;
final String packageRoot;
final String token;
final String serviceName;

CommandLineClient._(
this.projectDirectory, this.packageRoot, this.token, this.serviceName);
CommandLineClient._(this.projectDirectory, this.packageRoot, this.token);

factory CommandLineClient({String projectDirectory, String packageRoot,
String token, Map<String, String> environment}) {
Expand All @@ -30,11 +29,9 @@ class CommandLineClient {

packageRoot = _calcPackageRoot(projectDirectory, packageRoot);

var serviceName = getServiceName(environment);
token = getToken(token, environment);

return new CommandLineClient._(
projectDirectory, packageRoot, token, serviceName);
return new CommandLineClient._(projectDirectory, packageRoot, token);
}

Future<CoverageResult<String>> getLcovResult(String testFile,
Expand All @@ -56,13 +53,6 @@ class CommandLineClient {
return environment["REPO_TOKEN"];
}

static String getServiceName([Map<String, String> environment]) {
if (null == environment) environment = Platform.environment;
var serviceName = environment["COVERALLS_SERVICE_NAME"];
if (serviceName == null) return "local";
return serviceName;
}

Future reportToCoveralls(String testFile, {int workers,
ProcessSystem processSystem: const ProcessSystem(),
String coverallsAddress, bool dryRun: false,
Expand All @@ -73,17 +63,23 @@ class CommandLineClient {

rawLcov.printSummary();
var lcov = LcovDocument.parse(rawLcov.result.toString());
var report = CoverallsReport.parse(
token, lcov, projectDirectory, serviceName,
excludeTestFiles: excludeTestFiles);
var endpoint = new CoverallsEndpoint(coverallsAddress);

var serviceName = travis.getServiceName(Platform.environment);
var serviceJobId = travis.getServiceJobId(Platform.environment);

var report = CoverallsReport.parse(token, lcov, projectDirectory,
excludeTestFiles: excludeTestFiles,
serviceName: serviceName,
serviceJobId: serviceJobId);

if (printJson) {
print(const JsonEncoder.withIndent(' ').convert(report));
}

if (dryRun) return;

var endpoint = new CoverallsEndpoint(coverallsAddress);

try {
var encoded = JSON.encode(report);
await _sendLoop(endpoint, encoded, retry: retry);
Expand Down
37 changes: 25 additions & 12 deletions lib/src/coveralls_entities.dart
Expand Up @@ -237,25 +237,38 @@ class CoverallsReport {
final GitData gitData;
final SourceFileReports sourceFileReports;
final String serviceName;
final String serviceJobId;

CoverallsReport(
this.repoToken, this.sourceFileReports, this.gitData, this.serviceName);
CoverallsReport(this.repoToken, this.sourceFileReports, this.gitData,
{this.serviceName, this.serviceJobId});

static CoverallsReport parse(String repoToken, LcovDocument lcov,
String projectDirectory, String serviceName,
{bool excludeTestFiles: false}) {
static CoverallsReport parse(
String repoToken, LcovDocument lcov, String projectDirectory,
{String serviceName, String serviceJobId, bool excludeTestFiles: false}) {
var gitData = GitData.getGitData(new Directory(projectDirectory));
var reports = SourceFileReports.parse(lcov, projectDirectory,
excludeTestFiles: excludeTestFiles);
return new CoverallsReport(repoToken, reports, gitData, serviceName);
return new CoverallsReport(repoToken, reports, gitData,
serviceName: serviceName, serviceJobId: serviceJobId);
}

Map toJson() => {
"repo_token": repoToken,
"git": gitData,
"service_name": serviceName,
"source_files": sourceFileReports.sourceFileReports.toList()
};
Map toJson() {
var data = <String, dynamic>{
"repo_token": repoToken,
"git": gitData,
"source_files": sourceFileReports.sourceFileReports.toList()
};

if (serviceName != null) {
data['service_name'] = serviceName;
}

if (serviceJobId != null) {
data['service_job_id'] = serviceJobId;
}

return data;
}
}

/// Yields the Dart files represented by [entity].
Expand Down
7 changes: 5 additions & 2 deletions lib/src/git_data.dart
Expand Up @@ -3,6 +3,7 @@ library dart_coveralls.git_data;
import 'dart:io' show Directory, ProcessException, Platform;

import 'log.dart';
import 'services/travis.dart' as travis;
import 'process_system.dart';

abstract class GitPerson {
Expand Down Expand Up @@ -129,8 +130,10 @@ class GitBranch {
Map<String, String> environment}) {
if (null == environment) environment = Platform.environment;
if (null != environment["CI_BRANCH"]) return environment["CI_BRANCH"];
if (null != environment["TRAVIS_BRANCH"]) return environment[
"TRAVIS_BRANCH"];

var travisBranch = travis.getBranch(environment);
if (travisBranch != null) return travisBranch;

var args = ["rev-parse", "--abbrev-ref", "HEAD"];
var result =
processSystem.runProcessSync("git", args, workingDirectory: dir.path);
Expand Down
18 changes: 18 additions & 0 deletions lib/src/services/travis.dart
@@ -0,0 +1,18 @@
library coveralls_dart.src.services.travis;

/// Returns the current branch name for the provided [environment] as defined
/// by Travis.
///
/// If none exists, return `null`.
String getBranch(Map<String, String> environment) =>
environment["TRAVIS_BRANCH"];

/// Following the coveralls conventions
/// See https://coveralls.zendesk.com/hc/en-us/articles/201774865-API-Introduction
String getServiceName(Map<String, String> environment) =>
(environment['TRAVIS'] == 'true') ? 'travis-ci' : null;

/// Following the coveralls conventions
/// See https://coveralls.zendesk.com/hc/en-us/articles/201774865-API-Introduction
String getServiceJobId(Map<String, String> environment) =>
environment['TRAVIS_JOB_ID'];
2 changes: 1 addition & 1 deletion pubspec.yaml
@@ -1,5 +1,5 @@
name: dart_coveralls
version: 0.2.0
version: 0.3.0-dev
author: Axel Christ <adracus@gmail.com>
description: |-
Pub package to calculate coverage, format it
Expand Down
9 changes: 0 additions & 9 deletions test/coveralls_test.dart
Expand Up @@ -83,15 +83,6 @@ void main() {
});

group("CommandLineClient", () {
test("getServiceName", () {
var s1 = CommandLineClient.getServiceName();
var s2 =
CommandLineClient.getServiceName({"COVERALLS_SERVICE_NAME": "name"});

expect(s1, equals("local"));
expect(s2, equals("name"));
});

group("getToken", () {
test("with candidate", () {
var t1 = CommandLineClient.getToken("test");
Expand Down

0 comments on commit cc0b4c3

Please sign in to comment.