forked from coding-blocks/boss
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix old url issues, Ref coding-blocks#390
- Loading branch information
1 parent
395403d
commit c31dbbf
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
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'` | ||
) | ||
|
||
// `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() |