Skip to content

Commit 6bd8451

Browse files
author
vikasrohit
authored
Merge pull request #162 from topcoder-platform/v5-upgrade
Migrate to Project Service V5
2 parents 9fcd0af + 5627a2b commit 6bd8451

File tree

6 files changed

+46
-23
lines changed

6 files changed

+46
-23
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ workflows:
102102
context : org-global
103103
filters:
104104
branches:
105-
only: [dev, 'hotfix/V5-API-Standards']
105+
only: [dev, 'hotfix/V5-API-Standards', 'v5-upgrade']
106106
- "build-prod":
107107
context : org-global
108108
filters:

README.md

+14-13
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ tc-notifications (as a standard nodejs app) provides generic framework around no
2020
5. Either add deployment for this new notification consumer/processor in existing deployment script (if you want to host the processor as separate service in the same ECS cluster) or write a new script if you want to keep the deployment separate.
2121

2222
## Dependencies
23-
- nodejs https://nodejs.org/en/ (v6+, if newer version of node is used, e.g. v10, then it needs to install extra lib `npm i [email protected]` to support the gulp build)
23+
- nodejs https://nodejs.org/en/ (v6+, if newer version of node is used, e.g. v10, then it needs to install extra lib `npm i [email protected]` to support the gulp build)
2424
- Heroku Toolbelt https://toolbelt.heroku.com
2525
- git
2626
- PostgreSQL 9.5
@@ -50,8 +50,8 @@ The following parameters can be set in config files or in env variables:
5050
if not provided, then SSL connection is not used, direct insecure connection is used;
5151
if provided, it can be either path to private key file or private key content
5252
- **Topcoder API**
53-
- `TC_API_V3_BASE_URL`: the TopCoder API V3 base URL
54-
- `TC_API_V4_BASE_URL`: the TopCoder API V4 base URL
53+
- `TC_API_V3_BASE_URL`: the TopCoder API V3 base URL
54+
- `TC_API_V4_BASE_URL`: the TopCoder API V4 base URL
5555
- `TC_API_V5_BASE_URL`: the TopCoder API V5 base URL
5656
- **Notifications API**
5757
- `API_CONTEXT_PATH`: path to serve API on
@@ -61,16 +61,16 @@ The following parameters can be set in config files or in env variables:
6161
- `TOKEN_CACHE_TIME`: time period of the cached token
6262
- `AUTH0_CLIENT_ID`: auth0 client id
6363
- `AUTH0_CLIENT_SECRET`: auth0 client secret
64-
- `AUTH0_PROXY_SERVER_URL`: auth0 proxy server URL
65-
- **Consumer handlers**
66-
- `KAFKA_CONSUMER_HANDLERS`: mapping from consumer topic to handlers
67-
- **Email notification**
68-
- `ENV`: used to construct email category
69-
- `ENABLE_EMAILS`: whether to enable email notifications
70-
- `ENABLE_DEV_MODE`: whether to enable dev mode
71-
- `DEV_MODE_EMAIL`: recipient email used in dev mode
72-
- `DEFAULT_REPLY_EMAIL`: default reply email
73-
64+
- `AUTH0_PROXY_SERVER_URL`: auth0 proxy server URL
65+
- **Consumer handlers**
66+
- `KAFKA_CONSUMER_HANDLERS`: mapping from consumer topic to handlers
67+
- **Email notification**
68+
- `ENV`: used to construct email category
69+
- `ENABLE_EMAILS`: whether to enable email notifications
70+
- `ENABLE_DEV_MODE`: whether to enable dev mode
71+
- `DEV_MODE_EMAIL`: recipient email used in dev mode
72+
- `DEFAULT_REPLY_EMAIL`: default reply email
73+
7474

7575
### Connect notification server
7676
Configuration for the connect notification server is at `connect/config.js`.
@@ -137,6 +137,7 @@ You may reuse it during review.
137137
- start local PostgreSQL db, create an empty database, update the config/default.js DATABASE_URL param to point to the db
138138
- install dependencies `npm i`
139139
- run code lint check `npm run lint`
140+
- init DB `npm run reset:db`
140141
- start connect notification server `npm start`
141142
- the app is running at `http://localhost:4000`, it also starts Kafka consumer to listen for events and save unroll-ed notifications to db
142143

connect/config.js

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module.exports = {
66
// TC API related variables
77
TC_API_V3_BASE_URL: process.env.TC_API_V3_BASE_URL || 'https://api.topcoder-dev.com/v3',
88
TC_API_V4_BASE_URL: process.env.TC_API_V4_BASE_URL || 'https://api.topcoder-dev.com/v4',
9+
TC_API_V5_BASE_URL: process.env.TC_API_V5_BASE_URL || 'https://api.topcoder-dev.com/v5',
910
MESSAGE_API_BASE_URL: process.env.MESSAGE_API_BASE_URL || 'https://api.topcoder-dev.com/v5',
1011

1112
// id of the BOT user which creates post with various events in discussions

connect/service.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ const getProject = (projectId) => (
1919
M2m.getMachineToken(config.AUTH0_CLIENT_ID, config.AUTH0_CLIENT_SECRET)
2020
.then((token) => (
2121
request
22-
.get(`${config.TC_API_V4_BASE_URL}/projects/${projectId}`)
22+
.get(`${config.TC_API_V5_BASE_URL}/projects/${projectId}`)
2323
.set('accept', 'application/json')
2424
.set('authorization', `Bearer ${token}`)
2525
.then((res) => {
26-
if (!_.get(res, 'body.result.success')) {
26+
const project = res.body;
27+
if (!project) {
2728
throw new Error(`Failed to get project details of project id: ${projectId}`);
2829
}
29-
const project = _.get(res, 'body.result.content');
3030
return project;
3131
}).catch((err) => {
32-
const errorDetails = _.get(err, 'response.body.result.content.message');
32+
const errorDetails = _.get(err, 'response.body.message');
3333
throw new Error(
3434
`Failed to get project details of project id: ${projectId}.` +
3535
(errorDetails ? ' Server response: ' + errorDetails : '')
@@ -244,17 +244,17 @@ const getPhase = (projectId, phaseId) => (
244244
M2m.getMachineToken(config.AUTH0_CLIENT_ID, config.AUTH0_CLIENT_SECRET)
245245
.then((token) => (
246246
request
247-
.get(`${config.TC_API_V4_BASE_URL}/projects/${projectId}/phases/${phaseId}`)
247+
.get(`${config.TC_API_V5_BASE_URL}/projects/${projectId}/phases/${phaseId}`)
248248
.set('accept', 'application/json')
249249
.set('authorization', `Bearer ${token}`)
250250
.then((res) => {
251-
if (!_.get(res, 'body.result.success')) {
251+
const project = res.body;
252+
if (!project) {
252253
throw new Error(`Failed to get phase details of project id: ${projectId}, phase id: ${phaseId}`);
253254
}
254-
const project = _.get(res, 'body.result.content');
255255
return project;
256256
}).catch((err) => {
257-
const errorDetails = _.get(err, 'response.body.result.content.message');
257+
const errorDetails = _.get(err, 'response.body.message');
258258
throw new Error(
259259
`Failed to get phase details of project id: ${projectId}, phase id: ${phaseId}.` +
260260
(errorDetails ? ' Server response: ' + errorDetails : '')

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"lint:fix": "eslint *.js --fix src config test connect",
1212
"postinstall": "npm run build",
1313
"build": "gulp build",
14-
"watch": "gulp watch"
14+
"watch": "gulp watch",
15+
"reset:db": "node tools/resetDb.js"
1516
},
1617
"author": "TCSCODER",
1718
"license": "none",

tools/resetDb.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Script for initializing/resetting DB.
3+
*
4+
* WARNING
5+
* It recreates DB schema causing removing existent data if any.
6+
*/
7+
const notificationServer = require('../index');
8+
9+
console.info('Initializing db...');
10+
11+
notificationServer
12+
.initDatabase()
13+
.then(() => {
14+
console.info('Database was successfully initialized.');
15+
process.exit();
16+
})
17+
.catch((err) => {
18+
console.error('Error initializing DB', err);
19+
process.exit(1);
20+
});

0 commit comments

Comments
 (0)