Skip to content

Commit 1236509

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

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

fixStrangeUrls.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
const thirdConflict = await db.Database.query(
24+
`UPDATE "claims" SET "issueUrl"='https://github.com/coding-blocks/gondor/pull/22' WHERE "pullUrl" = 'https://github.com/coding-blocks/gondor/pull/22'`
25+
)
26+
27+
const fourthConflict = await db.Database.query(
28+
`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'`
29+
)
30+
31+
// `DELETE FROM "claims" WHERE "pullUrl" = 'https://github.com/coding-blocks/boss/pull/308#issuecomment-633161908'`
32+
const response = await db.Database.query(
33+
`SELECT "issueUrl", "pullUrl", "id" FROM "claims" `
34+
)
35+
36+
const rows = response[0]
37+
console.log(rows)
38+
for (let i = 0; i < rows.length; i += 1) {
39+
try {
40+
let pullUrl = rows[i].pullUrl
41+
let issueUrl = rows[i].issueUrl
42+
pullUrl = generateGenericUrl(pullUrl)
43+
issueUrl = generateGenericUrl(issueUrl)
44+
console.log(`Processing id #${rows[i].id} ...`)
45+
const dbResponse = await db.Claim.update(
46+
{
47+
issueUrl: issueUrl,
48+
pullUrl: pullUrl
49+
},
50+
{
51+
where: {
52+
id: rows[i].id
53+
},
54+
returning: true
55+
}
56+
)
57+
} catch (error) {
58+
fs.appendFileSync('errors.txt', `${error.message} in ${rows[i].id}\n`)
59+
console.log(`>>>>>>>${error.message}`)
60+
console.log(error)
61+
}
62+
}
63+
}
64+
65+
worker()

0 commit comments

Comments
 (0)