|
1 |
| -## Requirements |
2 |
| - |
3 |
| -- Nodejs 8 is required |
4 |
| -- [Apache Kafka](https://kafka.apache.org/) |
5 |
| - - [Local installation guide](https://devops.profitbricks.com/tutorials/install-and-configure-apache-kafka-on-ubuntu-1604-1/) |
6 |
| -## Install dependencies |
7 |
| - |
8 |
| -```shell |
9 |
| -npm install |
10 |
| -``` |
11 |
| - |
12 |
| -## Source code lint |
13 |
| - |
14 |
| -eslint is used to lint the javascript source code: |
15 |
| - |
16 |
| -```shell |
17 |
| -npm run lint |
18 |
| -``` |
19 |
| - |
20 |
| -## Endpoints |
21 |
| - |
22 |
| -- POST /webhooks/github - The webhook handler for github |
23 |
| -- POST /webhooks/gitlab - The webhook handler for gitlab |
24 |
| - |
25 |
| - |
26 |
| -## Configuration |
27 |
| - |
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 |
| -| WEBHOOK_SECRET_TOKEN | the webhook security token for githost, it must be same as `WEBHOOK_SECRET_TOKEN` configured for Topcoder-X-backend| `ka75hsrq65cFEr61Hd4x`| |
37 |
| -|KAFKA_OPTIONS | the connection option for kafka | see below about KAFKA options | |
38 |
| -| MONGODB_URL | the MongoDB URL which must be same as Ragnar tool | mongodb://127.0.0.1:27017/ragnar| |
39 |
| - |
40 |
| -KAFKA_OPTIONS should be object as described in https://github.com/SOHU-Co/kafka-node#kafkaclient |
41 |
| -For using with SSL, the options should be as |
42 |
| -``` |
43 |
| - { |
44 |
| - kafkaHost: '<server>', |
45 |
| - sslOptions: { |
46 |
| - cert: '<certificate>', |
47 |
| - key: '<key>' |
48 |
| - } |
49 |
| - } |
50 |
| -``` |
51 |
| - |
52 |
| -`config/local.js` will not tracked by git. |
53 |
| - |
54 |
| -## Local Setup |
55 |
| - |
56 |
| -```shell |
57 |
| -npm start |
58 |
| -``` |
59 |
| - |
60 |
| -Server should be started at port 3002. |
61 |
| - |
62 |
| -use `ngrok` to make your local deploy accessible by internet: |
63 |
| -```shell |
64 |
| -ngrok http 3002 |
65 |
| -``` |
66 |
| - |
67 |
| -Copy the forwarding URL to set in `HOOK_BASE_URL` of topcoder-x-ui in config.json |
68 |
| - |
69 |
| -## Setup for verification |
70 |
| -Before verifying the tool, 4 service needs be configured and run them |
71 |
| -- processor |
72 |
| -- receiver |
73 |
| -- Ragnar Tool |
74 |
| -- Topcoder X (both backend and UI) |
75 |
| - |
76 |
| -First login in Ragnar tool with admin and Add owner for which requires topcoder handle, git host's username and type of git host. |
77 |
| - |
78 |
| -Go to Topcoder X UI login with above used topcoder username and |
79 |
| -- go to settings and make sure git hosts are correctly setup, if not click setup and authorize to setup. |
80 |
| - |
81 |
| -- 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. |
82 |
| - |
83 |
| -Now, receiver service can receive the webhooks from git host's project. Now you can verify this service by following the verfication steps below |
84 |
| - |
85 |
| -## GitHub Verification |
86 |
| - |
87 |
| -- create an issue in the repo, you can see the logs in `receiver` and `processor`, the `issue.created` event is generated. |
88 |
| -- update an issue in the repo, you can see the logs in `receiver` and `processor`, the `issue.updated` event is generated. |
89 |
| -- create a comment on an issue, you can see the logs in `receiver` and `processor`, the `comment.created` event is generated. |
90 |
| -- update a comment on an issue, you can see the logs in `receiver` and `processor`, the `comment.updated` event is generated. |
91 |
| -- assigned a user to an issue, you can see the logs in `receiver` and `processor`, the `issue.assigned` event is generated. |
92 |
| -- un-assigned a user to an issue, you can see the logs in `receiver` and `processor`, the `issue.unassigned` event is generated. |
93 |
| -- add/remove a label to an issue, you can see the logs in `receiver` and `processor`, the `issue.labelUpdated` event is generated. |
94 |
| -- create a pull request, you can see the logs in `receiver` and `processor`, the `pull_request.created` event is generated. |
95 |
| -- 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`. |
96 |
| -- 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`. |
97 |
| - |
98 |
| -## Gitlab Verification |
99 |
| - |
100 |
| -- create an issue in the repo, you can see the logs in `receiver` and `processor`, the `issue.created` event is generated. |
101 |
| -- update an issue in the repo, you can see the logs in `receiver` and `processor`, the `issue.updated` event is generated. |
102 |
| -- create a comment on an issue, you can see the logs in `receiver` and `processor`, the `comment.created` event is generated. |
103 |
| -- assigned a user to an issue, you can see the logs in `receiver` and `processor`, the `issue.assigned` event is generated. |
104 |
| -- un-assigned a user to an issue, you can see the logs in `receiver` and `processor`, the `issue.unassigned` event is generated. |
105 |
| -- add/remove a label to an issue, you can see the logs in `receiver` and `processor`, the `issue.labelUpdated` event is generated. |
106 |
| -- create a pull request, you can see the logs in `receiver` and `processor`, the `pull_request.created` event is generated. |
107 |
| -- 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`. |
| 1 | +## Requirements |
| 2 | + |
| 3 | +- Nodejs 8 is required |
| 4 | +- [Apache Kafka](https://kafka.apache.org/) |
| 5 | + - [Local installation guide](https://devops.profitbricks.com/tutorials/install-and-configure-apache-kafka-on-ubuntu-1604-1/) |
| 6 | +## Install dependencies |
| 7 | + |
| 8 | +```shell |
| 9 | +npm install |
| 10 | +``` |
| 11 | + |
| 12 | +## Source code lint |
| 13 | + |
| 14 | +eslint is used to lint the javascript source code: |
| 15 | + |
| 16 | +```shell |
| 17 | +npm run lint |
| 18 | +``` |
| 19 | + |
| 20 | +## Endpoints |
| 21 | + |
| 22 | +- POST /webhooks/github - The webhook handler for github |
| 23 | +- POST /webhooks/gitlab - The webhook handler for gitlab |
| 24 | + |
| 25 | + |
| 26 | +## Configuration |
| 27 | + |
| 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 | +``` |
| 50 | + |
| 51 | +`config/local.js` will not tracked by git. |
| 52 | + |
| 53 | +## Local Setup |
| 54 | + |
| 55 | +```shell |
| 56 | +npm start |
| 57 | +``` |
| 58 | + |
| 59 | +Server should be started at port 3002. |
| 60 | + |
| 61 | +use `ngrok` to make your local deploy accessible by internet: |
| 62 | +```shell |
| 63 | +ngrok http 3002 |
| 64 | +``` |
| 65 | + |
| 66 | +Copy the forwarding URL to set in `HOOK_BASE_URL` of topcoder-x in config.json |
| 67 | + |
| 68 | +## Setup for verification |
| 69 | +Before verifying the tool, 3 service needs be configured and run them |
| 70 | +- processor |
| 71 | +- receiver |
| 72 | +- Topcoder X |
| 73 | + |
| 74 | +Go to Topcoder X UI login with above used topcoder username and |
| 75 | +- go to settings and make sure git hosts are correctly setup, if not click setup and authorize to setup. |
| 76 | + |
| 77 | +- 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, verify that webhooks are set up correctly on git host's project. |
| 78 | + |
| 79 | +Now, receiver service can receive the webhooks from git host's project. Now you can verify this service by following the verfication steps below |
| 80 | + |
| 81 | +## GitHub Verification |
| 82 | + |
| 83 | +- create an issue in the repo, you can see the logs in `receiver` and `processor`, the `issue.created` event is generated. |
| 84 | +- update an issue in the repo, you can see the logs in `receiver` and `processor`, the `issue.updated` event is generated. |
| 85 | +- create a comment on an issue, you can see the logs in `receiver` and `processor`, the `comment.created` event is generated. |
| 86 | +- update a comment on an issue, you can see the logs in `receiver` and `processor`, the `comment.updated` event is generated. |
| 87 | +- assigned a user to an issue, you can see the logs in `receiver` and `processor`, the `issue.assigned` event is generated. |
| 88 | +- un-assigned a user to an issue, you can see the logs in `receiver` and `processor`, the `issue.unassigned` event is generated. |
| 89 | +- add/remove a label to an issue, you can see the logs in `receiver` and `processor`, the `issue.labelUpdated` event is generated. |
| 90 | +- create a pull request, you can see the logs in `receiver` and `processor`, the `pull_request.created` event is generated. |
| 91 | +- 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`. |
| 92 | +- 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`. |
| 93 | + |
| 94 | +## Gitlab Verification |
| 95 | + |
| 96 | +- create an issue in the repo, you can see the logs in `receiver` and `processor`, the `issue.created` event is generated. |
| 97 | +- update an issue in the repo, you can see the logs in `receiver` and `processor`, the `issue.updated` event is generated. |
| 98 | +- create a comment on an issue, you can see the logs in `receiver` and `processor`, the `comment.created` event is generated. |
| 99 | +- assigned a user to an issue, you can see the logs in `receiver` and `processor`, the `issue.assigned` event is generated. |
| 100 | +- un-assigned a user to an issue, you can see the logs in `receiver` and `processor`, the `issue.unassigned` event is generated. |
| 101 | +- add/remove a label to an issue, you can see the logs in `receiver` and `processor`, the `issue.labelUpdated` event is generated. |
| 102 | +- create a pull request, you can see the logs in `receiver` and `processor`, the `pull_request.created` event is generated. |
| 103 | +- 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`. |
108 | 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`.
|
0 commit comments