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

Commit 3c5d798

Browse files
committed
Merge remote-tracking branch 'github/develop'
2 parents f03c15b + 24cb5a3 commit 3c5d798

14 files changed

+846
-1212
lines changed

.dockerignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
node_modules
2+
npm-debug.log
3+
Dockerfile*
4+
docker-compose*
5+
.dockerignore
6+
.git
7+
.gitignore
8+
README.md
9+
LICENSE
10+
.vscode

Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM node:8.9-alpine
2+
WORKDIR /usr/src/app
3+
COPY ["package.json", "package-lock.json*", "npm-shrinkwrap.json*", "./"]
4+
RUN echo "installing packages"
5+
RUN npm install --silent
6+
COPY . .
7+
EXPOSE 80
8+
CMD npm start

README.md

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,7 @@ npm run lint
2525

2626
## Configuration
2727

28-
The following config parameters are supported, they are defined in `config/default.js` and can be configured in system environment:
29-
30-
31-
| Name | Description | Default |
32-
| :----------------------------- | :----------------------------------------: | :------------------------------: |
33-
| PORT | the port the application will listen on | 3000 |
34-
| LOG_LEVEL | the log level | info |
35-
| TOPIC | the kafka subscribe topic name | tc-x-events |
36-
| KAFKA_OPTIONS | the connection option for kafka | see below about KAFKA options |
37-
| MONGODB_URL | the MongoDB URL which must be same as Topcoder x tool | mongodb://127.0.0.1:27017/topcoderx|
38-
39-
KAFKA_OPTIONS should be object as described in https://github.com/SOHU-Co/kafka-node#kafkaclient
40-
For using with SSL, the options should be as
41-
```
42-
{
43-
kafkaHost: '<server>',
44-
sslOptions: {
45-
cert: '<certificate>',
46-
key: '<key>'
47-
}
48-
}
49-
```
28+
See "configuration.md"
5029

5130
`config/local.js` will not tracked by git.
5231

@@ -63,8 +42,6 @@ use `ngrok` to make your local deploy accessible by internet:
6342
ngrok http 3002
6443
```
6544

66-
Copy the forwarding URL to set in `HOOK_BASE_URL` of topcoder-x in config.json
67-
6845
## Setup for verification
6946
Before verifying the tool, 3 service needs be configured and run them
7047
- processor
@@ -90,6 +67,7 @@ Now, receiver service can receive the webhooks from git host's project. Now you
9067
- create a pull request, you can see the logs in `receiver` and `processor`, the `pull_request.created` event is generated.
9168
- 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`.
9269
- 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`.
70+
- close an issue in the repo, you can see the logs in `receiver` and `processor`, the `issue.closed` event is generated
9371

9472
## Gitlab Verification
9573

@@ -101,4 +79,5 @@ Now, receiver service can receive the webhooks from git host's project. Now you
10179
- add/remove a label to an issue, you can see the logs in `receiver` and `processor`, the `issue.labelUpdated` event is generated.
10280
- create a pull request, you can see the logs in `receiver` and `processor`, the `pull_request.created` event is generated.
10381
- 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`.
104-
- 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`.
82+
- 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`.
83+
- close an issue in the repo, you can see the logs in `receiver` and `processor`, the `issue.closed` event is generated

build.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
4+
# Builds Docker image of Topcoder-X Receiver application.
5+
# This script expects a single argument: NODE_ENV, which must be either
6+
# "development" or "production".
7+
8+
NODE_ENV=$1
9+
10+
ENV=$1
11+
12+
source buildvar.conf
13+
SECRET_FILE_NAME="${APPNAME}-buildsecvar.conf"
14+
cp ./../buildscript/$APPNAME/$SECRET_FILE_NAME.enc .
15+
#ccdecrypt -f $SECRET_FILE_NAME.cpt -K $SECPASSWD
16+
openssl enc -aes-256-cbc -d -in $SECRET_FILE_NAME.enc -out $SECRET_FILE_NAME -k $SECPASSWD
17+
source $SECRET_FILE_NAME
18+
19+
AWS_REGION=$(eval "echo \$${ENV}_AWS_REGION")
20+
AWS_ACCESS_KEY_ID=$(eval "echo \$${ENV}_AWS_ACCESS_KEY_ID")
21+
AWS_SECRET_ACCESS_KEY=$(eval "echo \$${ENV}_AWS_SECRET_ACCESS_KEY")
22+
AWS_ACCOUNT_ID=$(eval "echo \$${ENV}_AWS_ACCOUNT_ID")
23+
AWS_REPOSITORY=$(eval "echo \$${ENV}_AWS_REPOSITORY")
24+
25+
#App variables
26+
KAFKA_CLIENT_CERT=$(eval "echo \$${ENV}_KAFKA_CLIENT_CERT")
27+
KAFKA_CLIENT_CERT_KEY=$(eval "echo \$${ENV}_KAFKA_CLIENT_CERT_KEY")
28+
KAFKA_HOST=$(eval "echo \$${ENV}_KAFKA_URL")
29+
ZOO_KEEPER=$(eval "echo \$${ENV}_ZOO_KEEPER")
30+
TOPIC=$(eval "echo \$${ENV}_TOPIC")
31+
MONGODB_URI=$(eval "echo \$${ENV}_MONGODB_URI")
32+
33+
LOG_LEVEL=$(eval "echo \$${ENV}_LOG_LEVEL")
34+
NODE_ENV=$(eval "echo \$${ENV}_NODE_ENV")
35+
NODE_PORT=$(eval "echo \$${ENV}_NODE_PORT")
36+
JWKSURI=$(eval "echo \$${ENV}_JWKSURI")
37+
TEMPLATE_MAP=$(eval "echo \$${ENV}_TEMPLATE_MAP")
38+
39+
TAG=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/ragnar:$CIRCLE_SHA1
40+
41+
docker build -t $TAG .
42+
43+
# Copies "node_modules" from the created image, if necessary for caching.
44+
docker create --name app $TAG
45+
46+
if [ -d node_modules ]
47+
then
48+
# If "node_modules" directory already exists, we should compare
49+
# "package-lock.json" from the code and from the container to decide,
50+
# whether we need to re-cache, and thus to copy "node_modules" from
51+
# the Docker container.
52+
mv package-lock.json old-package-lock.json
53+
docker cp app:/usr/src/app/package-lock.json package-lock.json
54+
# docker cp .env app:/usr/src/app/
55+
set +eo pipefail
56+
UPDATE_CACHE=$(cmp package-lock.json old-package-lock.json)
57+
set -eo pipefail
58+
else
59+
# If "node_modules" does not exist, then cache must be created.
60+
UPDATE_CACHE=1
61+
fi
62+
63+
if [ "$UPDATE_CACHE" == 1 ]
64+
then
65+
docker cp app:/usr/src/app/node_modules .
66+
fi

config/default.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ module.exports = {
1818
LOG_LEVEL: process.env.LOG_LEVEL || 'info',
1919
TOPIC: process.env.TOPIC || 'tc-x-events',
2020
KAFKA_OPTIONS: {
21-
kafkaHost: process.env.KAFKA_HOST || 'localhost:9092',
22-
sslOptions: {
21+
connectionString: process.env.KAFKA_HOST || 'localhost:9092',
22+
ssl: {
2323
cert: process.env.KAFKA_CLIENT_CERT || fs.readFileSync('./kafka_client.cer'), // eslint-disable-line no-sync
2424
key: process.env.KAFKA_CLIENT_CERT_KEY || fs.readFileSync('./kafka_client.key') // eslint-disable-line no-sync
2525
}

configuration.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Topcoder X Receiver Configuration
2+
The following config parameters are supported, they are defined in `config/default.js` and can be configured in env variables:
3+
4+
5+
| Name | Description | Default |
6+
| :------------------------------------- | :----------------------------------------: | :------------------------------: |
7+
| PORT | The port the application will listen on | 3002 |
8+
| LOG_LEVEL | The log level | info |
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+
16+
KAFKA_OPTIONS should be object as described in https://github.com/oleksiyk/kafka#ssl
17+
For using with SSL, the options should be as
18+
```
19+
{
20+
connectionString: '<server>',
21+
ssl: {
22+
cert: '<certificate>',
23+
key: '<key>'
24+
}
25+
}
26+
```
27+
28+
## Endpoints
29+
30+
- POST /webhooks/github - The webhook handler for github
31+
- POST /webhooks/gitlab - The webhook handler for gitlab
32+
33+
## Github Verification
34+
35+
#### Webhook configuration
36+
37+
Configure a Github project with a webhook with a format like this: https://<receiver URL>:<receiver port>/webhooks/github
38+
39+
#### Smoke test
40+
- Create an issue in the repo, you can see the logs in `receiver`, the `issue.created` event is generated.
41+
42+
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.
43+
44+
## Gitlab Verification
45+
46+
#### Webhook configuration
47+
48+
Configure a Gitlab project with a webhook with a format like this: https://<receiver URL>:<receiver port>/webhooks/gitlab
49+
50+
#### Smoke test
51+
52+
See above - the steps are the same for Github and Gitlab
53+
54+
## Debugging
55+
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.

models/IssueClosedEvent.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) 2018 TopCoder, Inc. All rights reserved.
3+
*/
4+
/**
5+
* This module contains the schema of the issue closed schema.
6+
*
7+
* @author veshu
8+
* @version 1.0
9+
*/
10+
'use strict';
11+
const Joi = require('joi');
12+
const {issueSchema, repositorySchema} = require('./common');
13+
14+
const IssueClosedEvent = {
15+
name: 'issue.closed',
16+
17+
schema: Joi.object().keys({
18+
issue: issueSchema.required(),
19+
repository: repositorySchema.required(),
20+
assignee: Joi.object().keys({
21+
id: Joi.number().allow(null)
22+
}).required()
23+
})
24+
};
25+
26+
27+
module.exports = IssueClosedEvent;
28+

models/Project.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@ 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});
24+
schema.index({tcDirectId: 1});
2625

2726

2827
module.exports = schema;

models/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ mongoose.Promise = global.Promise;
1717
const connection = mongoose.createConnection(config.MONGODB_URL);
1818
const IssueCreatedEvent = require('./IssueCreatedEvent');
1919
const IssueUpdatedEvent = require('./IssueUpdatedEvent');
20+
const IssueClosedEvent = require('./IssueClosedEvent');
2021
const CommentCreatedEvent = require('./CommentCreatedEvent');
2122
const CommentUpdatedEvent = require('./CommentUpdatedEvent');
2223
const UserAssignedEvent = require('./UserAssignedEvent');
@@ -36,5 +37,6 @@ module.exports = {
3637
PullRequestCreatedEvent,
3738
PullRequestClosedEvent,
3839
LabelUpdatedEvent,
39-
Project: connection.model('Project', Project)
40+
Project: connection.model('Project', Project),
41+
IssueClosedEvent
4042
};

0 commit comments

Comments
 (0)