Skip to content

Commit 4ba6a64

Browse files
committed
Merge remote-tracking branch 'github/develop'
2 parents 4cf6b5d + 8d36255 commit 4ba6a64

18 files changed

+1537
-881
lines changed

.eslintrc

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@
33
"node": true
44
},
55
"parserOptions": {
6-
"ecmaVersion": 8
6+
"ecmaVersion": 8,
7+
"ecmaFeatures": {
8+
"experimentalObjectRestSpread": true
9+
}
710
},
811
"extends": "eslint-config-topcoder/nodejs",
912
"rules": {
10-
"max-len": ["error", 160],
13+
"max-len": [
14+
"error",
15+
160
16+
],
1117
"indent": [
1218
"error",
1319
2
@@ -25,12 +31,16 @@
2531
"always"
2632
],
2733
"no-console": 0,
28-
"comma-dangle": ["error", {
29-
"arrays": "never",
30-
"objects": "never",
31-
"imports": "never",
32-
"exports": "never",
33-
"functions": "ignore"
34-
}]
34+
"comma-dangle": [
35+
"error",
36+
{
37+
"arrays": "never",
38+
"objects": "never",
39+
"imports": "never",
40+
"exports": "never",
41+
"functions": "ignore"
42+
}
43+
],
44+
"max-lines": 0,
3545
}
36-
}
46+
}

README.md

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,16 @@ The following config parameters are supported, they are defined in `config/defau
4141
|ISSUE_BID_EMAIL_RECEIVER| the email receiver about bid email||
4242
|TC_URL| the base URL of topcoder to get the challenge URL| defaults to `https://www.topcoder-dev.com`|
4343
|GITLAB_API_BASE_URL| the URL for gitlab host| defaults to `https://gitlab.com`|
44+
|PAID_ISSUE_LABEL|the label name for paid, should be one of the label configured in topcoder x ui|'Paid'|
45+
|FIX_ACCEPTED_ISSUE_LABEL|the label name for fix accepted, should be one of the label configured in topcoder x ui|'Fix Accepted'|
46+
|TC_OR_DETAIL_LINK|the link to online review detail of challenge| see `default.js`, OR link for dev environment|
4447

45-
KAFKA_OPTIONS should be object as described in https://github.com/SOHU-Co/kafka-node#kafkaclient
48+
KAFKA_OPTIONS should be object as described in https://github.com/oleksiyk/kafka#ssl
4649
For using with SSL, the options should be as
4750
```
4851
{
49-
kafkaHost: '<server>',
50-
sslOptions: {
52+
connectionString: '<server>',
53+
ssl: {
5154
cert: '<certificate>',
5255
key: '<key>'
5356
}
@@ -85,6 +88,7 @@ Now, receiver service can receive the webhooks from git host's project and proce
8588
- create a pull request, you can see the logs in `receiver` and `processor`, the `pull_request.created` event is generated.
8689
- close a pull request without merge, you can see the logs in `receiver` and `processor`, the `pull_request.closed` event is generated and the `merged` property is `false`.
8790
- merge a pull request, you can see the logs in `receiver` and `processor`, the `pull_request.closed` event is generated and the `merged` property is `true`.
91+
- close an issue in the repo, you can see the logs in `receiver` and `processor`, the `issue.closed` event is generated
8892

8993
### Create a new challenge for a new issue
9094
- Create a new issue in the repo. E.g.
@@ -132,7 +136,7 @@ Now, receiver service can receive the webhooks from git host's project and proce
132136
debug: nothing changed for issue 3
133137
```
134138
135-
- Update the tilte by removing `[$50 ]`, you'll get an error:
139+
- Update the title by removing `[$50 ]`, you'll get an error:
136140
```
137141
error: Error: Cannot parse prize from title: A new issue title - Updated the prize
138142
```
@@ -157,3 +161,38 @@ When an user is assigned to an issue then 'issue.assigned' event will be capture
157161
@username, please sign-up with Topcoder x Self-service tool.
158162
```
159163
- user will be unassigned from issue
164+
165+
### Closing issue
166+
167+
When an issue is closed it will first check if issue has any assignee or not,
168+
169+
- if there is no assignee then simply ignores the issue closed event with message in logger
170+
- if there is an assignee then it will
171+
- first set the current assignee user as challenge assignee,
172+
- activate the challenge with project's billing
173+
- closes the challenge with winner as assignee
174+
- you can verify the challenge closed in OR (link will be commented in same issue in git host)
175+
- issue label will be updated from configured paid and fix accepted label name
176+
177+
You can see following logs
178+
```
179+
debug: Looking up TC handle of git user: 82332
180+
debug: Getting the billing account ID for project ID: 15180
181+
debug: Getting project billing detail 15180
182+
debug: assigning the billing account id 70016668 to challenge
183+
debug: Updating challenge 30052019 with {"billingAccountId":70016668,"prizes":[234]}
184+
debug: Getting the topcoder member ID for member name: tonyj
185+
debug: Getting the topcoder member ID for copilot name : tonyj
186+
debug: adding resource to challenge 30052019
187+
debug: resource is added to challenge 30052019 successfully.
188+
debug: adding resource to challenge 30052019
189+
debug: Activating challenge 30052019
190+
debug: Challenge 30052019 is activated successfully.
191+
debug: close challenge with winner tonyj(8547899)
192+
debug: Closing challenge 30052019
193+
debug: Challenge 30052019 is closed successfully.
194+
debug: update issue as paid
195+
debug: Gitlab/Github issue is updated for as paid and fix accepted for 59
196+
```
197+
198+
- if issue have already paid label it won't process

config/default.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ module.exports = {
1717
PARTITION: process.env.PARTITION || 0,
1818
TOPIC: process.env.TOPIC || 'tc-x-events',
1919
KAFKA_OPTIONS: {
20-
kafkaHost: process.env.KAFKA_HOST || 'localhost:9092',
21-
sslOptions: {
20+
connectionString: process.env.KAFKA_HOST || 'localhost:9092',
21+
ssl: {
2222
cert: process.env.KAFKA_CLIENT_CERT || fs.readFileSync('./kafka_client.cer'), // eslint-disable-line no-sync
2323
key: process.env.KAFKA_CLIENT_CERT_KEY || fs.readFileSync('./kafka_client.key'), // eslint-disable-line no-sync
2424
}
@@ -80,4 +80,10 @@ module.exports = {
8080
ISSUE_BID_EMAIL_RECEIVER: process.env.ISSUE_BID_EMAIL_RECEIVER || '',
8181
TC_URL: process.env.TC_URL || 'https://www.topcoder-dev.com',
8282
GITLAB_API_BASE_URL: process.env.GITLAB_API_BASE_URL || 'https://gitlab.com',
83+
PAID_ISSUE_LABEL: process.env.PAID_ISSUE_LABEL || 'Paid',
84+
FIX_ACCEPTED_ISSUE_LABEL: process.env.FIX_ACCEPTED_ISSUE_LABEL || 'Fix accepted',
85+
READY_FOR_REVIEW_ISSUE_LABEL: process.env.READY_FOR_REVIEW_ISSUE_LABEL || 'Ready for review',
86+
TC_OR_DETAIL_LINK: process.env.TC_OR_DETAIL_LINK || 'https://software.topcoder-dev.com/review/actions/ViewProjectDetails?pid=',
87+
RETRY_COUNT: process.env.RETRY_COUNT || 3,
88+
RETRY_INTERVAL: process.env.RETRY_INTERVAL || 120000, // 2 minutes
8389
};

configuration.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Topcoder X Processor Configuration
2+
3+
The following config parameters are supported, they are defined in `config/default.js` and can be configured as env variables:
4+
5+
| Name | Description | Default |
6+
| :----------------------------- | :----------------------------------------: | :------------------------------: |
7+
| LOG_LEVEL | the log level | debug |
8+
| PARTITION | The Kafka partition | 0|
9+
| MONGODB_URI | The MongoDB URI. This needs to be the same MongoDB used by topcoder-x-receiver, topcoder-x-processor, and topcoder-x-site | mongodb://127.0.0.1:27017/topcoderx |
10+
|TOPIC | The Kafka topic where events are published. This must be the same as the configured value for topcoder-x-processor| |
11+
|KAFKA_OPTIONS | Kafka connection options| |
12+
|KAFKA_HOST | The Kafka host to connect to| localhost:9092 |
13+
|KAFKA_CLIENT_CERT | The Kafka SSL certificate to use when connecting| Read from kafka_client.cer file, but this can be set as a string like it is on Heroku |
14+
|KAFKA_CLIENT_CERT_KEY | The Kafka SSL certificate key to use when connecting| Read from kafka_client.key file, but this can be set as a string like it is on Heroku|
15+
|TC_DEV_ENV| the flag whether to use topcoder development api or production| false|
16+
| TC_AUTHN_URL | the Topcoder authentication url | https://topcoder-dev.auth0.com/oauth/ro |
17+
| 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` |
18+
| TC_AUTHZ_URL | the Topcoder authorization url | https://api.topcoder-dev.com/v3/authorizations |
19+
| NEW_CHALLENGE_TEMPLATE | the body template for new challenge request. You can change the subTrack, reviewTypes, technologies, .. here | see `default.js` |
20+
| NEW_CHALLENGE_DURATION_IN_DAYS | the duration of new challenge | 5 |
21+
| NODE_MAILER_OPTIONS| the node mailer smtp options, see [here](https://nodemailer.com/smtp/ for more detail)| see `default.js` |
22+
|EMAIL_SENDER_ADDRESS| the email sender email address||
23+
|ISSUE_BID_EMAIL_RECEIVER| the email receiver about bid email||
24+
|TC_URL| the base URL of topcoder to get the challenge URL| defaults to `https://www.topcoder-dev.com`|
25+
|GITLAB_API_BASE_URL| the URL for gitlab host| defaults to `https://gitlab.com`|
26+
|PAID_ISSUE_LABEL|the label name for paid, should be one of the label configured in topcoder x ui|'Paid'|
27+
|FIX_ACCEPTED_ISSUE_LABEL|the label name for fix accepted, should be one of the label configured in topcoder x ui|'Fix Accepted'|
28+
|TC_OR_DETAIL_LINK|the link to online review detail of challenge| see `default.js`, OR link for dev environment|
29+
|RETRY_COUNT| the number of times an event should be retried to process| 3|
30+
|RETRY_INTERVAL| the interval at which the event should be retried to process in milliseconds | 120000|
31+
|READY_FOR_REVIEW_ISSUE_LABEL| the label name for ready for review, should be one of the label configured in topcoder x ui|'Ready for review'|
32+
33+
KAFKA_OPTIONS should be object as described in https://github.com/oleksiyk/kafka#ssl
34+
For using with SSL, the options should be as
35+
```
36+
{
37+
kafkaHost: '<server>',
38+
sslOptions: {
39+
cert: '<certificate>',
40+
key: '<key>'
41+
}
42+
}
43+
```
44+
## Github Verification
45+
46+
#### Webhook configuration
47+
48+
Configure a Github project with a webhook with a format like this: https://<receiver URL>:<receiver port>/webhooks/github
49+
50+
#### Smoke test
51+
- Create an issue in the repo, you can see the logs in `receiver`, the `issue.created` event is generated. You should then see the processor receive the event and process it accordingly. It's important to validate that the issue.created event is seen by the receiver *and* the processor. This ensures that the Kafka communication between the two services is working properly.
52+
53+
You can test other events, but just validating that an issue.created event is generated in Kafka is enough to smoke test the receiver is set up properly.
54+
55+
## Github Verification
56+
57+
#### Webhook configuration
58+
59+
Configure a Gitlab project with a webhook with a format like this: https://<receiver URL>:<receiver port>/webhooks/gitlab
60+
61+
#### Smoke test
62+
63+
See above - the steps are the same for Github and Gitlab
64+
65+
## Debugging
66+
You can re-run and debug the responses to webhook requests on Github and Gitlab, in the configuration for the webhook. This can be useful if things aren't coming through properly in the receiver.
67+
68+
If you see the event come into the receiver but the processor doesn't see it, make sure that Kafka is configured the same between the processor and receiver and that there aren't any Kafka connection errors being raised in the processor.

constants.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ const USER_ROLES = {
2222
OWNER: 'owner'
2323
};
2424

25+
const SERVICE_ERROR_STATUS = 500;
26+
2527
module.exports = {
2628
USER_ROLES,
27-
USER_TYPES
29+
USER_TYPES,
30+
SERVICE_ERROR_STATUS
2831
};

models/Project.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,13 @@ const schema = new mongoose.Schema({
1414
title: {type: String, required: true},
1515
tcDirectId: {type: Number, required: true},
1616
repoUrl: {type: String, required: true},
17-
rocketChatWebhook: {type: String, required: true},
18-
rocketChatChannelName: {type: String, required: true},
17+
rocketChatWebhook: {type: String, required: false},
18+
rocketChatChannelName: {type: String, required: false},
1919
archived: {type: String, required: true},
2020
username: {type: String, required: true},
2121
secretWebhookKey: {type: String, required: true}
2222
});
2323

24-
// project id, provider, repositoryId must be unique
25-
schema.index({tcDirectId: 1}, {unique: true});
26-
24+
schema.index({tcDirectId: 1});
2725

2826
module.exports = schema;

models/UserMapping.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ const schema = new Schema({
1515
gitlabUserId: Number
1616
});
1717

18-
schema.index({topcoderUsername: 1});
18+
schema.index({topcoderUsername: 1}, {unique: true});
1919

2020
module.exports = schema;

0 commit comments

Comments
 (0)