Skip to content

Commit

Permalink
Merge pull request #635 from EladHeller/develop
Browse files Browse the repository at this point in the history
dependabot updates.
  • Loading branch information
EladHeller authored Jan 2, 2025
2 parents 8926720 + b907f3f commit 5a14c7f
Show file tree
Hide file tree
Showing 8 changed files with 604 additions and 759 deletions.
7 changes: 4 additions & 3 deletions bot/kineret/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ export async function updateLevel(
const { date, level } = levelData;
const articleName = `${baseArticleName}/נתונים`;

const content = await api.getArticleContent(articleName);
if (!content) {
const contentResult = await api.articleContent(articleName);
if (!contentResult) {
throw new Error('Failed to get article content');
}
const { content, revid } = contentResult;
const template = findTemplate(content, templateName, articleName);
const oldTemplate = template;
const templateData = getTemplateKeyValueData(template);
Expand Down Expand Up @@ -104,7 +105,7 @@ export async function updateLevel(
}, templateName, true);
const newContent = content.replace(oldTemplate, newTemplateText);

await api.updateArticle(articleName, 'עדכון מפלס', newContent);
await api.edit(articleName, 'עדכון מפלס', newContent, revid);

await api.purge([baseArticleName]);
}
6 changes: 3 additions & 3 deletions bot/maintenance/copyrightViolation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ function textFromMatch(
}

async function getLastRun(api: ReturnType<typeof NewWikiApi>): Promise<string> {
const lastRunFromWiki = await api.getArticleContent(LAST_RUN_PAGE);
if (lastRunFromWiki) {
return lastRunFromWiki;
const lastRunResult = await api.articleContent(LAST_RUN_PAGE);
if (lastRunResult) {
return lastRunResult.content;
}
const hours = isAfterShabathOrHolliday() ? 36 : 12;

Expand Down
5 changes: 3 additions & 2 deletions bot/scripts/oneTime/renameParlementMembersCategories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ export default async function renameParlementMembersCategories(api: IWikiApi) {
const isMale = !old.includes('חברות כנסת');

try {
const content = await api.getArticleContent(old);
if (!content) {
const contentResult = await api.articleContent(old);
if (!contentResult) {
throw new Error(`No content for page ${old}`);
}
const { content } = contentResult;
if (!content.includes('#הפניה [[:קטגוריה')) {
throw new Error(`No reference for page ${oldCategory}`);
}
Expand Down
7 changes: 4 additions & 3 deletions bot/swordsOfIron/casualties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ export default async function casualtiesBot() {
}
}

const content = await api.getArticleContent(templateName);
if (!content) {
const contentResult = await api.articleContent(templateName);
if (!contentResult) {
throw new Error('Failed to get article content');
}
const { content, revid } = contentResult;
const rows = content.split('\n').filter((row) => row.trim().startsWith('|'));
let newContent = replaceData(content, rows, 'חיילים', casualties.deathsAll);
newContent = replaceData(newContent, rows, 'חיילים בעזה', casualties.deathsInsideGaza);
Expand All @@ -85,7 +86,7 @@ export default async function casualtiesBot() {
console.log('No changes');
return;
}
await api.updateArticle(templateName, newContent, 'בוט: עדכון נתוני אבדות');
await api.edit(templateName, newContent, 'בוט: עדכון נתוני אבדות', revid);
}

export const main = shabathProtectorDecorator(casualtiesBot);
15 changes: 0 additions & 15 deletions bot/wiki/NewWikiApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ export interface IWikiApi {
create(
articleTitle: string, summary: string, content: string
): Promise<any>;
/**
* @deprecated Use articleContent api instead
*/
getArticleContent(title: string): Promise<string | undefined>;
articleContent(title: string): Promise<{content: string, revid: number} | null>;
externalUrl(link: string, protocol?: string, namespace?: string): AsyncGenerator<WikiPage[], void, void>;
info(titles: string[]): Promise<Partial<WikiPage>[]>;
Expand Down Expand Up @@ -157,16 +153,6 @@ export default function NewWikiApi(baseWikiApi = BaseWikiApi(defaultConfig)): IW
return request('?action=edit&format=json&assert=bot&bot=true', 'post', objectToFormData(data));
}

async function getArticleContent(title: string): Promise<string | undefined> {
const path = `?action=query&format=json&rvprop=content&rvslots=*&prop=revisions&titles=${
encodeURIComponent(title)
}`;
const result = await request(path);
const wikiPages:Record<string, Partial<WikiPage>> = result.query.pages;

return Object.values(wikiPages)[0]?.revisions?.[0].slots.main['*'];
}

async function articleContent(title: string): Promise<{content: string, revid: number} | null> {
const props = encodeURIComponent('content|ids');
const path = `?action=query&format=json&rvprop=${props}&rvslots=*&prop=revisions&titles=${
Expand Down Expand Up @@ -400,7 +386,6 @@ export default function NewWikiApi(baseWikiApi = BaseWikiApi(defaultConfig)): IW
recursiveSubCategories,
backlinksTo,
updateArticle,
getArticleContent,
articleContent,
externalUrl,
categroyTitles,
Expand Down
Loading

0 comments on commit 5a14c7f

Please sign in to comment.