Skip to content

Commit 67bbf2d

Browse files
Merge pull request #357 from prathambatra/conflicted-claims-2
Added Conflicted Claims Feature
2 parents 737f458 + cf52ef7 commit 67bbf2d

File tree

4 files changed

+113
-13
lines changed

4 files changed

+113
-13
lines changed

routes/root.js

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const du = require('./../utils/datautils')
1212

1313
const { BOSS_END_DATE, BOSS_START_DATE } = require('./../utils/consts')
1414

15+
const { getUrlDetails } = require('../utils/urlUtils')
16+
1517
const route = new Router()
1618

1719
let adminUser = process.env.BOSS_ADMIN || config.secrets.BOSS_DB_USER
@@ -228,17 +230,6 @@ route.get('/claims/add', auth.ensureLoggedInGithub, (req, res) => {
228230
})
229231
})
230232

231-
route.get('/claims/:id', auth.adminOnly, (req, res) => {
232-
du.getClaimById(req.params.id)
233-
.then(claim => {
234-
if (!claim) throw new Error('No claim found')
235-
res.render('pages/claims/id', { claim })
236-
})
237-
.catch(err => {
238-
res.send('Error fetching claim id = ' + escapeHtml(req.params.id))
239-
})
240-
})
241-
242233
route.post('/claims/add', auth.ensureLoggedInGithub, (req, res) => {
243234
if (Date.now() > BOSS_END_DATE.getTime()) {
244235
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) => {
262253
})
263254
})
264255

256+
route.get('/claims/:id', auth.adminOnly, (req, res) => {
257+
du.getClaimById(req.params.id)
258+
.then(claim => {
259+
if (!claim) throw new Error('No claim found')
260+
pullUrlDetail = getUrlDetails(claim["pullUrl"])
261+
issueUrlDetail = getUrlDetails(claim["issueUrl"])
262+
du.getConflictedClaims(claim,issueUrlDetail,pullUrlDetail.type)
263+
.then(conflictedClaims => {
264+
if(conflictedClaims.length === 0)
265+
res.render('pages/claims/id',{claim, hasConflict: false })
266+
else
267+
res.render('pages/claims/id',{ claim, hasConflict: true, conflictedClaims })
268+
})
269+
.catch(err => {
270+
res.send('Error getting conflicting claims')
271+
})
272+
})
273+
.catch(err => {
274+
console.log(err)
275+
res.send('Error fetching claim id = ' + escapeHtml(req.params.id))
276+
})
277+
})
278+
265279
route.post('/claims/:id/update', auth.adminOnly, (req, res) => {
266280
du.updateClaim(req.params.id, req.body)
267281
.then(result => {

utils/datautils.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
const db = require('./db')
55
const fs = require('fs')
66
const consts = require('./consts')
7+
const {Op} = require('sequelize')
78

89
function getContestPeriod(year) {
910
if (year)
@@ -77,6 +78,26 @@ function delClaim(claimId) {
7778
})
7879
}
7980

81+
function getConflictedClaims(claim,issueUrlDetail,pullUrlType) {
82+
projectName = '/' + issueUrlDetail.project + '/'
83+
issueId = '/' + issueUrlDetail.id
84+
pullUrlType = projectName + pullUrlType + '/'
85+
return db.Claim.findAll({
86+
where : {
87+
[Op.and] : [
88+
{
89+
[Op.or] : [
90+
{ issueUrl: { [Op.like]: '%' + projectName + '%' + issueId } },
91+
{ issueUrl: { [Op.like]: '%' + projectName + '%' + issueId + '/' } }
92+
]
93+
},
94+
{ pullUrl: { [Op.like]: '%' + pullUrlType + '%' } },
95+
{ id : { [Op.ne] : claim.id } }
96+
]
97+
}
98+
})
99+
}
100+
80101
function updateClaim(claimId, { status, reason, bounty }) {
81102
const claim = {
82103
action: 'update',
@@ -230,5 +251,6 @@ module.exports = {
230251
getClaimById,
231252
updateClaim,
232253
getCounts,
254+
getConflictedClaims,
233255
getResourceFromUrl
234256
}

utils/urlUtils.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function getUrlDetails(url) {
2+
let urlDetails = {
3+
project : "",
4+
type : "",
5+
id : ""
6+
}
7+
8+
url = url.split('/')
9+
position = url.indexOf('github.com')
10+
11+
urlDetails.project = url[position+2]
12+
urlDetails.type = url[position+3]
13+
urlDetails.id = url[position+4]
14+
15+
return urlDetails;
16+
}
17+
18+
module.exports = { getUrlDetails }

views/pages/claims/id.hbs

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,53 @@
109109
</div>
110110
</div>
111111
</div>
112+
{{#if hasConflict}}
113+
<h3 style="margin-top: 1em;">Conflicted claims</h3>
114+
{{#each conflictedClaims as |conflictedClaim|}}
115+
<div class="card">
116+
<div class="card-body">
117+
<div class="row">
118+
<div class="col-md-4">
119+
<div class="text-center">
120+
<h1>
121+
<span>{{conflictedClaim.bounty}}</span>
122+
</h1>
123+
<small>bounty points</small>
124+
<hr />
125+
<button class="btn btn-primary btn-sm" onclick="OpenConflict({{conflictedClaim.id}})">View conflict</button>
126+
<script>
127+
function OpenConflict(conflictId) {
128+
window.location.href = conflictId
129+
}
130+
</script>
131+
</div>
132+
</div>
133+
<div class="col-md-8">
134+
<a href="/claims/view?username={{conflictedClaim.user}}&status={{status}}">
135+
<h5 class="card-title">{{conflictedClaim.user}}</h5>
136+
</a>
137+
<p class="card-text">
138+
<small class="text-muted">Project : <a
139+
href="https://www.github.com/coding-blocks/">{{conflictedClaim.repo}}</a></small>
140+
<br />
141+
</p>
142+
<p class="card-text">
143+
<span class="text-muted">Issue: <small><a
144+
href="{{conflictedClaim.issueUrl}}">{{conflictedClaim.issueUrl}}</a></small></span>
145+
<br />
146+
147+
<span class="text-muted">Pull Request: <small><a
148+
href="{{conflictedClaim.pullUrl}}">{{conflictedClaim.pullUrl}}</a></small></span>
149+
<br />
150+
</p>
151+
</div>
152+
</div>
153+
</div>
154+
</div>
155+
{{/each}}
156+
{{else}}
157+
<h3 style="margin-top: 1em;">No Conflicted claims</h3>
158+
{{/if}}
112159
</div>
113160
</div>
114161
{{!-- <div class="four wide item">
@@ -120,7 +167,6 @@
120167
<select name="status" class="ui dropdown" id="status">
121168
</select>
122169
</div>
123-
124170
<label>Reason </label>
125171
<textarea name="reason" id="reason"> {{claim.reason}} </textarea>
126172
<br />
@@ -138,4 +184,4 @@
138184
$('#reason').html('').hide();
139185
});
140186
</script>
141-
</div> --}}
187+
</div> --}}

0 commit comments

Comments
 (0)