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

Commit c1a95e6

Browse files
Winning submission from 30108352
1 parent 4f96a43 commit c1a95e6

26 files changed

+993
-6144
lines changed

.eslintrc.yaml

Lines changed: 0 additions & 1 deletion
This file was deleted.

.gitignore

Lines changed: 144 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,145 @@
1-
.nyc_output
1+
# File created using '.gitignore Generator' for Visual Studio Code: https://bit.ly/vscode-gig
2+
3+
# Created by https://www.gitignore.io/api/visualstudiocode,node,macos
4+
# Edit at https://www.gitignore.io/?templates=visualstudiocode,node,macos
5+
6+
### macOS ###
7+
# General
8+
.DS_Store
9+
.AppleDouble
10+
.LSOverride
11+
12+
# Icon must end with two \r
13+
Icon
14+
15+
# Thumbnails
16+
._*
17+
18+
# Files that might appear in the root of a volume
19+
.DocumentRevisions-V100
20+
.fseventsd
21+
.Spotlight-V100
22+
.TemporaryItems
23+
.Trashes
24+
.VolumeIcon.icns
25+
.com.apple.timemachine.donotpresent
26+
27+
# Directories potentially created on remote AFP share
28+
.AppleDB
29+
.AppleDesktop
30+
Network Trash Folder
31+
Temporary Items
32+
.apdisk
33+
34+
### Node ###
35+
# Logs
36+
logs
37+
*.log
38+
npm-debug.log*
39+
yarn-debug.log*
40+
yarn-error.log*
41+
lerna-debug.log*
42+
43+
# Diagnostic reports (https://nodejs.org/api/report.html)
44+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
45+
46+
# Runtime data
47+
pids
48+
*.pid
49+
*.seed
50+
*.pid.lock
51+
52+
# Directory for instrumented libs generated by jscoverage/JSCover
53+
lib-cov
54+
55+
# Coverage directory used by tools like istanbul
256
coverage
3-
/node_modules
57+
*.lcov
58+
59+
# nyc test coverage
60+
.nyc_output
61+
62+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
63+
.grunt
64+
65+
# Bower dependency directory (https://bower.io/)
66+
bower_components
67+
68+
# node-waf configuration
69+
.lock-wscript
70+
71+
# Compiled binary addons (https://nodejs.org/api/addons.html)
72+
build/Release
73+
74+
# Dependency directories
75+
node_modules/
76+
jspm_packages/
77+
78+
# TypeScript v1 declaration files
79+
typings/
80+
81+
# TypeScript cache
82+
*.tsbuildinfo
83+
84+
# Optional npm cache directory
85+
.npm
86+
87+
# Optional eslint cache
88+
.eslintcache
89+
90+
# Optional REPL history
91+
.node_repl_history
92+
93+
# Output of 'npm pack'
94+
*.tgz
95+
96+
# Yarn Integrity file
97+
.yarn-integrity
98+
99+
# dotenv environment variables file
100+
.env
101+
.env.test
102+
103+
# parcel-bundler cache (https://parceljs.org/)
104+
.cache
105+
106+
# next.js build output
107+
.next
108+
109+
# nuxt.js build output
110+
.nuxt
111+
112+
# react / gatsby
113+
public/
114+
115+
# vuepress build output
116+
.vuepress/dist
117+
118+
# Serverless directories
119+
.serverless/
120+
121+
# FuseBox cache
122+
.fusebox/
123+
124+
# DynamoDB Local files
125+
.dynamodb/
126+
127+
### VisualStudioCode ###
128+
.vscode/*
129+
!.vscode/settings.json
130+
!.vscode/tasks.json
131+
!.vscode/launch.json
132+
!.vscode/extensions.json
133+
134+
### VisualStudioCode Patch ###
135+
# Ignore all local history of files
136+
.history
137+
138+
# End of https://www.gitignore.io/api/visualstudiocode,node,macos
139+
140+
# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)
141+
142+
.topcoderrc
143+
144+
# package-lock.json vary while installing on different operating system
145+
package-lock.json

.topcoderrc

Lines changed: 0 additions & 7 deletions
This file was deleted.

bin/topcoder-cli.js

Lines changed: 146 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,161 @@ const program = require('commander')
44
const submissionHandler = require('../src/commands/submit')
55
const payHandler = require('../src/commands/pay')
66
const configHandler = require('../src/commands/config')
7+
const fetchSubmissionHandler = require('../src/commands/fetchSubmissions')
8+
const fetchArtifactsHandler = require('../src/commands/fetchArtifacts')
79
const logger = require('../src/common/logger')
810

911
// Overall help text which will be displayed after usage information
1012
program.on('--help', () => {
11-
console.log(`\nTopcoder CLI to interact with Topcoder systems\n`)
13+
console.log('\nTopcoder CLI to interact with Topcoder systems\n')
1214
})
1315

1416
program
1517
.command('submit')
16-
.description('Submit the contents of current working directory to Topcoder challenge(s)')
17-
.option('-u, --username <uname>', 'Topcoder username')
18+
.description(
19+
'Submit the contents of current working directory to Topcoder challenge(s)'
20+
)
21+
.option('-u, --username <username>', 'Topcoder username')
1822
.option('-p, --password <password>', 'Topcoder password')
19-
.option('-m, --memberId <memberid>', 'Admin submitting on behalf of other member will use the member id')
20-
.option('-c, --challengeIds <ids>', 'Comma separated challenge IDs to which submission need to be done')
23+
.option(
24+
'-m, --memberId <memberId>',
25+
'Admin submitting on behalf of other member will use the member id'
26+
)
27+
.option(
28+
'-c, --challengeIds <ids>',
29+
'Comma separated challenge IDs to which submission need to be done'
30+
)
2131
.option('--dev', 'Points to Topcoder development environment')
2232
.on('--help', () => {
23-
console.log(`\nEither use CLI parameters or Create a file .topcoderrc in JSON format with below details
24-
{
25-
"challengeIds": [
26-
"30095545" // at least one item here
27-
],
28-
"username": "<Topcoder username>",
29-
"password": "<Topcoder password>"
33+
console.log(
34+
`\nEither use CLI parameters or Create a file .topcoderrc in JSON ` +
35+
`format with below details\n` +
36+
`{\n` +
37+
` "memberId": "<Topcoder memberId",\n` +
38+
` "challengeIds": [\n` +
39+
` "30095545" // at least one item here\n` +
40+
` ],\n` +
41+
` "username": "<Topcoder username>",\n` +
42+
` "password": "<Topcoder password>",\n` +
43+
` "m2m": {\n` +
44+
` client_id: "<Client ID for M2M authentication>",\n` +
45+
` client_secret: "<Client Secret for M2M authentication>"\n` +
46+
` }\n` +
47+
`}\n` +
48+
`and execute command \`topcoder submit\` to submit the contents of ` +
49+
`current working directory except .topcoderrc file to the challenge.\n` +
50+
`You'd need either the m2m config or the username and password, but ` +
51+
`not both.`
52+
)
53+
})
54+
.action(async args => {
55+
try {
56+
if (args.dev) {
57+
process.env.NODE_ENV = 'dev'
58+
}
59+
await submissionHandler(program.args[0])
60+
} catch (error) {
61+
logger.error(error.message)
62+
}
63+
})
64+
65+
program
66+
.command('fetch-submissions')
67+
.description('Command to fetch submissions for a challenge and save them.')
68+
.option('-u, --username <username>', 'Topcoder username')
69+
.option('-p, --password <password>', 'Topcoder password')
70+
.option(
71+
'-c, --challengeId <id>',
72+
'Challenge ID for submissions to be fetched'
73+
)
74+
.option(
75+
'-u, --userId <id>',
76+
'Fetch only the submission of for a particular user id'
77+
)
78+
.option(
79+
'-s, --submissionId <id>',
80+
'Fetch only the submission with a particular submission id'
81+
)
82+
.option('-l, --latest', 'fetch only the latest submission of each member')
83+
.option('--dev', 'Points to Topcoder development environment')
84+
.on('--help', () => {
85+
console.log(
86+
`\nUse CLI parameters or create a file .topcoderrc in JSON format with below details` +
87+
`{\n` +
88+
` "userId": "<Topcoder memberId",\n` +
89+
` "challengeId": "<Topcoder challengeId",\n` +
90+
` "submissionId": "<Topcoder submissionId",\n` +
91+
` "latest": true,\n` +
92+
` "username": "<Topcoder username>",\n` +
93+
` "password": "<Topcoder password>",\n` +
94+
` "m2m": {\n` +
95+
` client_id: "<Client ID for M2M authentication>",\n` +
96+
` client_secret: "<Client Secret for M2M authentication>"\n` +
97+
` }\n` +
98+
`}\n` +
99+
`and execute command \`topcoder fetch-submissions\` to fetch submissions ` +
100+
`for a challenge and save them.\n` +
101+
`You may specify the m2m config or the username and password config, ` +
102+
`but not both.\n` +
103+
`If the submissionId parameter is provided, you must not provide the ` +
104+
`userId or the latest parameters.\n` +
105+
`The challengeId parameter is always required.`
106+
)
107+
})
108+
.action(async args => {
109+
try {
110+
if (args.dev) {
111+
process.env.NODE_ENV = 'dev'
112+
}
113+
await fetchSubmissionHandler(program.args[0])
114+
} catch (error) {
115+
logger.error(error.message)
30116
}
31-
and execute command \`topcoder submit\` to submit the contents of current working directory except .topcoderrc file to the challenge`)
32-
}).action((args) => {
117+
})
118+
119+
program
120+
.command('fetch-artifacts')
121+
.description('Command to fetch artifacts for a challenge and save them.')
122+
.option('-u, --username <username>', 'Topcoder username')
123+
.option('-p, --password <password>', 'Topcoder password')
124+
.option(
125+
'-s, --submissionId <id>',
126+
'Fetch only the submission with a particular submission id'
127+
)
128+
.option(
129+
'-L, --legacySubmissionId <id>',
130+
'Fetch only the submission with a particular (legacy) submission id'
131+
)
132+
.option('--dev', 'Points to Topcoder development environment')
133+
.on('--help', () => {
134+
console.log(
135+
`\nUse CLI parameters or create a file .topcoderrc in JSON format ` +
136+
`with below details\n` +
137+
`{\n` +
138+
` "submissionId": "<Topcoder submissionId>",\n` +
139+
` "legacySubmissionId": "<Topcoder legacySubmissionId>",\n` +
140+
` "username": "<Topcoder username>",\n` +
141+
` "password": "<Topcoder password>",\n` +
142+
` "m2m": {\n` +
143+
` client_id: "<Client ID for M2M authentication>",\n` +
144+
` client_secret: "<Client Secret for M2M authentication>"\n` +
145+
` }\n` +
146+
`}\n` +
147+
`and execute command \`topcoder fetch-artifacts\` to fetch submissions for` +
148+
` a challenge and save them.\n` +
149+
`You may specify the m2m config or the username and password config, ` +
150+
`but not both.\n` +
151+
`If the submissionId parameter is provided, you must not provide the the ` +
152+
`legacySubmissionId parameters, and vice-versa.`
153+
)
154+
})
155+
.action(async args => {
33156
try {
34157
if (args.dev) {
35158
process.env.NODE_ENV = 'dev'
36159
}
37-
submissionHandler(program.args[0])
160+
await fetchArtifactsHandler(program.args[0])
38161
} catch (error) {
39-
logger.error(error)
40162
logger.error(error.message)
41163
}
42164
})
@@ -47,9 +169,9 @@ program
47169
.option('-l --list', 'Print the keys in the config file')
48170
.option('-a --add <key> <value>', 'Add / Replace a key in the config file.')
49171
.option('--unset <key>', 'Removes a key from the config file')
50-
.action((...args) => {
172+
.action(async (...args) => {
51173
try {
52-
configHandler.handleSubCommand(args)
174+
await configHandler.handleSubCommand(args)
53175
} catch (error) {
54176
logger.error(error.message)
55177
}
@@ -60,7 +182,7 @@ program
60182
.description('Let copilot/managers process private task payments')
61183
.option('-o --copilot <payment>', 'copilot payment.')
62184
.option('--dev', 'Points to Topcoder development environment')
63-
.action((...args) => {
185+
.action(args => {
64186
if (args.dev) {
65187
process.env.NODE_ENV = 'dev'
66188
}
@@ -69,7 +191,11 @@ program
69191

70192
// error on unknown commands
71193
program.on('command:*', function () {
72-
console.error('Invalid command: %s\nEnter topcoder --help for the list of available commands.', program.args.join(' '))
194+
console.error(
195+
'Invalid command: %s\nEnter topcoder --help for the list of available ' +
196+
'commands.',
197+
program.args.join(' ')
198+
)
73199
process.exit(1)
74200
})
75201

config/dev.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@
44

55
module.exports = {
66
LOG_LEVEL: process.env.LOG_LEVEL || 'info',
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-
AUTH0_URL: process.env.AUTH0_URL || 'https://topcoder-dev.auth0.com/oauth/token',
10-
TC_AUTHN_URL: process.env.TC_AUTHN_URL || 'https://topcoder-dev.auth0.com/oauth/ro',
11-
TC_AUTHZ_URL: process.env.TC_AUTHZ_URL || 'https://api.topcoder-dev.com/v3/authorizations',
7+
TC_MEMBERS_API:
8+
process.env.TC_MEMBERS_API || 'https://api.topcoder-dev.com/v3/members',
9+
SUBMISSION_API_URL:
10+
process.env.TEST_SUBMISSION_API_URL || 'https://api.topcoder-dev.com/v5',
11+
AUTH0_URL:
12+
process.env.AUTH0_URL || 'https://topcoder-dev.auth0.com/oauth/token',
13+
TC_AUTHN_URL:
14+
process.env.TC_AUTHN_URL || 'https://topcoder-dev.auth0.com/oauth/ro',
15+
TC_AUTHZ_URL:
16+
process.env.TC_AUTHZ_URL ||
17+
'https://api.topcoder-dev.com/v3/authorizations',
1218
TC_CLIENT_ID: process.env.TC_CLIENT_ID || 'JFDo7HMkf0q2CkVFHojy3zHWafziprhT',
13-
TC_CLIENT_V2CONNECTION: process.env.CLIENT_V2CONNECTION || 'TC-User-Database'
19+
TC_CLIENT_V2CONNECTION: process.env.CLIENT_V2CONNECTION || 'TC-User-Database',
20+
AUTH0_AUDIENCE: process.env.AUTH0_AUDIENCE || 'https://m2m.topcoder-dev.com/'
1421
}

0 commit comments

Comments
 (0)