Skip to content
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

Clean claim inputs #391

Open
wants to merge 2 commits 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
65 changes: 65 additions & 0 deletions fixStrangeUrls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const config = require('./config')
const secrets = config.secrets
const Sequelize = require('sequelize')
const db = require('./utils/db')
const fs = require('fs')

function generateGenericUrl(url) {
const extractSingleUrl = url.trim().split(' ')[0].split('#')[0]
const genericUrl = new URL(extractSingleUrl).pathname.replace(/\/+$/, '')
return `https://github.com${genericUrl}`
}

async function worker() {
// these two claims are done twice, with a space, so no other option than to delete it
const firstConflict = await db.Database.query(
`DELETE FROM "claims" WHERE "pullUrl" = ' https://github.com/coding-blocks/gondor/pull/61'`
)

const secondConflict = await db.Database.query(
`DELETE FROM "claims" WHERE "pullUrl" = 'https://github.com/coding-blocks/boss/pull/308#issuecomment-633161908'`
)

const thirdConflict = await db.Database.query(
`UPDATE "claims" SET "issueUrl"='https://github.com/coding-blocks/gondor/pull/22' WHERE "pullUrl" = 'https://github.com/coding-blocks/gondor/pull/22'`
)

const fourthConflict = await db.Database.query(
`UPDATE "claims" SET "issueUrl"='https://github.com/coding-blocks/make-a-pr/pull/717' WHERE "pullUrl" = 'https://github.com/coding-blocks/make-a-pr/pull/717'`
)

// `DELETE FROM "claims" WHERE "pullUrl" = 'https://github.com/coding-blocks/boss/pull/308#issuecomment-633161908'`
const response = await db.Database.query(
`SELECT "issueUrl", "pullUrl", "id" FROM "claims" `
)

const rows = response[0]
console.log(rows)
for (let i = 0; i < rows.length; i += 1) {
try {
let pullUrl = rows[i].pullUrl
let issueUrl = rows[i].issueUrl
pullUrl = generateGenericUrl(pullUrl)
issueUrl = generateGenericUrl(issueUrl)
console.log(`Processing id #${rows[i].id} ...`)
const dbResponse = await db.Claim.update(
{
issueUrl: issueUrl,
pullUrl: pullUrl
},
{
where: {
id: rows[i].id
},
returning: true
}
)
} catch (error) {
fs.appendFileSync('errors.txt', `${error.message} in ${rows[i].id}\n`)
console.log(`>>>>>>>${error.message}`)
console.log(error)
}
}
}

worker()
4 changes: 2 additions & 2 deletions routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ route.post('/claims/add', auth.ensureLoggedInGithub, (req, res) => {

du.createClaim(
req.user.usergithub.username,
req.body.issue_url,
req.body.pull_url,
du.generateGenericUrl(req.body.issue_url),
du.generateGenericUrl(req.body.pull_url),
req.body.bounty,
config.CLAIM_STATUS.CLAIMED
)
Expand Down
4 changes: 2 additions & 2 deletions routes/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ route.post('/claims/add', auth.ensureLoggedInGithub, (req, res) => {

du.createClaim(
req.user.usergithub.username, // github username already valid
req.body.issue_url,
req.body.pull_url,
du.generateGenericUrl(req.body.issue_url),
du.generateGenericUrl(req.body.pull_url),
req.body.bounty,
config.CLAIM_STATUS.CLAIMED
)
Expand Down
7 changes: 7 additions & 0 deletions utils/datautils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ const db = require('./db')
const fs = require('fs')
const consts = require('./consts')

function generateGenericUrl(url) {
const extractSingleUrl = url.trim().split(' ')[0].split('#')[0]
const genericUrl = new URL(extractSingleUrl).pathname.replace(/\/+$/, '')
return `https://github.com${genericUrl}`
}

function getContestPeriod(year) {
if (year)
return {
Expand Down Expand Up @@ -180,5 +186,6 @@ module.exports = {
getLoggedInUserStats,
getClaimById,
updateClaim,
generateGenericUrl,
getCounts
}