Files
jobtrackingapp/scripts/gitea-board.js
T
cesnimda c05d6f8906
CI and Deploy / test (pull_request) Failing after 7m16s
CI and Deploy / deploy (pull_request) Has been skipped
Establish Gitea backlog workflow and reconcile Project 1
2026-12-02 18:30:39 +01:00

59 lines
3.2 KiB
JavaScript

async page => {
const options = /*MANIFEST*/null;
const repo = 'https://git.cesnimda.uk/cesnimda/jobtrackingapp';
const board = repo + '/projects/1';
const columns = ['Backlog', 'Ready', 'In Progress', 'Blocked', 'Code Review', 'Testing', 'Ready to Deploy', 'Done'];
const status = [];
await page.setViewportSize({width: 3600, height: 1000});
await page.goto(board);
const titles = await page.locator('.project-column-title-text').allInnerTexts();
if (JSON.stringify(titles) !== JSON.stringify(columns)) throw Error('unexpected board columns');
const position = async id => page.locator('.project-column').filter({
has: page.locator('.issue-card[data-issue="' + id + '"]')
}).locator('.project-column-title-text').allInnerTexts();
for (const row of options.rows) {
if (!Number.isSafeInteger(row.id) || !Number.isSafeInteger(row.number) || !columns.includes(row.column))
throw Error('unexpected manifest row');
const previous = await position(row.id);
if (previous.length > 1) throw Error('unexpected duplicate board card');
if (previous[0] === row.column || !options.apply) {
status.push([row.number, previous[0] || 'missing', row.column]);
continue;
}
if (previous.length && previous[0] !== 'Backlog' && !options.explicit)
throw Error('refused to overwrite an existing non-default stage for #' + row.number);
if (!previous.length) {
await page.goto(repo + '/issues/' + row.number);
const picker = page.locator('[data-update-url*=projects]');
if (!(await picker.innerText()).includes('No project'))
throw Error('refused to replace a project on #' + row.number);
await picker.getByRole('combobox').click();
const response = page.waitForResponse(r => r.url().includes('/issues/projects?') && r.request().method() === 'POST');
await picker.getByText('JobbJakt Development', {exact:true}).click();
if (!(await response).ok()) throw Error('project assignment failed');
await page.goto(board);
}
if ((await position(row.id))[0] !== row.column) {
const card = page.locator('.issue-card[data-issue="' + row.id + '"]');
const target = page.locator('.project-column').nth(titles.indexOf(row.column)).locator('.cards');
await card.scrollIntoViewIfNeeded();
const a = await card.boundingBox(), b = await target.boundingBox();
const x = a.x + 12, y = a.y + a.height / 2;
await page.mouse.move(x,y);
await page.mouse.down();
await page.waitForTimeout(250);
await page.mouse.move(x+20,y+4,{steps:10});
await page.mouse.move(b.x+80,b.y+80,{steps:35});
await page.mouse.move(b.x+82,b.y+84);
await page.waitForTimeout(250);
const saved = page.waitForResponse(r => r.url().startsWith(board + '/') && r.url().endsWith('/move') && r.request().method() === 'POST', {timeout:8000});
await page.mouse.up();
if (!(await saved).ok()) throw Error('card move failed for #' + row.number);
}
await page.reload();
if ((await position(row.id))[0] !== row.column) throw Error('card verification failed for #' + row.number);
status.push([row.number, 'verified', row.column]);
}
return {alreadyOrVerified:status};
}