Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
added -C to unlink reports after uploading
Browse files Browse the repository at this point in the history
  • Loading branch information
stevepeak committed Mar 30, 2017
1 parent d1bf5e4 commit 74a44f2
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
1 change: 1 addition & 0 deletions bin/codecov
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
16 changes: 15 additions & 1 deletion lib/codecov.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(){});
}
}

Expand Down
42 changes: 41 additions & 1 deletion test/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -25,6 +37,34 @@ describe("Codecov", function(){
});
});

it("can remove files after uploading", function(done){
fs.writeFileSync('report.tmp', '<content>');
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)
Expand Down Expand Up @@ -68,6 +108,6 @@ describe("Codecov", function(){
throw new Error(errMsg);
}
)).to.not.throwException();
})
});

});

1 comment on commit 74a44f2

@eddiemoore
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Please sign in to comment.