Skip to content

Commit 92e98bd

Browse files
Merge branch 'master' into better-log
2 parents 16f2f55 + 300eb11 commit 92e98bd

File tree

9 files changed

+124
-7
lines changed

9 files changed

+124
-7
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ jobs:
395395
- release_tag
396396
release:
397397
docker:
398-
- image: google/cloud-sdk:348.0.0-slim
398+
- image: google/cloud-sdk:349.0.0-slim
399399
steps:
400400
- attach_workspace:
401401
# Must be absolute path or relative path from working_directory

src/ci_providers/provider_local.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ function _getBuildURL(inputs) {
1818

1919
function _getBranch(inputs) {
2020
const { args } = inputs
21+
if (args.branch) {
22+
return args.branch
23+
}
2124
try {
2225
const branchName = childprocess
2326
.spawnSync('git', ['rev-parse', '--abbrev-ref', 'HEAD'])
2427
.stdout.toString()
2528
.trimRight()
26-
return args.branch || branchName
29+
return branchName
2730
} catch (error) {
2831
logAndThrow(`There was an error getting the branch name from git: ${error}`)
2932
}
@@ -52,25 +55,31 @@ function getServiceName() {
5255

5356
function _getSHA(inputs) {
5457
const { args } = inputs
58+
if (args.sha) {
59+
return args.sha
60+
}
5561
try {
5662
const sha = childprocess
5763
.spawnSync('git', ['rev-parse', 'HEAD'])
5864
.stdout.toString()
5965
.trimRight()
60-
return args.sha || sha
66+
return sha
6167
} catch (error) {
6268
logAndThrow(`There was an error getting the commit SHA from git: ${error}`)
6369
}
6470
}
6571

6672
function _getSlug(inputs) {
6773
const { args } = inputs
74+
if (args.slug) {
75+
return args.slug
76+
}
6877
try {
6978
const slug = childprocess
7079
.spawnSync('git', ['config', '--get', 'remote.origin.url'])
7180
.stdout.toString()
7281
.trimRight()
73-
return args.slug || parseSlug(slug)
82+
return parseSlug(slug)
7483
} catch (error) {
7584
logAndThrow(`There was an error getting the slug from git: ${error}`)
7685
}

src/ci_providers/provider_teamcity.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const { parseSlugFromRemoteAddr } = require('../helpers/git')
2+
13
function detect(envs) {
24
return !!envs.TEAMCITY_VERSION
35
}
@@ -29,7 +31,7 @@ function _getSHA(inputs) {
2931

3032
function _getSlug(inputs) {
3133
const { args } = inputs
32-
return args.slug || ''
34+
return args.slug || parseSlugFromRemoteAddr('') || ''
3335
}
3436

3537
function _getBuild(inputs) {

src/helpers/validate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const validator = require('validator')
66
* @returns boolean
77
*/
88
function validateToken(token) {
9-
return validator.isAlphanumeric(token)
9+
return validator.isAlphanumeric(token) || validator.isUUID(token)
1010
}
1111

1212
function validateURL(url) {

src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ async function main(args) {
8787

8888
// == Step 3: sanitize and set token
8989
const token = await tokenHelpers.getToken(inputs, projectRoot)
90+
if (token === '') {
91+
log('-> No token specified or token is empty')
92+
}
9093

9194
// == Step 4: get network
9295
let uploadFile = ''

test/helpers/validate.test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ const realEnv = { ...process.env }
55

66
describe('Input Validators', () => {
77
describe('Tokens', () => {
8-
it('Returns true with a valid token', () => {
8+
it('Returns true with a valid alphanumeric token', () => {
99
expect(validate.validateToken('1bc123')).toBe(true)
1010
})
11+
it('Returns true with a valid UUID token', () => {
12+
// Use a randomly generated UUIDv4
13+
expect(validate.validateToken('5becd1a9-efa8-4bd8-8f94-e9f8613820c3')).toBe(true)
14+
})
1115
it('Returns false with an invalid token', () => {
1216
expect(validate.validateToken('1bc1 23')).toBe(false)
1317
})

test/index.test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ const { version } = require('../package.json')
44
const nock = require('nock')
55
const fs = require('fs')
66

7+
// Backup the env
8+
const realEnv = { ...process.env }
9+
710
describe('Uploader Core', () => {
811
const env = process.env
912

@@ -68,6 +71,28 @@ describe('Uploader Core', () => {
6871
expect(log).toHaveBeenCalledWith(expect.stringMatching(/<<<<<< ENV/))
6972
})
7073

74+
describe('Token', () => {
75+
beforeEach(() => {
76+
delete process.env.CODECOV_TOKEN
77+
})
78+
79+
afterEach(() => {
80+
process.env = realEnv
81+
})
82+
83+
it('Can upload without token', async () => {
84+
jest.spyOn(process, 'exit').mockImplementation(() => {})
85+
const log = jest.spyOn(console, 'log').mockImplementation(() => {})
86+
await app.main({
87+
name: 'customname',
88+
url: 'https://codecov.io',
89+
dryRun: true,
90+
env: 'SOMETHING,ANOTHER',
91+
})
92+
expect(log).toHaveBeenCalledWith(expect.stringMatching('-> No token specified or token is empty'))
93+
})
94+
})
95+
7196
describe('Flags', () => {
7297
it('can upload with flags', async () => {
7398
process.env.CI = 'true'

test/providers/provider_local.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,30 @@ describe('Local Params', () => {
3232
})
3333
})
3434

35+
it('returns on override args', () => {
36+
const inputs = {
37+
args: {
38+
branch: 'main',
39+
pr: '1',
40+
sha: 'testingsha',
41+
slug: 'owner/repo',
42+
},
43+
envs: {},
44+
}
45+
const expected = {
46+
branch: 'main',
47+
build: '',
48+
buildURL: '',
49+
commit: 'testingsha',
50+
job: '',
51+
pr: '1',
52+
service: '',
53+
slug: 'owner/repo',
54+
}
55+
const params = providerLocal.getServiceParams(inputs)
56+
expect(params).toMatchObject(expected)
57+
})
58+
3559
it('returns errors on git command failures', () => {
3660
const inputs = {
3761
args: {},

test/providers/provider_teamcity.test.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const td = require('testdouble')
2+
const childProcess = require('child_process')
23

34
const providerTeamCity = require('../../src/ci_providers/provider_teamcity')
45

@@ -51,6 +52,47 @@ describe('TeamCity Params', () => {
5152
service: 'teamcity',
5253
slug: '',
5354
}
55+
const spawnSync = td.replace(childProcess, 'spawnSync')
56+
td.when(
57+
spawnSync('git', [
58+
'config',
59+
'--get',
60+
'remote.origin.url',
61+
]),
62+
).thenReturn({ stdout: '' })
63+
const params = providerTeamCity.getServiceParams(inputs)
64+
expect(params).toMatchObject(expected)
65+
})
66+
67+
it('gets correct params and remote slug', () => {
68+
const inputs = {
69+
args: {},
70+
envs: {
71+
CI: true,
72+
TEAMCITY_VERSION: true,
73+
BRANCH_NAME: 'main',
74+
BUILD_VCS_NUMBER: 'testingsha',
75+
BUILD_NUMBER: 1,
76+
},
77+
}
78+
const expected = {
79+
branch: 'main',
80+
build: 1,
81+
buildURL: '',
82+
commit: 'testingsha',
83+
job: '',
84+
pr: '',
85+
service: 'teamcity',
86+
slug: 'testOrg/testRepo',
87+
}
88+
const spawnSync = td.replace(childProcess, 'spawnSync')
89+
td.when(
90+
spawnSync('git', [
91+
'config',
92+
'--get',
93+
'remote.origin.url',
94+
]),
95+
).thenReturn({ stdout: 'https://github.com/testOrg/testRepo.git' })
5496
const params = providerTeamCity.getServiceParams(inputs)
5597
expect(params).toMatchObject(expected)
5698
})
@@ -72,6 +114,14 @@ describe('TeamCity Params', () => {
72114
BUILD_NUMBER: 1,
73115
},
74116
}
117+
const spawnSync = td.replace(childProcess, 'spawnSync')
118+
td.when(
119+
spawnSync('git', [
120+
'config',
121+
'--get',
122+
'remote.origin.url',
123+
]),
124+
).thenReturn({ stdout: '' })
75125
const expected = {
76126
branch: 'branch',
77127
build: 3,

0 commit comments

Comments
 (0)