Skip to content

Commit a3fff6f

Browse files
authored
Merge pull request #256 from codecov/fix-codecov-token
fix: Token should be codecov.token and update symlinks
2 parents 814b881 + 8a4330f commit a3fff6f

File tree

8 files changed

+43
-11
lines changed

8 files changed

+43
-11
lines changed

npm-shrinkwrap.json

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/helpers/files.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ function getAllFiles(projectRoot, dirPath, args, arrayOfFiles = []) {
237237
if (isBlacklisted(projectRoot, file, manualBlacklist())) {
238238
return
239239
}
240-
if (fs.statSync(path.join(dirPath, file)).isDirectory()) {
240+
if (fs.lstatSync(path.join(dirPath, file)).isDirectory()) {
241241
arrayOfFiles = getAllFiles(
242242
projectRoot,
243243
path.join(dirPath, file),

src/helpers/token.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,18 @@ function getTokenFromYaml(projectRoot, args) {
5050
})
5151
const yamlConfig = yaml.load(fileContents)
5252
if (
53-
yamlConfig['codecov_token'] &&
54-
validateHelpers.validateToken(yamlConfig['codecov_token'])
53+
yamlConfig['codecov'] &&
54+
yamlConfig['codecov']['token'] &&
55+
validateHelpers.validateToken(yamlConfig['codecov']['token'])
5556
) {
56-
return yamlConfig['codecov_token']
57+
return yamlConfig['codecov']['token']
58+
}
59+
60+
if (yamlConfig['codecov_token']) {
61+
error(
62+
`'codecov_token' is a deprecated field. Please switch to 'codecov.token' ` +
63+
'(https://docs.codecov.com/docs/codecovyml-reference#codecovtoken)'
64+
)
5765
}
5866
}
5967
} catch (err) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
codecov_token: faketoken

test/fixtures/yaml/.codecov.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
codecov_token: invalid token
1+
codecov:
2+
token: invalid token

test/fixtures/yaml/codecov.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
codecov_token: faketoken
1+
codecov:
2+
token: faketoken

test/fixtures/yaml/codecov.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
codecov_token: anotherfaketoken
1+
codecov:
2+
token: anotherfaketoken

test/helpers/token.test.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const path = require('path')
2+
const { expect, it } = require('@jest/globals')
23

34
const fileHelpers = require('../../src/helpers/files')
45
const tokenHelpers = require('../../src/helpers/token')
@@ -8,7 +9,15 @@ describe('Get tokens', () => {
89
fileHelpers.fetchGitRoot(),
910
'test/fixtures/yaml',
1011
)
11-
console.log(fixturesDir)
12+
const invalidFixturesDir = path.join(
13+
fileHelpers.fetchGitRoot(),
14+
'test/fixtures/invalid_yaml',
15+
)
16+
17+
afterEach(() => {
18+
jest.clearAllMocks()
19+
})
20+
1221
describe('From yaml', () => {
1322
it('Returns empty with no yaml file', () => {
1423
expect(tokenHelpers.getTokenFromYaml('.')).toBe('')
@@ -19,6 +28,19 @@ describe('Get tokens', () => {
1928
tokenHelpers.getTokenFromYaml(fixturesDir, { verbose: true }),
2029
).toBe('faketoken')
2130
})
31+
32+
it('Returns deprecation error from codecov_token', () => {
33+
jest.spyOn(console, 'error').mockImplementation(() => {
34+
// Intentionally empty
35+
})
36+
expect(
37+
tokenHelpers.getTokenFromYaml(invalidFixturesDir, { verbose: true }),
38+
).toBe('')
39+
40+
expect(console.error).toHaveBeenCalledWith(
41+
expect.stringContaining("'codecov_token' is a deprecated field"),
42+
)
43+
})
2244
})
2345

2446
describe('From right source', () => {

0 commit comments

Comments
 (0)