Skip to content

Added Conflicted Claims Feature #357

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

Merged
Merged
Show file tree
Hide file tree
Changes from 5 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
37 changes: 26 additions & 11 deletions routes/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -227,17 +229,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.")
Expand All @@ -261,6 +252,30 @@ 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 => {
console.log(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 => {
Expand Down
24 changes: 23 additions & 1 deletion utils/datautils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -59,6 +60,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',
Expand Down Expand Up @@ -180,5 +201,6 @@ module.exports = {
getLoggedInUserStats,
getClaimById,
updateClaim,
getCounts
getCounts,
getConflictedClaims
}
18 changes: 18 additions & 0 deletions utils/urlUtils.js
Original file line number Diff line number Diff line change
@@ -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;
}
Comment on lines +2 to +16
Copy link
Contributor

@prabalsingh24 prabalsingh24 Jun 9, 2020

Choose a reason for hiding this comment

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

upperCase lowerCase in the url is not handled properly here.

if github.com is in upperCase then this would fail. (Although you can't really enter https://GITHUB.com/coding-blocks/boss/issues/29923232. this throws duplicate issue error (a bug maybe?). But still it's better to make sure it doesn't break in the future)

Also project, type should be converted to lowerCase.

https://github.com/coding-blocks/BOSS/issues/29923232
https://github.com/coding-blocks/boss/issues/29923232 This fails when these two are the issueUrl. Op.like is case-sensitive I guess

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@prabalsingh24 'GITHUB.com' and 'github.com' should be fixed at add claim level. thanks for pointing the project, and type. yes, they should be converted to lower case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@prabalsingh24 @hereisnaman I think we just need to convert both issue URL and pull URL to lowercase before adding. Everything will work fine, no need to do any change anywhere else. just convert url to lowercase on adding.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah that would work but if there is already a pull url with uppercase, then it might fail in that case. I know chances of that happening is pretty low. But better to be on the safer side and fix it from the both side?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we will add convert code to add claims and also write a migration to convert existing ones.


module.exports = { getUrlDetails }
125 changes: 86 additions & 39 deletions views/pages/claims/id.hbs
Original file line number Diff line number Diff line change
@@ -1,42 +1,4 @@
<div class="row">
<div class="col-md-5">
<form method="post" action="/claims/{{claim.id}}/update">
<div class="card">
<div class="card-body">
<div class="form-group row">
<div class="col-sm-12">
<input name="user" type="number" class="form-control" id="bounty" type="number"
value="{{claim.bounty}}">
<small id="bountyHelper" class="form-text text-muted">Final Bounty to award to user</small>
</div>
</div>
<div class="form-group row">
<div class="col-sm-12">
<select name="status" id="updateStatus" class="custom-select form-control">
<option value="claimed" selected>Claimed</option>
<option value="rejected">Rejected</option>
<option value="accepted">Accepted</option>
<option value="disputed">Disputed</option>
<option value="revoked">Revoked</option>
</select>
<small id="updateStatusHelper" class="form-text text-muted">Update status of claim</small>
</div>
</div>

<div class="form-group row">
<div class="col-sm-12">
<textarea name="reason" class="form-control" id="reason" rows="3"></textarea>
<small id="reason" class="form-text text-muted">Update Reason</small>
</div>
</div>
</div>
</div>
<br />
<div class="card-footer text-center">
<button type="submit" class="btn btn-primary btn-sm">Update Claim Status</a>
</div>
</form>
</div>
<div class="col-md-7 ">
<div class="card">
<div class="card-body">
Expand Down Expand Up @@ -81,13 +43,98 @@
<br />

<span class="text-muted">Pull Request: <small><a
href="{{claim.issueUrl}}">{{claim.issueUrl}}</a></small></span>
href="{{claim.pullUrl}}">{{claim.pullUrl}}</a></small></span>
<br />
</p>
</div>
</div>
</div>
</div>
{{#if hasConflict}}
<h3 style="margin-top: 1em;">Conflicted claims</h3>
{{#each conflictedClaims as |conflictedClaim|}}
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-md-4">
<div class="text-center">
<h1>
<span>{{conflictedClaim.bounty}}</span>
</h1>
<small>bounty points</small>
<hr />
<button class="btn btn-primary btn-sm" onclick="OpenConflict({{conflictedClaim.id}})">View conflict</button>
<script>
function OpenConflict(conflictId) {
window.location.href = conflictId
}
</script>
</div>
</div>
<div class="col-md-8">
<a href="/claims/view?username={{conflictedClaim.user}}&status={{status}}">
<h5 class="card-title">{{conflictedClaim.user}}</h5>
</a>
<p class="card-text">
<small class="text-muted">Project : <a
href="https://www.github.com/coding-blocks/">{{conflictedClaim.repo}}</a></small>
<br />
</p>
<p class="card-text">
<span class="text-muted">Issue: <small><a
href="{{conflictedClaim.issueUrl}}">{{conflictedClaim.issueUrl}}</a></small></span>
<br />

<span class="text-muted">Pull Request: <small><a
href="{{conflictedClaim.pullUrl}}">{{conflictedClaim.pullUrl}}</a></small></span>
<br />
</p>
</div>
</div>
</div>
</div>
{{/each}}
{{else}}
<h3 style="margin-top: 1em;">No Conflicted claims</h3>
{{/if}}
</div>
<div class="col-md-5">
<form method="post" action="/claims/{{claim.id}}/update">
<div class="card">
<div class="card-body">
<div class="form-group row">
<div class="col-sm-12">
<input name="user" type="number" class="form-control" id="bounty" type="number"
value="{{claim.bounty}}">
<small id="bountyHelper" class="form-text text-muted">Final Bounty to award to user</small>
</div>
</div>
<div class="form-group row">
<div class="col-sm-12">
<select name="status" id="updateStatus" class="custom-select form-control">
<option value="claimed" selected>Claimed</option>
<option value="rejected">Rejected</option>
<option value="accepted">Accepted</option>
<option value="disputed">Disputed</option>
<option value="revoked">Revoked</option>
</select>
<small id="updateStatusHelper" class="form-text text-muted">Update status of claim</small>
</div>
</div>

<div class="form-group row">
<div class="col-sm-12">
<textarea name="reason" class="form-control" id="reason" rows="3"></textarea>
<small id="reason" class="form-text text-muted">Update Reason</small>
</div>
</div>
</div>
</div>
<br />
<div class="card-footer text-center">
<button type="submit" class="btn btn-primary btn-sm">Update Claim Status</a>
</div>
</form>
</div>
</div>
{{!-- <div class="four wide item">
Expand Down
2 changes: 1 addition & 1 deletion views/pages/claims/view.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<br />

<span class="text-muted">Pull Request: <small><a
href="{{claim.issueUrl}}">{{claim.issueUrl}}</a></small></span>
href="{{claim.pullUrl}}">{{claim.pullUrl}}</a></small></span>
<br />
</p>
</div>
Expand Down