Skip to content

Commit

Permalink
gadgets-sync: fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthvp committed Jun 1, 2024
1 parent 02f59f0 commit e0feed7
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions gadgets-sync/gadgets-sync.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {argv, bot, log} from "../botbase";
import {setIntersection} from "../utils";

const header = `
/******************************************************************************/
Expand All @@ -20,12 +19,6 @@ async function getConfig() {
return JSON.parse(content)
}

const editReqCategories = new Set([
'Wikipedia_interface-protected_edit_requests',
'Wikipedia_fully_protected_edit_requests',
'Wikipedia_template-protected_edit_requests',
]);

(async function () {
await bot.getTokensAndSiteInfo()
const allConfigs = await getConfig()
Expand Down Expand Up @@ -62,8 +55,8 @@ const editReqCategories = new Set([
const substitutedHeader = header.replaceAll('$SOURCE', conf.source)

if (remote.data !== local.data.replace(substitutedHeader, '')) {
let talkCategories = (await new bot.Page(talkTitle).categories()).map(e => e.category)
if (setIntersection(talkCategories, editReqCategories).size > 0) {
const pg = await bot.read(talkTitle)
if (!pg.missing && pg.revisions[0].content.includes(`{{sudo|page=${conf.page}|answered=no}}`)) {
log(`[+] Open edit request already exists on ${conf.talkPage}, skipping`)
continue
}
Expand All @@ -77,8 +70,10 @@ const editReqCategories = new Set([
const curRevId = (await new bot.Page(conf.page).history(['ids'], 1))[0].revid;
const comparePagesLink = `https://en.wikipedia.org/wiki/Special:ComparePages?page1=${encodeURIComponent(conf.page)}&rev1=${curRevId}&page2=${encodeURIComponent(syncPage)}&rev2=${saveResult.newrevid}`

await bot.newSection(conf.talkPage, `Sync request {{subst:#time:j F Y}}`,
`{{sudo|page=${conf.page}|answered=no}} Please sync [[${conf.page}]] with [[${syncPage}]] ([${comparePagesLink} diff]). This brings it in sync with the upstream changes at [[${conf.source}]] ([[Special:PageHistory/${conf.source}|hist]]).\n\nThis edit request is raised automatically based on the configuration at [[${CONFIG_PAGE}]]. Thanks, ~~~~`)
const date = new bot.Date().format('D MMMM YYYY')
const isMatchingTalk = new bot.Page(conf.page).toText() === new bot.Title(conf.talkPage).getSubjectPage().toText()
await bot.newSection(conf.talkPage, `Sync request ${date}` + (isMatchingTalk ? '' : ` for ${conf.page}`),
`{{sudo|page=${conf.page}|answered=no}}\nPlease sync [[${conf.page}]] with [[${syncPage}]] ([${comparePagesLink} diff]). This brings it in sync with the upstream changes at [[${conf.source}]] ([[Special:PageHistory/${conf.source}|hist]]).\n\nThis edit request is raised automatically based on the configuration at [[${CONFIG_PAGE}]]. Thanks, ~~~~`)
log(`[S] Created edit request on [[${conf.talkPage}]]`)
}
}
Expand Down

0 comments on commit e0feed7

Please sign in to comment.