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

Commit 6cf60bf

Browse files
Merge branch '30060466_updates' into 'develop'
Updates See merge request luettich/receiver!5
2 parents 61b439e + 3f54993 commit 6cf60bf

File tree

9 files changed

+108
-35
lines changed

9 files changed

+108
-35
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,22 @@ The following config parameters are supported, they are defined in `config/defau
3333
| PORT | the port the application will listen on | 3000 |
3434
| LOG_LEVEL | the log level | info |
3535
| TOPIC | the kafka subscribe topic name | events_topic |
36-
| ZOO_KEEPER | the ip:port to connect to ZOO_KEEPER | localhost:2181 |
36+
|KAFKA_OPTIONS | the connection option for kafka | see below about KAFKA options |
3737
| GITHUB_SECRET_TOKEN | the webhook security token for github | |
3838
| GITLAB_SECRET_TOKEN | the webhook security token for gitlab | |
3939
| WATCH_REPOS | the repos we want to watch | |
4040

41+
KAFKA_OPTIONS should be object as described in https://github.com/SOHU-Co/kafka-node#kafkaclient
42+
For using with SSL, the options should be as
43+
```
44+
{
45+
kafkaHost: '<server>',
46+
sslOptions: {
47+
cert: '<certificate>',
48+
key: '<key>'
49+
}
50+
}
51+
```
4152

4253
To change the WATCH_REPOS, you'd better create a `config/local.js` file to override the WATCH_REPOS, see `config/sample-local.js` for example.
4354

@@ -108,6 +119,7 @@ ngrok http 3000
108119
- create an issue in the repo, you can see the logs in `receiver` and `processor`, the `issue.created` event is generated.
109120
- update an issue in the repo, you can see the logs in `receiver` and `processor`, the `issue.updated` event is generated.
110121
- create a comment on an issue, you can see the logs in `receiver` and `processor`, the `comment.created` event is generated.
122+
- update a comment on an issue, you can see the logs in `receiver` and `processor`, the `comment.updated` event is generated.
111123
- assigned a user to an issue, you can see the logs in `receiver` and `processor`, the `issue.assigned` event is generated.
112124
- assigned a user to an issue, you can see the logs in `receiver` and `processor`, the `issue.unassigned` event is generated.
113125
- add a label to an issue, you can see the logs in `receiver` and `processor`, the `issue.labeled` event is generated.

config/default.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,23 @@
44

55
/**
66
* This module contains the configurations of the app.
7-
*
7+
* Changes in 1.1:
8+
* - changes related to https://www.topcoder.com/challenges/30060466
89
* @author TCSCODER
9-
* @version 1.0
10+
* @version 1.1
1011
*/
1112
'use strict';
1213

1314
module.exports = {
1415
PORT: process.env.PORT || 3000, // eslint-disable-line no-magic-numbers
1516
LOG_LEVEL: process.env.LOG_LEVEL || 'info',
1617
TOPIC: process.env.TOPIC || 'events_topic',
17-
ZOO_KEEPER: process.env.ZOO_KEEPER || 'localhost:2181',
1818
GITHUB_SECRET_TOKEN: process.env.GITHUB_SECRET_TOKEN || '',
1919
GITLAB_SECRET_TOKEN: process.env.GITLAB_SECRET_TOKEN || '',
2020
WATCH_REPOS: [
2121
'https://github.com/cwdcwd/challengeFetcher'
22-
]
22+
],
23+
KAFKA_OPTIONS: {
24+
kafkaHost: 'localhost:9092'
25+
}
2326
};

models/CommentUpdatedEvent.js

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

models/common.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
/**
66
* This module contains some common schemas.
7-
*
7+
* Changes in 1.1:
8+
* - changes related to https://www.topcoder.com/challenges/30060466
89
* @author TCSCODER
9-
* @version 1.0
10+
* @version 1.1
1011
*/
1112

1213
'use strict';
@@ -16,6 +17,7 @@ const Joi = require('joi');
1617
// the repository schema
1718
const repositorySchema = Joi.object().keys({
1819
id: Joi.number().required(),
20+
name: Joi.string().required(),
1921
full_name: Joi.string().required()
2022
});
2123

models/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
*/
44
/**
55
* This module contains all the events in this app.
6-
*
6+
* Changes in 1.1:
7+
* - changes related to https://www.topcoder.com/challenges/30060466
78
* @author TCSCODER
8-
* @version 1.0
9+
* @version 1.1
910
*/
1011
'use strict';
1112

1213
const IssueCreatedEvent = require('./IssueCreatedEvent');
1314
const IssueUpdatedEvent = require('./IssueUpdatedEvent');
1415
const CommentCreatedEvent = require('./CommentCreatedEvent');
16+
const CommentUpdatedEvent = require('./CommentUpdatedEvent');
1517
const UserAssignedEvent = require('./UserAssignedEvent');
1618
const UserUnassignedEvent = require('./UserUnassignedEvent');
1719
const LabelAssignedEvent = require('./LabelAssignedEvent');
@@ -23,6 +25,7 @@ module.exports = {
2325
IssueCreatedEvent,
2426
IssueUpdatedEvent,
2527
CommentCreatedEvent,
28+
CommentUpdatedEvent,
2629
UserAssignedEvent,
2730
UserUnassignedEvent,
2831
LabelAssignedEvent,

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"scripts": {
66
"start": "node ./bin/www",
7-
"lint": "eslint . --ignore-pattern 'public/*' --ext .js || true"
7+
"lint": "eslint . --ignore-pattern 'public/*' --ext .js --fix || true"
88
},
99
"engines": {
1010
"node": ">8.6.0"

utils/GithubEventDetector.js

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
/**
66
* This module contains the EventDetector for github.
7-
*
7+
* Changes in 1.1:
8+
* - changes related to https://www.topcoder.com/challenges/30060466
89
* @author TCSCODER
9-
* @version 1.0
10+
* @version 1.1
1011
*/
1112
'use strict';
1213

@@ -33,6 +34,7 @@ const parseIssue = (issue) => ({
3334

3435
const parseRepository = (repository) => ({
3536
id: repository.id,
37+
name: repository.name,
3638
full_name: repository.full_name
3739
});
3840

@@ -88,6 +90,18 @@ IssueUpdatedEvent.parse = (data) => ({
8890

8991
// end the IssueUpdatedEvent
9092

93+
const parseComment = (data) => ({
94+
issue: parseIssue(data.issue),
95+
repository: parseRepository(data.repository),
96+
comment: {
97+
id: data.comment.id,
98+
body: data.comment.body,
99+
user: {
100+
id: data.comment.user.id,
101+
name: data.comment.user.login
102+
}
103+
}
104+
});
91105
// begin the CommentCreatedEvent
92106
const CommentCreatedEvent = {
93107
event: models.CommentCreatedEvent
@@ -100,21 +114,25 @@ CommentCreatedEvent.schema = Joi.object().keys({
100114
comment: Joi.object().required()
101115
});
102116

103-
CommentCreatedEvent.parse = (data) => ({
104-
issue: parseIssue(data.issue),
105-
repository: parseRepository(data.repository),
106-
comment: {
107-
id: data.comment.id,
108-
body: data.comment.body,
109-
user: {
110-
id: data.comment.user.id,
111-
name: data.comment.user.login
112-
}
113-
}
114-
});
117+
CommentCreatedEvent.parse = parseComment;
115118

116119
// end the CommentCreatedEvent
117120

121+
// begin the CommentUpdatedEvent
122+
const CommentUpdatedEvent = {
123+
event: models.CommentUpdatedEvent
124+
};
125+
126+
CommentUpdatedEvent.schema = Joi.object().keys({
127+
action: Joi.string().valid('edited').required(),
128+
issue: Joi.object().required(),
129+
repository: Joi.object().required(),
130+
comment: Joi.object().required()
131+
});
132+
133+
CommentUpdatedEvent.parse = parseComment;
134+
// end the CommentUpdatedEvent
135+
118136
// begin the UserAssignedEvent
119137
const UserAssignedEvent = {
120138
event: models.UserAssignedEvent
@@ -238,6 +256,7 @@ module.exports = new EventDetector('github', [
238256
IssueCreatedEvent,
239257
IssueUpdatedEvent,
240258
CommentCreatedEvent,
259+
CommentUpdatedEvent,
241260
UserAssignedEvent,
242261
UserUnassignedEvent,
243262
LabelAssignedEvent,

utils/kafka.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
*/
44
/**
55
* This module is a wrapper for kafka producer.
6-
*
6+
* Changes in 1.1:
7+
* - changes related to https://www.topcoder.com/challenges/30060466
78
* @author TCSCODER
8-
* @version 1.0
9+
* @version 1.1
910
*/
1011
'use strict';
1112

@@ -16,7 +17,7 @@ const logger = require('./logger');
1617

1718
class Kafka {
1819
constructor() {
19-
this.client = new kafka.Client(config.ZOO_KEEPER);
20+
this.client = new kafka.KafkaClient(config.KAFKA_OPTIONS);
2021
this.producer = new kafka.Producer(this.client);
2122
this.producer.on('ready', () => {
2223
logger.info('kafka producer is ready.');

0 commit comments

Comments
 (0)