diff --git a/routes/root.js b/routes/root.js index 9fa1f24..0e9b722 100644 --- a/routes/root.js +++ b/routes/root.js @@ -12,6 +12,8 @@ const du = require('./../utils/datautils') const { BOSS_END_DATE, BOSS_START_DATE } = require('./../utils/consts') +const { getUrlDetails } = require('../utils/urlUtils') + const route = new Router() let adminUser = process.env.BOSS_ADMIN || config.secrets.BOSS_DB_USER @@ -228,17 +230,6 @@ route.get('/claims/add', auth.ensureLoggedInGithub, (req, res) => { }) }) -route.get('/claims/:id', auth.adminOnly, (req, res) => { - du.getClaimById(req.params.id) - .then(claim => { - if (!claim) throw new Error('No claim found') - res.render('pages/claims/id', { claim }) - }) - .catch(err => { - res.send('Error fetching claim id = ' + escapeHtml(req.params.id)) - }) -}) - route.post('/claims/add', auth.ensureLoggedInGithub, (req, res) => { if (Date.now() > BOSS_END_DATE.getTime()) { return res.send("Sorry. Boss has ended, can't add claim from now.") @@ -262,6 +253,29 @@ route.post('/claims/add', auth.ensureLoggedInGithub, (req, res) => { }) }) +route.get('/claims/:id', auth.adminOnly, (req, res) => { + du.getClaimById(req.params.id) + .then(claim => { + if (!claim) throw new Error('No claim found') + pullUrlDetail = getUrlDetails(claim["pullUrl"]) + issueUrlDetail = getUrlDetails(claim["issueUrl"]) + du.getConflictedClaims(claim,issueUrlDetail,pullUrlDetail.type) + .then(conflictedClaims => { + if(conflictedClaims.length === 0) + res.render('pages/claims/id',{claim, hasConflict: false }) + else + res.render('pages/claims/id',{ claim, hasConflict: true, conflictedClaims }) + }) + .catch(err => { + res.send('Error getting conflicting claims') + }) + }) + .catch(err => { + console.log(err) + res.send('Error fetching claim id = ' + escapeHtml(req.params.id)) + }) +}) + route.post('/claims/:id/update', auth.adminOnly, (req, res) => { du.updateClaim(req.params.id, req.body) .then(result => { diff --git a/utils/datautils.js b/utils/datautils.js index dba6e0d..503a30f 100644 --- a/utils/datautils.js +++ b/utils/datautils.js @@ -4,6 +4,7 @@ const db = require('./db') const fs = require('fs') const consts = require('./consts') +const {Op} = require('sequelize') function getContestPeriod(year) { if (year) @@ -77,6 +78,26 @@ function delClaim(claimId) { }) } +function getConflictedClaims(claim,issueUrlDetail,pullUrlType) { + projectName = '/' + issueUrlDetail.project + '/' + issueId = '/' + issueUrlDetail.id + pullUrlType = projectName + pullUrlType + '/' + return db.Claim.findAll({ + where : { + [Op.and] : [ + { + [Op.or] : [ + { issueUrl: { [Op.like]: '%' + projectName + '%' + issueId } }, + { issueUrl: { [Op.like]: '%' + projectName + '%' + issueId + '/' } } + ] + }, + { pullUrl: { [Op.like]: '%' + pullUrlType + '%' } }, + { id : { [Op.ne] : claim.id } } + ] + } + }) +} + function updateClaim(claimId, { status, reason, bounty }) { const claim = { action: 'update', @@ -230,5 +251,6 @@ module.exports = { getClaimById, updateClaim, getCounts, + getConflictedClaims, getResourceFromUrl } diff --git a/utils/urlUtils.js b/utils/urlUtils.js new file mode 100644 index 0000000..6389d0d --- /dev/null +++ b/utils/urlUtils.js @@ -0,0 +1,18 @@ +function getUrlDetails(url) { + let urlDetails = { + project : "", + type : "", + id : "" + } + + url = url.split('/') + position = url.indexOf('github.com') + + urlDetails.project = url[position+2] + urlDetails.type = url[position+3] + urlDetails.id = url[position+4] + + return urlDetails; +} + +module.exports = { getUrlDetails } \ No newline at end of file diff --git a/views/pages/claims/id.hbs b/views/pages/claims/id.hbs index c82d1e1..db0a943 100644 --- a/views/pages/claims/id.hbs +++ b/views/pages/claims/id.hbs @@ -109,6 +109,53 @@ + {{#if hasConflict}} +

Conflicted claims

+ {{#each conflictedClaims as |conflictedClaim|}} +
+
+
+
+
+

+ {{conflictedClaim.bounty}} +

+ bounty points +
+ + +
+
+ +
+
+
+ {{/each}} + {{else}} +

No Conflicted claims

+ {{/if}} {{!--
@@ -120,7 +167,6 @@
-
@@ -138,4 +184,4 @@ $('#reason').html('').hide(); }); - --}} + --}} \ No newline at end of file