Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit f8f2054

Browse files
Merge pull request #13 from topcoder-platform/use-api-wrapper
Update module to use the submission API wrapper
2 parents 914d579 + 11ff818 commit f8f2054

File tree

9 files changed

+989
-153
lines changed

9 files changed

+989
-153
lines changed

bin/tc-submission-cli.js

100644100755
Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ process.env.NODE_CONFIG_DIR = `${__dirname}/../config/`
44
const program = require('commander')
55
const uploadSubmissionService = require('../src/services/uploadSubmissionService')
66
const logger = require('../src/common/logger')
7+
const _ = require('lodash')
8+
const fs = require('fs')
79

810
program.on('--help', () => {
911
console.log(`\nTopcoder CLI to create a new submission in the challenge
@@ -23,8 +25,26 @@ program.on('--help', () => {
2325
program.parse(process.argv)
2426

2527
uploadSubmissionService.smart(process.cwd())
26-
.then(() => {
27-
logger.info('done!')
28+
.then(async (responses) => {
29+
const log = {}
30+
_.each(responses, response => {
31+
const resp = JSON.parse(response.text)
32+
const submissionId = _.get(resp, 'id', undefined)
33+
const challengeId = _.get(resp, 'challengeId', undefined)
34+
if (submissionId && challengeId) {
35+
if (log[challengeId]) {
36+
log[challengeId].push(submissionId)
37+
} else {
38+
log[challengeId] = [submissionId]
39+
}
40+
}
41+
})
42+
const logTxt = _.join(_.map(_.keys(log), key => `challenge_${key}:\t${log[key]}`), '\n')
43+
logger.info(`Uploaded submissions:\n${logTxt}`)
44+
await fs.writeFileSync('topcoder-cli.log',
45+
`${Date.now()}:\n${logTxt}\n\n`,
46+
{ flag: 'a' })
47+
logger.info('Completed!')
2848
process.exit()
2949
})
3050
.catch(err => {

config/default.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
module.exports = {
66
LOG_LEVEL: process.env.LOG_LEVEL || 'info',
7-
TC_MEMBERS_API: process.env.TC_MEMBERS_API || 'https://api.topcoder.com/v3/members',
8-
SUBMISSION_API_URL: process.env.TEST_SUBMISSION_API_URL || 'https://api.topcoder.com/v5/submissions',
9-
TC_AUTHN_URL: process.env.TC_AUTHN_URL || 'https://topcoder.auth0.com/oauth/ro',
10-
TC_AUTHZ_URL: process.env.TC_AUTHZ_URL || 'https://api.topcoder.com/v3/authorizations',
11-
TC_CLIENT_ID: process.env.TC_CLIENT_ID || '6ZwZEUo2ZK4c50aLPpgupeg5v2Ffxp9P', // for dev 'JFDo7HMkf0q2CkVFHojy3zHWafziprhT',
7+
TC_MEMBERS_API: process.env.TC_MEMBERS_API || 'https://api.topcoder-dev.com/v3/members',
8+
SUBMISSION_API_URL: process.env.TEST_SUBMISSION_API_URL || 'https://api.topcoder-dev.com/v5',
9+
TC_AUTHN_URL: process.env.TC_AUTHN_URL || 'https://topcoder-dev.auth0.com/oauth/ro',
10+
TC_AUTHZ_URL: process.env.TC_AUTHZ_URL || 'https://api.topcoder-dev.com/v3/authorizations',
11+
TC_CLIENT_ID: process.env.TC_CLIENT_ID || 'JFDo7HMkf0q2CkVFHojy3zHWafziprhT', // for dev 'JFDo7HMkf0q2CkVFHojy3zHWafziprhT',
1212
TC_CLIENT_V2CONNECTION: process.env.CLIENT_V2CONNECTION || 'TC-User-Database'
1313
}

docs/Development.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The following parameters can be set in config files or in env variables:
1212
| Property | Environment varible | Default value | Description |
1313
| --- | --- | --- | --- |
1414
| LOG_LEVEL | LOG_LEVEL | info | control log level |
15-
| SUBMISSION_API_URL | TEST_SUBMISSION_API_URL | https://api.topcoder.com/v5/submissions | the TC submission API URL |
15+
| SUBMISSION_API_URL | TEST_SUBMISSION_API_URL | https://api.topcoder.com/v5 | the TC submission API URL |
1616
| TC_AUTHN_URL | TC_AUTHN_URL | https://topcoder.auth0.com/oauth/ro | API that is used to fetch JWT token v2 |
1717
| TC_AUTHZ_URL | TC_AUTHZ_URL | https://api.topcoder.com/v3/authorizations | API that is used to fetch JWT token v3 |
1818
| TC_CLIENT_ID | TC_CLIENT_ID | 6ZwZEUo2ZK4c50aLPpgupeg5v2Ffxp9P | TC client ID |

0 commit comments

Comments
 (0)