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

Commit 16f13cd

Browse files
committed
1 parent 09f3acb commit 16f13cd

12 files changed

+821
-675
lines changed

README.md

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ eslint is used to lint the javascript source code:
1818
npm run lint
1919
```
2020

21-
22-
2321
## Configuration
2422

2523
The following config parameters are supported, they are defined in `config/default.js` and can be configured in system environment:
@@ -28,24 +26,21 @@ The following config parameters are supported, they are defined in `config/defau
2826
| Name | Description | Default |
2927
| :----------------------------- | :----------------------------------------: | :------------------------------: |
3028
| LOG_LEVEL | the log level | debug |
31-
| TOPIC | the kafka subscribe topic name | events_topic |
29+
| TOPIC | the kafka subscribe topic name | tc-x-events |
30+
| PARTITION | the kafka partition | 0|
3231
| KAFKA_OPTIONS | the connection option for kafka | see below about KAFKA options |
33-
| MONGODB_URL | the MongoDB URL | mongodb://127.0.0.1:27017/events |
32+
| MONGODB_URL | the MongoDB URL which must be same as Ragnar tool | mongodb://127.0.0.1:27017/ragnar |
33+
|TC_DEV_ENV| the flag whether to use topcoder development api or production| false|
3434
| TC_AUTHN_URL | the Topcoder authentication url | https://topcoder-dev.auth0.com/oauth/ro |
3535
| TC_AUTHN_REQUEST_BODY | the Topcoder authentication request body. This makes use of some environment variables: `TC_USERNAME`, `TC_PASSWORD`, `TC_CLIENT_ID`, `CLIENT_V2CONNECTION` | see `default.js` |
3636
| TC_AUTHZ_URL | the Topcoder authorization url | https://api.topcoder-dev.com/v3/authorizations |
3737
| NEW_CHALLENGE_TEMPLATE | the body template for new challenge request. You can change the subTrack, reviewTypes, technologies, .. here | see `default.js` |
3838
| NEW_CHALLENGE_DURATION_IN_DAYS | the duration of new challenge | 5 |
39-
| GITHUB_ADMIN_TOKEN| the github repo admin/owner personal access token | see below section 'GitHub OAuth Admin Token'|
4039
| NODE_MAILER_OPTIONS| the node mailer smtp options, see [here](https://nodemailer.com/smtp/ for more detail)| see `default.js` |
4140
|EMAIL_SENDER_ADDRESS| the email sender email address||
4241
|ISSUE_BID_EMAIL_RECEIVER| the email receiver about bid email||
43-
|TC_RAGNAR_USER_MAPPING_URL| the api URL of Ragnar self service tool to get user mapping | see `default.js`|
44-
|TC_RAGNAR_ADMIN_LOGIN_BODY| the login request body of Admin user for Ragnar self service tool| see `default.js`|
45-
|TC_RAGNAR_LOGIN_URL| the api URL of Ragnar self service tool to login| see `default.js`|
46-
|TC_DEV_ENV| the flag whether to use topcoder development api or production| false|
42+
|TC_URL| the base URL of topcoder to get the challenge URL| defaults to `https://www.topcoder-dev.com`|
4743
|GITLAB_API_BASE_URL| the URL for gitlab host| defaults to `https://gitlab.com`|
48-
|GITLAB_ADMIN_TOKEN|the gitlab repo admin/owner personal access token | see below section 'Gitlab Admin Token'|
4944

5045
KAFKA_OPTIONS should be object as described in https://github.com/SOHU-Co/kafka-node#kafkaclient
5146
For using with SSL, the options should be as
@@ -59,42 +54,30 @@ For using with SSL, the options should be as
5954
}
6055
```
6156

62-
## GitHub OAuth Admin Token
63-
64-
- login into github.com
65-
- click the upper right avatar, then click `Settings`
66-
- click the left pannel --> Developer settings --> Personal access tokens
67-
- click the `Generate new token`, fill in the fields,
68-
select all scopes,
69-
- after creating the token, you can see personal access token,
70-
these should be set to GITHUB_ADMIN_TOKEN environment variables
57+
## Local Deployment
7158

72-
## Gitlab Admin Token
59+
```shell
60+
npm start
61+
```
7362

74-
- Log in to your GitLab account.
75-
- Go to your Profile settings.
76-
- Go to Access tokens.
77-
- Choose a name and optionally an expiry date for the token.
78-
- Choose the `api` scope at minimum.
79-
- Click on Create personal access token.
80-
- after creating the token, you can see personal access token,
81-
these should be set to GITLAB_ADMIN_TOKEN environment variables.
63+
## Setup for verification
64+
Before verifying the tool, 4 service needs be configured and run them
65+
- processor
66+
- receiver
67+
- Ragnar Tool
68+
- Topcoder X (both backend and UI)
8269

83-
## Local Setup
70+
First login in Ragnar tool with admin and Add owner for which requires topcoder handle, git host's username and type of git host.
8471

85-
Create a MongoDB database, and configure `MONGODB_URL`.
72+
Go to Topcoder X UI login with above used topcoder username and
73+
- go to settings and make sure git hosts are correctly setup, if not click setup and authorize to setup.
8674

87-
```shell
88-
npm start
89-
```
75+
- Go to Topcoder X UI and go to project management and add a project from git account and click save, and edit the same project and click 'Add Webhooks' button (you need to add personnel access token), verify that webhooks are set up correctly on git host's project.
9076

91-
Run and configure the Ragnar self-service tool
77+
Now, receiver service can receive the webhooks from git host's project and processor can processes the requests. Now you can verify this service by following the verfication steps below
9278

9379
## Verification
9480

95-
- properly config and run the `receiver` app.
96-
- properly config and run the `processor` app.
97-
- properly config and run the Ragnar self service tool.
9881
- create an issue in the repo, you can see the logs in `receiver` and `processor`, the `issue.created` event is generated.
9982
- update an issue in the repo, you can see the logs in `receiver` and `processor`, the `issue.updated` event is generated.
10083
- create a comment on an issue, you can see the logs in `receiver` and `processor`, the `comment.created` event is generated.

config/default.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) 2017 TopCoder, Inc. All rights reserved.
33
*/
44
'use strict';
5-
5+
const fs = require('fs');
66
/**
77
* This module is the configuration of the app.
88
* Changes in 1.1:
@@ -23,7 +23,7 @@ module.exports = {
2323
key: process.env.KAFKA_CLIENT_CERT_KEY || fs.readFileSync('./kafka_client.key')
2424
}
2525
},
26-
MONGODB_URL: process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017/topcoder-x-events',
26+
MONGODB_URL: process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017/ragnar',
2727
TC_DEV_ENV: process.env.NODE_ENV === 'production' ? false : true,
2828
TC_AUTHN_URL: process.env.TC_AUTHN_URL || 'https://topcoder-dev.auth0.com/oauth/ro',
2929
TC_AUTHN_REQUEST_BODY: {
@@ -66,8 +66,6 @@ module.exports = {
6666
// NOTE: if subTrack is FIRST_2_FINISH,
6767
// this config has no effect since the ***EndsAt will be set automatically by TC APIs
6868
NEW_CHALLENGE_DURATION_IN_DAYS: process.env.NEW_CHALLENGE_DURATION_IN_DAYS || 5,
69-
GITHUB_ADMIN_TOKEN: process.env.GITHUB_ADMIN_TOKEN || '',
70-
GITLAB_ADMIN_TOKEN:process.env.GITHUB_ADMIN_TOKEN || '',
7169
// node mailer option
7270
NODE_MAILER_OPTIONS: {
7371
host: process.env.SMTP_HOST || process.env.MAILGUN_SMTP_SERVER || 'smtp.gmail.com',
@@ -80,11 +78,6 @@ module.exports = {
8078
},
8179
EMAIL_SENDER_ADDRESS: process.env.EMAIL_SENDER_ADDRESS || '',
8280
ISSUE_BID_EMAIL_RECEIVER: process.env.ISSUE_BID_EMAIL_RECEIVER || '',
83-
TC_RAGNAR_USER_MAPPING_URL: process.env.TC_RAGNAR_USER_MAPPING_URL || 'http://ragnar.topcoder-dev.com/api/v1/admin/tcuser',
84-
TC_RAGNAR_ADMIN_LOGIN_BODY: {
85-
username: "admin",
86-
password: "password"
87-
},
88-
TC_RAGNAR_LOGIN_URL: process.env.TC_RAGNAR_LOGIN_URL || 'http://ragnar.topcoder-dev.com/api/v1/admin/login',
89-
TC_URL: 'https://www.topcoder-dev.com'
81+
TC_URL: process.env.TC_URL || 'https://www.topcoder-dev.com',
82+
GITLAB_API_BASE_URL: process.env.GITLAB_API_BASE_URL || 'https://gitlab.com',
9083
};

constants.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
3+
/*
4+
* Copyright (c) 2018 TopCoder, Inc. All rights reserved.
5+
*/
6+
7+
/**
8+
* Define constants.
9+
*
10+
* @author TCSCODER
11+
* @version 1.0
12+
*/
13+
14+
// The user types
15+
const USER_TYPES = {
16+
GITHUB: 'github',
17+
GITLAB: 'gitlab'
18+
};
19+
20+
// The user roles
21+
const USER_ROLES = {
22+
OWNER: 'owner'
23+
};
24+
25+
module.exports = {
26+
USER_ROLES,
27+
USER_TYPES
28+
};

models/Challenge.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (c) 2018 TopCoder, Inc. All rights reserved.
3+
*/
4+
5+
/**
6+
* This module contains the schema of the Challenge.
7+
*
8+
* @author TCSCODER
9+
* @version 1.0
10+
*/
11+
'use strict';
12+
13+
const mongoose = require('mongoose');
14+
15+
const schema = new mongoose.Schema({
16+
title: {type: String, required: true},
17+
tcDirectId: {type: Number, required: true},
18+
repoUrl: {type: String, required: true},
19+
rocketChatWebhook: {type: String, required: true},
20+
rocketChatChannelName: {type: String, required: true},
21+
archieved: {type: String, required: true},
22+
username: {type: String, required: true}
23+
});
24+
25+
module.exports = schema;

models/User.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2018 TopCoder, Inc. All rights reserved.
3+
*/
4+
/**
5+
* This defines user model.
6+
*/
7+
'use strict';
8+
9+
const _ = require('lodash');
10+
const mongoose = require('mongoose');
11+
const constants = require('../constants');
12+
13+
const Schema = mongoose.Schema;
14+
15+
const schema = new Schema({
16+
topcoderUsername: {type: String, required: true},
17+
userProviderId: {type: Number, required: true},
18+
username: {type: String, required: true},
19+
role: {type: String, required: true, enum: _.values(constants.USER_ROLES)},
20+
type: {type: String, required: true, enum: _.values(constants.USER_TYPES)},
21+
// gitlab token data
22+
accessToken: String,
23+
accessTokenExpiration: Date,
24+
refreshToken: String
25+
});
26+
27+
schema.index({topcoderUsername: 1});
28+
schema.index({userProviderId: 1});
29+
schema.index({username: 1});
30+
schema.index({role: 1});
31+
schema.index({type: 1});
32+
schema.index({topcoderUsername: 1, type: 1}, {unique: true});
33+
34+
module.exports = schema;

models/UserMapping.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* This defines user mapping model.
3+
*/
4+
'use strict';
5+
6+
const mongoose = require('mongoose');
7+
8+
const Schema = mongoose.Schema;
9+
10+
const schema = new Schema({
11+
topcoderUsername: {type: String, required: true, unique: true},
12+
githubUsername: String,
13+
gitlabUsername: String,
14+
githubUserId: Number,
15+
gitlabUserId: Number
16+
});
17+
18+
schema.index({topcoderUsername: 1});
19+
20+
module.exports = schema;

models/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ const connection = mongoose.createConnection(config.MONGODB_URL);
1919
/* eslint-disable global-require */
2020
const models = {
2121
Issue: connection.model('Issue', require('./Issue')),
22-
Project: connection.model('Project', require('./Project'))
22+
Project: connection.model('Project', require('./Project')),
23+
User: connection.model('User', require('./User')),
24+
Challenge: connection.model('Challenge', require('./Challenge')),
25+
UserMapping: connection.model('UserMapping', require('./UserMapping'))
2326
};
2427
/* eslint-enable global-require */
2528

0 commit comments

Comments
 (0)