const Telegraph = require('telegraph-node'); const { JSDOM } = require('jsdom'); const { gitlogPromise } = require('gitlog'); // CONSTANTS const AUTH_TOKEN = process.env.TELEGRAPH_TOKEN; const version = require('../package.json').version; const gitOptions = { repo: '.', branch: 'master', number: 100, fields: ['hash', 'subject', 'committerDate'], }; const pageTemplate = `
\This list is automatically updated when a new commit pushed to the beta repo\
Last updated ${new Date().toLocaleDateString('en-CA')}\ `.trim(); // MAIN function updateChangelog() { preparePage().then((dom) => { updateTelegraph(dom); }); } updateChangelog(); // UTIL async function updateTelegraph(dom) { const api = new Telegraph(); const content = domToNode(dom.window.document.body).children; const result = await api.editPage(AUTH_TOKEN, 'WebZ-Beta-04-01', 'Telegram WebZ Beta Changelog', content, { author_name: 'WebZ team', author_url: 'https://t.me/webztalks', }); // eslint-disable-next-line no-console console.log(result); } async function preparePage() { const dom = new JSDOM(pageTemplate); const commits = await getCommitsSince(version); commits.forEach((commit) => ( dom.window.document.getElementById('list').appendChild(renderCommit(dom, commit)) )); if (!commits?.length) { const li = dom.window.document.createElement('li'); li.innerHTML = `
Nothing changed since ${version}
`; dom.window.document.getElementById('list').appendChild(li); } return dom; } function renderCommit(dom, commit) { const li = dom.window.document.createElement('li'); const subject = commit.subject.replaceAll(/`(.+)`/g, '$1');
li.innerHTML = `${commit.hash.substring(0, 7)} ${subject}