From 74a44f2da6393820e5a19887010edebd90c33ad4 Mon Sep 17 00:00:00 2001 From: Steve Peak Date: Thu, 30 Mar 2017 09:29:52 -0400 Subject: [PATCH] added -C to unlink reports after uploading --- bin/codecov | 1 + lib/codecov.js | 16 +++++++++++++++- test/upload.js | 42 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/bin/codecov b/bin/codecov index ff9da26f..15f63da1 100755 --- a/bin/codecov +++ b/bin/codecov @@ -14,6 +14,7 @@ var args = argv.option([ {name: 'gcov-args', type: 'string', description: "extra arguments to pass to gcov"}, {name: 'disable', short: 'X', type: 'string', description: "Disable features. Accepting `search` to disable crawling through directories, `detect` to disable detecting CI provider, `gcov` disable gcov commands"}, {name: 'commit', short: 'c', type: 'string', description: "Commit sha, set automatically"}, + {name: 'clear', short: 'C', type: 'boolean', description: "Remove all discovered reports after uploading"}, {name: 'branch', short: 'b', type: 'string', description: "Branch name"}, {name: 'build', short: 'B', type: 'string', description: "Specify a custom build number to distinguish ci jobs, provided automatically for supported ci companies"}, {name: 'slug', short: 'r', type: 'string', description: "Specify repository slug for Enterprise ex. owner/repo"}, diff --git a/lib/codecov.js b/lib/codecov.js index c547e3db..052632ef 100644 --- a/lib/codecov.js +++ b/lib/codecov.js @@ -288,7 +288,21 @@ var upload = function(args, on_success, on_failure){ } else { console.log('==> Uploading reports'); - sendToCodecovV3(codecov_endpoint, query, upload, on_success || function(){}, on_failure || function(){}); + sendToCodecovV3(codecov_endpoint, query, upload, + function(){ + // remove files after Uploading + if (args.options.clear) { + for (var i = files.length - 1; i >= 0; i--) { + try { + fs.unlinkSync(files[i]); + } catch (e) {} + } + } + if (on_success) { + on_success.apply(this, arguments); + } + }, + on_failure || function(){}); } } diff --git a/test/upload.js b/test/upload.js index 4eb099de..97f792da 100644 --- a/test/upload.js +++ b/test/upload.js @@ -3,6 +3,18 @@ var codecov = require('../lib/codecov'); var offlineErrors = require('../lib/offline'); describe("Codecov", function(){ + beforeEach(function(){ + try { + fs.unlinkSync('report.tmp'); + } catch (e) {} + }); + + after(function(){ + try { + fs.unlinkSync('report.tmp'); + } catch (e) {} + }); + it("can get upload to v2", function(done){ var self = this; codecov.sendToCodecovV2('https://codecov.io', @@ -25,6 +37,34 @@ describe("Codecov", function(){ }); }); + it("can remove files after uploading", function(done){ + fs.writeFileSync('report.tmp', ''); + expect(fs.exists('report.tmp')).to.be.true; + + var self = this; + codecov.sendToCodecovV2('https://codecov.io', + { + token: 'f881216b-b5c0-4eb1-8f21-b51887d1d506', + commit: 'c739768fcac68144a3a6d82305b9c4106934d31a', + file: 'report.tmp', + clear: true, + branch: 'master' + }, + 'testing node-'+codecov.version, + function(body){ + expect(body).to.contain('https://codecov.io/github/codecov/ci-repo/commit/c739768fcac68144a3a6d82305b9c4106934d31a'); + expect(fs.exists('report.tmp')).to.be.false; + done(); + }, + function(errCode, errMsg){ + if(offlineErrors.indexOf(errCode) !== -1){ + self.skip(); // offline - we can not test upload + return; + } + throw new Error(errMsg); + }); + }); + it("can get upload to v3", function(done){ var self = this; this.timeout(3000); // give this test extra time to run (default is 2000ms) @@ -68,6 +108,6 @@ describe("Codecov", function(){ throw new Error(errMsg); } )).to.not.throwException(); - }) + }); });