Skip to content

Commit c31dbbf

Browse files
Fix old url issues, Ref #390
1 parent 395403d commit c31dbbf

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

fixStrangeUrls.js

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
const config = require('./config')
2+
const secrets = config.secrets
3+
const Sequelize = require('sequelize')
4+
const db = require('./utils/db')
5+
const fs = require('fs')
6+
7+
function generateGenericUrl(url) {
8+
const extractSingleUrl = url.trim().split(' ')[0].split('#')[0]
9+
const genericUrl = new URL(extractSingleUrl).pathname.replace(/\/+$/, '')
10+
return `https://github.com${genericUrl}`
11+
}
12+
13+
async function worker() {
14+
// these two claims are done twice, with a space, so no other option than to delete it
15+
const firstConflict = await db.Database.query(
16+
`DELETE FROM "claims" WHERE "pullUrl" = ' https://github.com/coding-blocks/gondor/pull/61'`
17+
)
18+
19+
const secondConflict = await db.Database.query(
20+
`DELETE FROM "claims" WHERE "pullUrl" = 'https://github.com/coding-blocks/boss/pull/308#issuecomment-633161908'`
21+
)
22+
23+
// `DELETE FROM "claims" WHERE "pullUrl" = 'https://github.com/coding-blocks/boss/pull/308#issuecomment-633161908'`
24+
const response = await db.Database.query(
25+
`SELECT "issueUrl", "pullUrl", "id" FROM "claims" `
26+
)
27+
28+
const rows = response[0]
29+
console.log(rows)
30+
for (let i = 0; i < rows.length; i += 1) {
31+
try {
32+
let pullUrl = rows[i].pullUrl
33+
let issueUrl = rows[i].issueUrl
34+
pullUrl = generateGenericUrl(pullUrl)
35+
issueUrl = generateGenericUrl(issueUrl)
36+
console.log(`Processing id #${rows[i].id} ...`)
37+
const dbResponse = await db.Claim.update(
38+
{
39+
issueUrl: issueUrl,
40+
pullUrl: pullUrl
41+
},
42+
{
43+
where: {
44+
id: rows[i].id
45+
},
46+
returning: true
47+
}
48+
)
49+
} catch (error) {
50+
fs.appendFileSync('errors.txt', `${error.message} in ${rows[i].id}\n`)
51+
console.log(`>>>>>>>${error.message}`)
52+
console.log(error)
53+
}
54+
}
55+
}
56+
57+
worker()

0 commit comments

Comments
 (0)