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

Commit

Permalink
Allow custom yaml file. (#107)
Browse files Browse the repository at this point in the history
* Add tests for custom `yaml`

* Allow custom `yaml` file

* Cleans missing variable

* Add `yml` as cli argument.

* rename `yml` cli argument to `y`
This to keep it consistent.

* Updates `bin` to receive `y` argument

* Rename `y` cli back to `yml`.
Added short name as `y`
  • Loading branch information
victorhqc authored and eddiemoore committed Aug 21, 2018
1 parent 77d7a5e commit 1fff4dc
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
3 changes: 2 additions & 1 deletion bin/codecov
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ var args = argv.option([
{name: 'slug', short: 'r', type: 'string', description: "Specify repository slug for Enterprise ex. owner/repo"},
{name: 'url', short: 'u', type: 'string', description: "Your Codecov endpoint"},
{name: 'flags', short: 'F', type: 'string', description: "Codecov Flags"},
{name: 'dump', type: 'boolean', description: "Dump collected data and do not send to Codecov"}
{name: 'dump', type: 'boolean', description: "Dump collected data and do not send to Codecov"},
{name: 'yml', short: 'y', type: 'string', description: "Configuration file Used to specify the location of the .codecov.yml config file. Defaults to codecov.yml and .codecov.yml"}
]).run();

codecov.upload(args);
7 changes: 6 additions & 1 deletion lib/codecov.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ var upload = function(args, on_success, on_failure) {
'https://codecov.io'
var query = {}
var debug = []
var yamlFile =
args.options.yml ||
process.env.codecov_yml ||
process.env.CODECOV_YML ||
'codecov.yml'

console.log(
'' +
Expand All @@ -253,7 +258,7 @@ var upload = function(args, on_success, on_failure) {
version
)

query.yaml = ['codecov.yml', '.codecov.yml'].reduce(function(result, file) {
query.yaml = [yamlFile, '.codecov.yml'].reduce(function(result, file) {
return (
result ||
(fs.existsSync(path.resolve(process.cwd(), file)) ? file : undefined)
Expand Down
31 changes: 31 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,35 @@ describe('Codecov', function() {
var version = require('../package.json').version
expect(codecov.version).to.eql('v' + version)
})

it('Should use codecov.yml via env variable', function() {
expect(
codecov.upload({ options: { dump: true, disable: 'detect' } }).query.yaml
).to.eql('codecov.yml')

fs.writeFileSync('foo.yml', '')
process.env.codecov_yml = 'foo.yml'
expect(
codecov.upload({ options: { dump: true, disable: 'detect' } }).query.yaml
).to.eql('foo.yml')
fs.unlinkSync('foo.yml')
delete process.env.codecov_yml

fs.writeFileSync('FOO.yml', '')
process.env.CODECOV_YML = 'FOO.yml'
expect(
codecov.upload({ options: { dump: true, disable: 'detect' } }).query.yaml
).to.eql('FOO.yml')
fs.unlinkSync('FOO.yml')
delete process.env.CODECOV_YML
})

it('can get config from cli args', function() {
fs.writeFileSync('foo.yml', '')
var res = codecov.upload({
options: { dump: true, yml: 'foo.yml', disable: 'detect' },
})
expect(res.query.yaml).to.eql('foo.yml')
fs.unlinkSync('foo.yml')
})
})

0 comments on commit 1fff4dc

Please sign in to comment.