Skip to content

Commit

Permalink
Merge pull request #256 from codecov/fix-codecov-token
Browse files Browse the repository at this point in the history
fix: Token should be codecov.token and update symlinks
  • Loading branch information
thomasrockhu authored Jul 26, 2021
2 parents 814b881 + 8a4330f commit a3fff6f
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 11 deletions.
4 changes: 1 addition & 3 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/helpers/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ function getAllFiles(projectRoot, dirPath, args, arrayOfFiles = []) {
if (isBlacklisted(projectRoot, file, manualBlacklist())) {
return
}
if (fs.statSync(path.join(dirPath, file)).isDirectory()) {
if (fs.lstatSync(path.join(dirPath, file)).isDirectory()) {
arrayOfFiles = getAllFiles(
projectRoot,
path.join(dirPath, file),
Expand Down
14 changes: 11 additions & 3 deletions src/helpers/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,18 @@ function getTokenFromYaml(projectRoot, args) {
})
const yamlConfig = yaml.load(fileContents)
if (
yamlConfig['codecov_token'] &&
validateHelpers.validateToken(yamlConfig['codecov_token'])
yamlConfig['codecov'] &&
yamlConfig['codecov']['token'] &&
validateHelpers.validateToken(yamlConfig['codecov']['token'])
) {
return yamlConfig['codecov_token']
return yamlConfig['codecov']['token']
}

if (yamlConfig['codecov_token']) {
error(
`'codecov_token' is a deprecated field. Please switch to 'codecov.token' ` +
'(https://docs.codecov.com/docs/codecovyml-reference#codecovtoken)'
)
}
}
} catch (err) {
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/invalid_yaml/codecov.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
codecov_token: faketoken
3 changes: 2 additions & 1 deletion test/fixtures/yaml/.codecov.yml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
codecov_token: invalid token
codecov:
token: invalid token
3 changes: 2 additions & 1 deletion test/fixtures/yaml/codecov.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
codecov_token: faketoken
codecov:
token: faketoken
3 changes: 2 additions & 1 deletion test/fixtures/yaml/codecov.yml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
codecov_token: anotherfaketoken
codecov:
token: anotherfaketoken
24 changes: 23 additions & 1 deletion test/helpers/token.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const path = require('path')
const { expect, it } = require('@jest/globals')

const fileHelpers = require('../../src/helpers/files')
const tokenHelpers = require('../../src/helpers/token')
Expand All @@ -8,7 +9,15 @@ describe('Get tokens', () => {
fileHelpers.fetchGitRoot(),
'test/fixtures/yaml',
)
console.log(fixturesDir)
const invalidFixturesDir = path.join(
fileHelpers.fetchGitRoot(),
'test/fixtures/invalid_yaml',
)

afterEach(() => {
jest.clearAllMocks()
})

describe('From yaml', () => {
it('Returns empty with no yaml file', () => {
expect(tokenHelpers.getTokenFromYaml('.')).toBe('')
Expand All @@ -19,6 +28,19 @@ describe('Get tokens', () => {
tokenHelpers.getTokenFromYaml(fixturesDir, { verbose: true }),
).toBe('faketoken')
})

it('Returns deprecation error from codecov_token', () => {
jest.spyOn(console, 'error').mockImplementation(() => {
// Intentionally empty
})
expect(
tokenHelpers.getTokenFromYaml(invalidFixturesDir, { verbose: true }),
).toBe('')

expect(console.error).toHaveBeenCalledWith(
expect.stringContaining("'codecov_token' is a deprecated field"),
)
})
})

describe('From right source', () => {
Expand Down

0 comments on commit a3fff6f

Please sign in to comment.