Skip to content

New Feature : conflicting claims #279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 54 additions & 9 deletions routes/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,60 @@ 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.get('/claims/:id', async (req, res) => {
try {
const claimInfo = await du.getClaimById(req.params.id)
if (!claimInfo) {
throw new Error('Error finding claim')
}

const genericUrl = new URL(claimInfo.pullUrl).pathname.replace(/\/+$/, '')
const urlDetails = {
project: genericUrl.split('github.com/')[1].split('/')[1],
type: genericUrl.split('github.com/')[1].split('/')[2],
id: genericUrl.split('github.com/')[1].split('/')[3],
}

let response, conflicts

/**
* the database has internal checks for duplicate items in the pull request column
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does not cover all the cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please mention which type of case is not handled

* therefore the main task of this segment is to handle the conditions when
* 1. issue is passed in both fields, pull-request column and issue column
* 2. pull request is submitted with a tailing slash, or url modifications like
* https, or hashes, or language slugs */
if (urlDetails.type === 'pull') {
/**
* this segment handles point number 2 mentioned above by checking only the
* useful and important , unchanged, and unique identity of a pull request
*/
response = await du.getConflictingClaimByPr(genericUrl)
conflicts = response[0].filter((claim) => claim.id !== claimInfo.id)
} else {
/**
* this segment handles the point number 1 mentioned above, by checking the
* url of the issue passed into pull-request column of current claim uniquely
* across database table for similar entries in the issues column
*/
response = await du.getConflictingClaimByIssue(genericUrl)
conflicts = response[0].filter((claim) => claim.id !== claimInfo.id)
}

/**
* now rendering the ui of the admin panel and populating it with conflicts data
* the following line displays the raw json used to build the page, use while debugging
* res.json({ claimInfo, conflicts })
*/
res.json({claimInfo, conflicts})
// res.render('pages/claims/id', { claim: claimInfo, conflicts })
} catch (err) {
console.log(err.message)
// res.status(500).json({
// error: true,
// message: 'There was some error processing your request'
// })
res.status(200).json({message:err.message})
}
})

route.post('/claims/add', auth.ensureLoggedInGithub, (req, res) => {
Expand Down
16 changes: 15 additions & 1 deletion utils/datautils.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ function getClaimById(claimId) {
return db.Claim.findById(claimId)
}

function getConflictingClaimByPr(genericUrl) {
return db.Database.query(
`SELECT * FROM claims WHERE "pullUrl" LIKE '%${genericUrl}%';`
)
}

function getConflictingClaimByIssue(genericUrl) {
return db.Database.query(
`SELECT * FROM claims WHERE "issueUrl" LIKE '%${genericUrl}%';`
)
}

function delClaim(claimId) {
if (isNaN(+claimId)) {
return res.send('ClaimId must be a number')
Expand Down Expand Up @@ -161,5 +173,7 @@ module.exports = {
getLeaderboard,
getClaimById,
updateClaim,
getCounts
getCounts,
getConflictingClaimByIssue,
getConflictingClaimByPr
}
176 changes: 108 additions & 68 deletions views/pages/claims/id.hbs
Original file line number Diff line number Diff line change
@@ -1,76 +1,116 @@
<div class="four wide item">
<div class="image">
<div class="ui statistic">
<div class="value">
{{claim.bounty}}
</div>
<div class="label">
BOUNTY POINTS
</div>
</div>
</div>
<div class="middle aligned content">
<a class="header">{{claim.user}}</a>
<div class="meta">
<span>{{claim.repo}}</span>
</div>
<div class="description">
<p>
Issue : <a href="{{claim.issueUrl}}">{{claim.issueUrl}}</a>
</p>
<p>
Pull : <a href="{{claim.pullUrl}}">{{claim.pullUrl}}</a>
</p>
</div>
<div class="extra">
{{#equal claim.status "claimed"}}
<div class="ui label yellow">{{claim.status}}</div>
{{/equal}}
{{#equal claim.status "accepted"}}
<div class="ui label green">{{claim.status}}</div>
{{/equal}}
{{#equal claim.status "rejected"}}
<div class="ui label red">{{claim.status}}</div>
{{/equal}}
</div>
</div>
<form class="ui form" style="padding: 3em" method="post" action="/claims/{{claim.id}}/update">
<div class="four wide field">
<label>Final Bounty Points</label>
<input name="bounty" value="{{claim.bounty}}">
<label>Update Status</label>
<select name="status" class="ui dropdown" id="status">
<option value="claimed">Claimed</option>
<option value="rejected">Rejected</option>
<option value="accepted">Accepted</option>
<option value="disputed">Disputed</option>
<option value="revoked">Revoked</option>
</select>
</div>
<div class="ui container">
<div class="ui two column grid">
<div class="column">
<div class="four wide item">
<div class="image">
<div class="ui statistic">
<div class="value">
{{claim.bounty}}
</div>
<div class="label">
BOUNTY POINTS
</div>
</div>
</div>
<div class="middle aligned content">
<a class="header">{{claim.user}}</a>
<div class="meta">
<span>{{claim.repo}}</span>
</div>
<div class="description">
<p>
Issue : <a href="{{claim.issueUrl}}">{{claim.issueUrl}}</a>
</p>
<p>
Pull : <a href="{{claim.pullUrl}}">{{claim.pullUrl}}</a>
</p>
</div>
<div class="extra">
{{#equal claim.status "claimed"}}
<div class="ui label yellow">{{claim.status}}</div>
{{/equal}}
{{#equal claim.status "accepted"}}
<div class="ui label green">{{claim.status}}</div>
{{/equal}}
{{#equal claim.status "rejected"}}
<div class="ui label red">{{claim.status}}</div>
{{/equal}}
</div>
</div>
<form class="ui form" style="padding: 3em" method="post" action="/claims/{{claim.id}}/update">
<div class="four wide field">
<label>Final Bounty Points</label>
<input name="bounty" value="{{claim.bounty}}">
<label>Update Status</label>
<select name="status" class="ui dropdown" id="status">
<option value="claimed">Claimed</option>
<option value="rejected">Rejected</option>
<option value="accepted">Accepted</option>
<option value="disputed">Disputed</option>
<option value="revoked">Revoked</option>
</select>
</div>

<label>Reason </label>
<textarea name="reason" id="reason"> {{claim.reason}} </textarea>
<br />
<button class="ui button green" type="submit">Submit</button>

<label>Reason </label>
<textarea name="reason" id="reason"> {{claim.reason}} </textarea>
<br/>
<button class="ui button green" type="submit">Submit</button>

</form>
<script>

</form>
<script>
$('select.dropdown').dropdown();

$('select.dropdown').dropdown();
{ {#unless claim.reason } }
$('#reason').hide();
{
{
/unless}}

{{#unless claim.reason}}
$('#reason').hide();
{{/unless}}
$('select').on('change', function (e) {
let status = $('#status option:selected').text();
if (['Rejected', 'Disputed', 'Revoked'].includes(status))
$('#reason').show();
else
$('#reason').html('').hide();

$('select').on('change', function (e){
let status = $('#status option:selected').text();
if( ['Rejected' , 'Disputed' , 'Revoked'].includes(status) )
$('#reason').show();
else
$('#reason').html('').hide();
});

});
</script>
</div>
</div>
<div class="column">
<h2>Conflicts</h2>
{{#if conflicts}}
This following claims collides with the current claim
<div class="ui two column grid">
{{#conflicts}}
<div class="column">
<div class="ui fluid card">
<div class="content">
<div class="header">Claim ID : {{id}}</div>
<div class="meta">Bounty : {{bounty}}</div>
<div class="meta">By : {{user}}</div>
<div class="description">
<div class="ui two column grid">
<div class="column">
<a href="{{issueUrl}}">View Issue</a>
</div>
<div class="column">
<a href="{{pullUrl}}">View PR</a>
</div>
</div>
</div>
</div>

</script>
</div>
</div>
</div>
{{/conflicts}}
</div>
{{else}}
There are no conflicting claims
{{/if}}
</div>
</div>
</div>