Skip to content

Conflict Analysis on Claim Review #392

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

Closed
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
20 changes: 11 additions & 9 deletions routes/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,17 @@ 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', auth.adminOnly,async (req, res) => {
try{
const claim = await du.getClaimById(req.params.id)
if (!claim) throw new Error('No claim found')

// get all conflicts
const conflicts = await du.getConflictsReport(claim)
res.render('pages/claims/id', {claim, conflicts})
}catch(e){
res.send('Error fetching claim id = ' + escapeHtml(req.params.id))
}
})

route.post('/claims/add', auth.ensureLoggedInGithub, (req, res) => {
Expand Down
59 changes: 58 additions & 1 deletion utils/datautils.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,62 @@ function delClaim(claimId) {
})
}

async function getConflictsReport(claim){
try{
const issues = await db.Database.query(`
SELECT *
FROM "claims"
WHERE ( "issueUrl"='${claim.issueUrl}' OR
"pullUrl"='${claim.issueUrl}' )
AND "id" != ${claim.id}
`)

const pulls = await db.Database.query(`
SELECT *
FROM "claims"
WHERE ("issueUrl"='${claim.pullUrl}')
AND "id" != ${claim.id}
`)

const both = await db.Database.query(`
SELECT *
FROM "claims"
WHERE (( "issueUrl"='${claim.issueUrl}' AND
"pullUrl"='${claim.pullUrl}' )
OR ( "issueUrl"='${claim.pullUrl}' AND
"pullUrl"='${claim.issueUrl}' ))
AND "id" != ${claim.id}
`)

// if both urls same
const object = {
both: both[0]
}
if(claim.issueUrl === claim.pullUrl){
// if url is of an issue
if(claim.issueUrl.includes("/issues/")){
object.issue = issues[0]
object.pulls = []
}else{
object.issue = []
object.pulls = pulls[0]
}
}
else{
object.issue = issues[0]
object.pulls = pulls[0]
}
return object
}catch(e){
console.log(e.message);
return {
issue: [],
pulls: [],
both: []
}
}
}

function updateClaim(claimId, { status, reason, bounty }) {
const claim = {
action: 'update',
Expand Down Expand Up @@ -180,5 +236,6 @@ module.exports = {
getLoggedInUserStats,
getClaimById,
updateClaim,
getCounts
getCounts,
getConflictsReport
}
Loading