feat(projects): pull Gitea issues onto any board

The import only existed on a repository board and always landed in the first
column. The organization board is exactly where issues from several
repositories belong together, so the button now lives on every board and
asks which repository, which column, and whether closed issues come too.

An issue already on the board is skipped rather than duplicated, so the
button survives being pressed twice — which the tests check against a
stand-in forge, along with the due date and labels carried over.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
nocodeandClaude Opus 5 committed 2026-09-24 14:03:06 +02:00
1 parent 8869c74b7b
commit 1c21f6ff53
4 files changed
+260 -21

No files matched your search

+30 -9
View File
@@ -407,26 +407,40 @@ export function registerProjectRoutes(router) {
{ access: ACCESS_LEVELS.STAFF },
);
/** Turns the open issues of a repository into cards, skipping the ones already there. */
/**
* Pulls issues from Gitea onto the board.
*
* An issue already on the board is skipped rather than duplicated, so the
* button can be pressed again after a sprint without cleaning up after it.
*/
router.post(
'/api/projects/:id/import',
async ({ params, body, actor }) => {
const found = board(params.id);
const repository = String(body.repository ?? found.repository ?? '');
const parts = splitRepository(repository);
if (!parts) throw badRequest('Dépôt attendu au format `organisation/depot`.');
if (!isGiteaConfigured()) throw badRequest('Gitea n’est pas configuré.');
const repository = String(body.repository ?? found.repository ?? '').trim();
const parts = splitRepository(repository);
if (!parts) throw badRequest('Dépôt attendu au format `organisation/depot`.');
const state = body.state === 'all' ? 'all' : 'open';
const columns = listColumns(found.id);
const target = columns.find((column) => !column.is_done) ?? columns[0];
if (!target) throw badRequest('Ce tableau n’a aucune colonne.');
if (columns.length === 0) throw badRequest('Ce tableau n’a aucune colonne.');
// Falls back to the first column that is not the finished one: importing
// straight into « Terminé » is never what anyone means.
const requested = body.columnId ? getColumn(Number.parseInt(body.columnId, 10)) : null;
const target =
requested && requested.board_id === found.id
? requested
: (columns.find((column) => !column.is_done) ?? columns[0]);
const existing = new Set(
listCards(found.id)
.map((card) => card.issue_ref)
.filter(Boolean),
);
const issues = await repos.listIssues(parts.owner, parts.repo, { state: 'open', limit: 50 });
const issues = await repos.listIssues(parts.owner, parts.repo, { state, limit: 100 });
let imported = 0;
for (const issue of issues) {
@@ -440,13 +454,20 @@ export function registerProjectRoutes(router) {
body: issue.body ? String(issue.body).slice(0, 2000) : null,
issueRef: ref,
labels: (issue.labels ?? []).map((label) => label.name),
dueAt: issue.due_date ? String(issue.due_date).slice(0, 10) : null,
createdBy: actor.userId,
});
imported += 1;
}
audit(actor, 'web.project.import', { board: found.id, repository, imported });
return { imported, skipped: issues.length - imported, column: target.name };
audit(actor, 'web.project.import', { board: found.id, repository, state, imported });
return {
imported,
skipped: issues.length - imported,
found: issues.length,
column: target.name,
repository,
};
},
{ access: ACCESS_LEVELS.STAFF },
);