Skip to content

Commit 6ad5b9f

Browse files
New Feature : conflicting claims : Fixes #260
1 parent 857e507 commit 6ad5b9f

File tree

3 files changed

+168
-77
lines changed

3 files changed

+168
-77
lines changed

routes/root.js

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,52 @@ route.get('/claims/add', auth.ensureLoggedInGithub, (req, res) => {
193193
})
194194
})
195195

196-
route.get('/claims/:id', auth.adminOnly, (req, res) => {
197-
du.getClaimById(req.params.id)
198-
.then(claim => {
199-
if (!claim) throw new Error('No claim found')
200-
res.render('pages/claims/id', { claim })
201-
})
202-
.catch(err => {
203-
res.send('Error fetching claim id = ' + escapeHtml(req.params.id))
196+
route.get('/claims/:id', auth.adminOnly, async (req, res) => {
197+
try {
198+
const claimInfo = await du.getClaimById(req.params.id)
199+
if (!claimInfo) {
200+
throw new Error('Error finding claim')
201+
}
202+
203+
const prSlug = new URL(claimInfo.pullUrl).pathname.replace(/\/+$/, '')
204+
let response, conflicts
205+
206+
/**
207+
* the database has internal checks for duplicate items in the pull request column
208+
* therefore the main task of this segment is to handle the conditions when
209+
* 1. issue is passed in both fields, pull-request column and issue column
210+
* 2. pull request is submitted with a tailing slash, or url modifications like
211+
* https, or hashes, or language slugs */
212+
if (prSlug.includes('pull')) {
213+
/**
214+
* this segment handles point number 2 mentioned above by checking only the
215+
* useful and important , unchanged, and unique identity of a pull request
216+
*/
217+
response = await du.getConflictingClaimByPr(prSlug)
218+
conflicts = response[0].filter((claim) => claim.id !== claimInfo.id)
219+
} else {
220+
/**
221+
* this segment handles the point number 1 mentioned above, by checking the
222+
* url of the issue passed into pull-request column of current claim uniquely
223+
* across database table for similar entries in the issues column
224+
*/
225+
response = await du.getConflictingClaimByIssue(prSlug)
226+
conflicts = response[0].filter((claim) => claim.id !== claimInfo.id)
227+
}
228+
229+
/**
230+
* now rendering the ui of the admin panel and populating it with conflicts data
231+
* the following line displays the raw json used to build the page, use while debugging
232+
* res.json({ claimInfo, conflicts })
233+
*/
234+
res.render('pages/claims/id', { claim: claimInfo, conflicts })
235+
} catch (err) {
236+
console.log(err.message)
237+
res.status(500).json({
238+
error: true,
239+
message: 'There was some error processing your request'
204240
})
241+
}
205242
})
206243

207244
route.post('/claims/add', auth.ensureLoggedInGithub, (req, res) => {

utils/datautils.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ function getClaimById(claimId) {
4848
return db.Claim.findById(claimId)
4949
}
5050

51+
function getConflictingClaimByPr(pullRequestId) {
52+
return db.Database.query(
53+
`SELECT * FROM claims WHERE "pullUrl" LIKE '%${pullRequestId}%';`
54+
)
55+
}
56+
57+
function getConflictingClaimByIssue(issueId) {
58+
return db.Database.query(
59+
`SELECT * FROM claims WHERE "issueUrl" LIKE '%${issueId}%';`
60+
)
61+
}
62+
5163
function delClaim(claimId) {
5264
if (isNaN(+claimId)) {
5365
return res.send('ClaimId must be a number')
@@ -161,5 +173,7 @@ module.exports = {
161173
getLeaderboard,
162174
getClaimById,
163175
updateClaim,
164-
getCounts
176+
getCounts,
177+
getConflictingClaimByIssue,
178+
getConflictingClaimByPr
165179
}

views/pages/claims/id.hbs

Lines changed: 108 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,116 @@
1-
<div class="four wide item">
2-
<div class="image">
3-
<div class="ui statistic">
4-
<div class="value">
5-
{{claim.bounty}}
6-
</div>
7-
<div class="label">
8-
BOUNTY POINTS
9-
</div>
10-
</div>
11-
</div>
12-
<div class="middle aligned content">
13-
<a class="header">{{claim.user}}</a>
14-
<div class="meta">
15-
<span>{{claim.repo}}</span>
16-
</div>
17-
<div class="description">
18-
<p>
19-
Issue : <a href="{{claim.issueUrl}}">{{claim.issueUrl}}</a>
20-
</p>
21-
<p>
22-
Pull : <a href="{{claim.pullUrl}}">{{claim.pullUrl}}</a>
23-
</p>
24-
</div>
25-
<div class="extra">
26-
{{#equal claim.status "claimed"}}
27-
<div class="ui label yellow">{{claim.status}}</div>
28-
{{/equal}}
29-
{{#equal claim.status "accepted"}}
30-
<div class="ui label green">{{claim.status}}</div>
31-
{{/equal}}
32-
{{#equal claim.status "rejected"}}
33-
<div class="ui label red">{{claim.status}}</div>
34-
{{/equal}}
35-
</div>
36-
</div>
37-
<form class="ui form" style="padding: 3em" method="post" action="/claims/{{claim.id}}/update">
38-
<div class="four wide field">
39-
<label>Final Bounty Points</label>
40-
<input name="bounty" value="{{claim.bounty}}">
41-
<label>Update Status</label>
42-
<select name="status" class="ui dropdown" id="status">
43-
<option value="claimed">Claimed</option>
44-
<option value="rejected">Rejected</option>
45-
<option value="accepted">Accepted</option>
46-
<option value="disputed">Disputed</option>
47-
<option value="revoked">Revoked</option>
48-
</select>
49-
</div>
1+
<div class="ui container">
2+
<div class="ui two column grid">
3+
<div class="column">
4+
<div class="four wide item">
5+
<div class="image">
6+
<div class="ui statistic">
7+
<div class="value">
8+
{{claim.bounty}}
9+
</div>
10+
<div class="label">
11+
BOUNTY POINTS
12+
</div>
13+
</div>
14+
</div>
15+
<div class="middle aligned content">
16+
<a class="header">{{claim.user}}</a>
17+
<div class="meta">
18+
<span>{{claim.repo}}</span>
19+
</div>
20+
<div class="description">
21+
<p>
22+
Issue : <a href="{{claim.issueUrl}}">{{claim.issueUrl}}</a>
23+
</p>
24+
<p>
25+
Pull : <a href="{{claim.pullUrl}}">{{claim.pullUrl}}</a>
26+
</p>
27+
</div>
28+
<div class="extra">
29+
{{#equal claim.status "claimed"}}
30+
<div class="ui label yellow">{{claim.status}}</div>
31+
{{/equal}}
32+
{{#equal claim.status "accepted"}}
33+
<div class="ui label green">{{claim.status}}</div>
34+
{{/equal}}
35+
{{#equal claim.status "rejected"}}
36+
<div class="ui label red">{{claim.status}}</div>
37+
{{/equal}}
38+
</div>
39+
</div>
40+
<form class="ui form" style="padding: 3em" method="post" action="/claims/{{claim.id}}/update">
41+
<div class="four wide field">
42+
<label>Final Bounty Points</label>
43+
<input name="bounty" value="{{claim.bounty}}">
44+
<label>Update Status</label>
45+
<select name="status" class="ui dropdown" id="status">
46+
<option value="claimed">Claimed</option>
47+
<option value="rejected">Rejected</option>
48+
<option value="accepted">Accepted</option>
49+
<option value="disputed">Disputed</option>
50+
<option value="revoked">Revoked</option>
51+
</select>
52+
</div>
53+
54+
<label>Reason </label>
55+
<textarea name="reason" id="reason"> {{claim.reason}} </textarea>
56+
<br />
57+
<button class="ui button green" type="submit">Submit</button>
5058

51-
<label>Reason </label>
52-
<textarea name="reason" id="reason"> {{claim.reason}} </textarea>
53-
<br/>
54-
<button class="ui button green" type="submit">Submit</button>
5559

60+
</form>
61+
<script>
5662
57-
</form>
58-
<script>
63+
$('select.dropdown').dropdown();
5964
60-
$('select.dropdown').dropdown();
65+
{ {#unless claim.reason } }
66+
$('#reason').hide();
67+
{
68+
{
69+
/unless}}
6170
62-
{{#unless claim.reason}}
63-
$('#reason').hide();
64-
{{/unless}}
71+
$('select').on('change', function (e) {
72+
let status = $('#status option:selected').text();
73+
if (['Rejected', 'Disputed', 'Revoked'].includes(status))
74+
$('#reason').show();
75+
else
76+
$('#reason').html('').hide();
6577
66-
$('select').on('change', function (e){
67-
let status = $('#status option:selected').text();
68-
if( ['Rejected' , 'Disputed' , 'Revoked'].includes(status) )
69-
$('#reason').show();
70-
else
71-
$('#reason').html('').hide();
78+
});
7279
73-
});
80+
</script>
81+
</div>
82+
</div>
83+
<div class="column">
84+
<h2>Conflicts</h2>
85+
{{#if conflicts}}
86+
This following claims collides with the current claim
87+
<div class="ui two column grid">
88+
{{#conflicts}}
89+
<div class="column">
90+
<div class="ui fluid card">
91+
<div class="content">
92+
<div class="header">Claim ID : {{id}}</div>
93+
<div class="meta">Bounty : {{bounty}}</div>
94+
<div class="meta">By : {{user}}</div>
95+
<div class="description">
96+
<div class="ui two column grid">
97+
<div class="column">
98+
<a href="{{issueUrl}}">View Issue</a>
99+
</div>
100+
<div class="column">
101+
<a href="{{pullUrl}}">View PR</a>
102+
</div>
103+
</div>
104+
</div>
105+
</div>
74106

75-
</script>
76-
</div>
107+
</div>
108+
</div>
109+
{{/conflicts}}
110+
</div>
111+
{{else}}
112+
There are no conflicting claims
113+
{{/if}}
114+
</div>
115+
</div>
116+
</div>

0 commit comments

Comments
 (0)