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

Update module to use the submission API wrapper #13

Merged
merged 3 commits into from
Aug 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions bin/tc-submission-cli.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ process.env.NODE_CONFIG_DIR = `${__dirname}/../config/`
const program = require('commander')
const uploadSubmissionService = require('../src/services/uploadSubmissionService')
const logger = require('../src/common/logger')
const _ = require('lodash')
const fs = require('fs')

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

uploadSubmissionService.smart(process.cwd())
.then(() => {
logger.info('done!')
.then(async (responses) => {
const log = {}
_.each(responses, response => {
const resp = JSON.parse(response.text)
const submissionId = _.get(resp, 'id', undefined)
const challengeId = _.get(resp, 'challengeId', undefined)
if (submissionId && challengeId) {
if (log[challengeId]) {
log[challengeId].push(submissionId)
} else {
log[challengeId] = [submissionId]
}
}
})
const logTxt = _.join(_.map(_.keys(log), key => `challenge_${key}:\t${log[key]}`), '\n')
logger.info(`Uploaded submissions:\n${logTxt}`)
await fs.writeFileSync('topcoder-cli.log',
`${Date.now()}:\n${logTxt}\n\n`,
{ flag: 'a' })
logger.info('Completed!')
process.exit()
})
.catch(err => {
Expand Down
10 changes: 5 additions & 5 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

module.exports = {
LOG_LEVEL: process.env.LOG_LEVEL || 'info',
TC_MEMBERS_API: process.env.TC_MEMBERS_API || 'https://api.topcoder.com/v3/members',
SUBMISSION_API_URL: process.env.TEST_SUBMISSION_API_URL || 'https://api.topcoder.com/v5/submissions',
TC_AUTHN_URL: process.env.TC_AUTHN_URL || 'https://topcoder.auth0.com/oauth/ro',
TC_AUTHZ_URL: process.env.TC_AUTHZ_URL || 'https://api.topcoder.com/v3/authorizations',
TC_CLIENT_ID: process.env.TC_CLIENT_ID || '6ZwZEUo2ZK4c50aLPpgupeg5v2Ffxp9P', // for dev 'JFDo7HMkf0q2CkVFHojy3zHWafziprhT',
TC_MEMBERS_API: process.env.TC_MEMBERS_API || 'https://api.topcoder-dev.com/v3/members',
SUBMISSION_API_URL: process.env.TEST_SUBMISSION_API_URL || 'https://api.topcoder-dev.com/v5',
TC_AUTHN_URL: process.env.TC_AUTHN_URL || 'https://topcoder-dev.auth0.com/oauth/ro',
TC_AUTHZ_URL: process.env.TC_AUTHZ_URL || 'https://api.topcoder-dev.com/v3/authorizations',
TC_CLIENT_ID: process.env.TC_CLIENT_ID || 'JFDo7HMkf0q2CkVFHojy3zHWafziprhT', // for dev 'JFDo7HMkf0q2CkVFHojy3zHWafziprhT',
TC_CLIENT_V2CONNECTION: process.env.CLIENT_V2CONNECTION || 'TC-User-Database'
}
2 changes: 1 addition & 1 deletion docs/Development.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The following parameters can be set in config files or in env variables:
| Property | Environment varible | Default value | Description |
| --- | --- | --- | --- |
| LOG_LEVEL | LOG_LEVEL | info | control log level |
| SUBMISSION_API_URL | TEST_SUBMISSION_API_URL | https://api.topcoder.com/v5/submissions | the TC submission API URL |
| SUBMISSION_API_URL | TEST_SUBMISSION_API_URL | https://api.topcoder.com/v5 | the TC submission API URL |
| TC_AUTHN_URL | TC_AUTHN_URL | https://topcoder.auth0.com/oauth/ro | API that is used to fetch JWT token v2 |
| TC_AUTHZ_URL | TC_AUTHZ_URL | https://api.topcoder.com/v3/authorizations | API that is used to fetch JWT token v3 |
| TC_CLIENT_ID | TC_CLIENT_ID | 6ZwZEUo2ZK4c50aLPpgupeg5v2Ffxp9P | TC client ID |
Expand Down
Loading