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

Commit 43d0127

Browse files
Ignore AV Scan reviews
1 parent 02b8024 commit 43d0127

File tree

5 files changed

+46
-4
lines changed

5 files changed

+46
-4
lines changed

config/default.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module.exports = {
2121

2222
LEADERBOARD_API_URL: process.env.LEADERBOARD_API_URL || 'https://api.topcoder-dev.com/v5/leaderboard',
2323
SUBMISSION_API_URL: process.env.SUBMISSION_API_URL || 'https://api.topcoder-dev.com/v5/submissions',
24+
REVIEW_TYPE_URL: process.env.REVIEW_TYPE_URL || 'https://api.topcoder-dev.com/v5/reviewTypes',
2425

2526
AUTH0_URL: process.env.AUTH0_URL,
2627
AUTH0_AUDIENCE: process.env.AUTH0_AUDIENCE,

src/app.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const logger = require('./common/logger')
88
const Kafka = require('no-kafka')
99
const healthcheck = require('topcoder-healthcheck-dropin')
1010
const ProcessorService = require('./services/ProcessorService')
11+
const helper = require('./common/helper')
1112

1213
// start Kafka consumer
1314
logger.info('Start Kafka consumer.')
@@ -19,7 +20,7 @@ if (config.KAFKA_CLIENT_CERT && config.KAFKA_CLIENT_CERT_KEY) {
1920
const consumer = new Kafka.GroupConsumer(options)
2021

2122
// data handler
22-
const dataHandler = (messageSet, topic, partition) => Promise.each(messageSet, (m) => {
23+
const dataHandler = (messageSet, topic, partition) => Promise.each(messageSet, async (m) => {
2324
const message = m.message.value.toString('utf8')
2425
logger.info(`Handle Kafka event message; Topic: ${topic}; Partition: ${partition}; Offset: ${
2526
m.offset}; Message: ${message}.`)
@@ -46,6 +47,13 @@ const dataHandler = (messageSet, topic, partition) => Promise.each(messageSet, (
4647
return
4748
}
4849

50+
const avScanTypeId = await helper.getreviewTypeId('AV Scan')
51+
52+
if (messageJSON.payload.typeId === avScanTypeId) {
53+
logger.debug(`Ignoring AV Scan reviews from topic ${messageJSON.topic}`)
54+
return false
55+
}
56+
4957
return (async () => {
5058
switch (topic) {
5159
case config.CREATE_DATA_TOPIC:

src/common/helper.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ const m2mAuth = require('tc-core-library-js').auth.m2m
99

1010
const m2m = m2mAuth(_.pick(config, ['AUTH0_URL', 'AUTH0_AUDIENCE', 'TOKEN_CACHE_TIME', 'AUTH0_PROXY_SERVER_URL']))
1111

12+
// Variable to cache reviewTypes from Submission API
13+
const reviewTypes = {}
14+
1215
/*
1316
* Function to get M2M token
1417
* @returns {Promise}
@@ -55,6 +58,25 @@ const reqToAPI = async (reqType, path, reqBody) => {
5558
})
5659
}
5760

61+
/*
62+
* Function to get reviewTypeId from Name
63+
* @param {String} reviewTypeName Name of the reviewType
64+
* @returns {String} reviewTypeId
65+
*/
66+
const getreviewTypeId = async (reviewTypeName) => {
67+
if (!reviewTypes[reviewTypeName]) {
68+
// Get review type id from Submission API
69+
const response = await reqToAPI('GET', `${config.REVIEW_TYPE_URL}?name=${reviewTypeName}`)
70+
if (response.body && response.body.length !== 0) {
71+
reviewTypes[reviewTypeName] = response.body[0].id
72+
} else {
73+
reviewTypes[reviewTypeName] = null
74+
}
75+
}
76+
return reviewTypes[reviewTypeName]
77+
}
78+
5879
module.exports = {
59-
reqToAPI
80+
reqToAPI,
81+
getreviewTypeId
6082
}

test/common/prepare.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
const nock = require('nock')
66
const prepare = require('mocha-prepare')
7-
const { submissionAPIResponse } = require('./testData')
7+
const { submissionAPIResponse, reviewTypesResponse } = require('./testData')
88

99
prepare(function (done) {
1010
nock(/\.com/)
@@ -27,6 +27,8 @@ prepare(function (done) {
2727
.reply(200)
2828
.delete('/v5/leaderboard/review/49871146-eb0a-4d0e-ab9a-adc94018c5da')
2929
.reply(204)
30+
.get('/v5/reviewTypes?name=AV%20Scan')
31+
.reply(200, reviewTypesResponse)
3032

3133
done()
3234
}, function (done) {

test/common/testData.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,16 @@ const submissionAPIResponse = [
116116
}
117117
]
118118

119+
const reviewTypesResponse = [
120+
{
121+
'name': 'AV Scan',
122+
'id': '6da98d0f-e663-4539-8507-cd6c9e0e56d8',
123+
'isActive': true
124+
}
125+
]
126+
119127
module.exports = {
120128
submissionAPIResponse,
121-
testTopics
129+
testTopics,
130+
reviewTypesResponse
122131
}

0 commit comments

Comments
 (0)