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:
1 parent
8869c74b7b
commit
1c21f6ff53
4 files changed
+260
-21
No files matched your search
@@ -345,18 +345,7 @@ async function renderBoard(host, state, id) {
|
||||
h(
|
||||
'div',
|
||||
{ class: 'row' },
|
||||
board.repository &&
|
||||
button(
|
||||
'Importer les issues',
|
||||
async () => {
|
||||
const result = await api.post(`/api/projects/${board.id}/import`, {});
|
||||
toast(
|
||||
`${result.imported} carte(s) créée(s) dans « ${result.column} », ${result.skipped} déjà présente(s).`,
|
||||
);
|
||||
reload();
|
||||
},
|
||||
{ tone: 'ghost' },
|
||||
),
|
||||
button('Importer depuis Gitea', () => importIssues(board, reload), { tone: 'ghost' }),
|
||||
button('Colonne', () => addColumn(board, reload), { tone: 'ghost' }),
|
||||
level >= LEVELS.OWNER &&
|
||||
button(
|
||||
@@ -389,6 +378,73 @@ async function renderBoard(host, state, id) {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pulls Gitea issues onto the board.
|
||||
*
|
||||
* Offered on every board, not only on a repository one: the organization board
|
||||
* is exactly where issues from several repositories belong together.
|
||||
*/
|
||||
async function importIssues(board, reload) {
|
||||
const { repositories } = await api.get('/api/repositories').catch(() => ({ repositories: [] }));
|
||||
|
||||
const repository =
|
||||
repositories.length > 0
|
||||
? select(
|
||||
repositories.map((entry) => ({ value: entry.fullName, label: entry.fullName })),
|
||||
{ value: board.repository ?? repositories[0]?.fullName },
|
||||
)
|
||||
: input({ value: board.repository ?? '', placeholder: 'FWS/FWS-Arch' });
|
||||
|
||||
const column = select(
|
||||
board.columns.map((entry) => ({ value: String(entry.id), label: entry.name })),
|
||||
{ value: String((board.columns.find((entry) => !entry.isDone) ?? board.columns[0])?.id) },
|
||||
);
|
||||
let closedToo = false;
|
||||
|
||||
const confirmed = await modal(
|
||||
'Importer depuis Gitea',
|
||||
() => ({
|
||||
node: h(
|
||||
'div',
|
||||
{ class: 'stack' },
|
||||
repositories.length === 0 &&
|
||||
notice(
|
||||
'La liste des dépôts est indisponible — saisis le dépôt à la main, au format `organisation/depot`.',
|
||||
'warning',
|
||||
),
|
||||
field('Dépôt', repository),
|
||||
field('Colonne d’arrivée', column),
|
||||
toggle(false, (checked) => (closedToo = checked), 'Inclure aussi les issues fermées'),
|
||||
h('p', {
|
||||
class: 'muted',
|
||||
text: 'Une issue déjà présente sur le tableau est ignorée : tu peux relancer l’import sans créer de doublon.',
|
||||
}),
|
||||
),
|
||||
submit: () => repository.value.trim() !== '',
|
||||
}),
|
||||
{ confirmLabel: 'Importer', tone: 'primary' },
|
||||
);
|
||||
if (!confirmed) return;
|
||||
|
||||
try {
|
||||
const result = await api.post(`/api/projects/${board.id}/import`, {
|
||||
repository: repository.value.trim(),
|
||||
columnId: Number(column.value),
|
||||
state: closedToo ? 'all' : 'open',
|
||||
});
|
||||
|
||||
toast(
|
||||
result.imported === 0
|
||||
? `Rien à importer : les ${result.found} issue(s) de ${result.repository} sont déjà sur le tableau.`
|
||||
: `${result.imported} carte(s) créée(s) dans « ${result.column} », ${result.skipped} déjà présente(s).`,
|
||||
result.imported === 0 ? 'info' : 'success',
|
||||
);
|
||||
reload();
|
||||
} catch (error) {
|
||||
toast(error.message, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
async function addColumn(board, reload) {
|
||||
const name = input({ placeholder: 'Nom de la colonne' });
|
||||
const wipLimit = input({ type: 'number', value: 0, min: 0 });
|
||||
|
||||
Reference in new issue
Block a user