mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-01 12:26:19 -05:00
Add a Repos module that mirrors git repositories (#783)
Repos keeps local mirrors of git repositories, cloned over https and kept up to date on a schedule. - A Repo is a Collection (kind='repo') plus a `repository` row. The new `git` downloader clones it, then updates it (weekly by default, or Never: the clone is kept as it is and only updated on request). - Repos are saved in `repos/<tag>/<name>` (the Repos Directory, ignored by default) or a directory the user chooses. An existing clone can be imported where it is. repos.yaml is the source of truth. - A GitHub-like page shows each repo's README, files, and history, with a ZIP download. READMEs are searchable under the global search's Other tab. - git is hardened against hostile repos and configs: https only, pinned addresses with no private addresses (for the repo and its submodules), sanitized configs, no hooks or links, and only clones WROLPi made or imported are updated. - Tagging a Repo moves its clone as one directory. Repo changes wait for repos.yaml to be imported at startup. - The file mover groups unindexed files with no primary file as one FileGroup, and never replaces a file at the destination. A failed tag move restores the Collection's tag. A Collection's directory cannot leave the media directory. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
1ded249fc7
commit
93d878952c
60 changed files with 7405 additions and 92 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import React from 'react';
|
||||
import {act, render, screen} from '../test-utils';
|
||||
import {OtherSearchView} from './Search';
|
||||
import {searchChannels} from '../api';
|
||||
import {searchChannels, searchRepos} from '../api';
|
||||
|
||||
// What the search page's Other tab shows for each state of useSearchChannels. "No Channels"
|
||||
// must only appear once the server has confirmed there are none.
|
||||
|
|
@ -9,11 +9,16 @@ import {searchChannels} from '../api';
|
|||
jest.mock('../api', () => ({
|
||||
...jest.requireActual('../api'),
|
||||
searchChannels: jest.fn(),
|
||||
searchRepos: jest.fn(),
|
||||
}));
|
||||
|
||||
const NO_CHANNELS = /No Channels/;
|
||||
|
||||
beforeEach(() => searchChannels.mockReset());
|
||||
beforeEach(() => {
|
||||
searchChannels.mockReset();
|
||||
searchRepos.mockReset();
|
||||
searchRepos.mockResolvedValue({repos: [], total: 0});
|
||||
});
|
||||
|
||||
test('pending: shows a loader, not "No Channels"', () => {
|
||||
searchChannels.mockReturnValue(new Promise(() => {
|
||||
|
|
@ -54,3 +59,61 @@ test('loaded: lists the channels', async () => {
|
|||
expect(screen.getByText('Cooking')).toBeInTheDocument();
|
||||
expect(screen.queryByText(NO_CHANNELS)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
describe('Repos', () => {
|
||||
test('pending: the Repos section loads while Channels are shown', async () => {
|
||||
searchChannels.mockResolvedValue({channels: []});
|
||||
searchRepos.mockReturnValue(new Promise(() => {
|
||||
}));
|
||||
const {container} = render(<OtherSearchView loading={false}/>);
|
||||
await act(async () => {
|
||||
});
|
||||
expect(screen.getByText(NO_CHANNELS)).toBeInTheDocument();
|
||||
expect(container.querySelector('.wrolpi-loading')).toBeInTheDocument();
|
||||
expect(screen.queryByText('No Repos')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('empty: shows "No Repos"', async () => {
|
||||
searchChannels.mockResolvedValue({channels: []});
|
||||
render(<OtherSearchView loading={false}/>);
|
||||
await act(async () => {
|
||||
});
|
||||
expect(screen.getByText('No Repos')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('failed: shows an error only in the Repos section', async () => {
|
||||
searchChannels.mockResolvedValue({channels: [{id: 1, name: 'Cooking'}]});
|
||||
searchRepos.mockRejectedValue(new Error('boom'));
|
||||
const spy = jest.spyOn(console, 'error').mockImplementation(() => {
|
||||
});
|
||||
try {
|
||||
render(<OtherSearchView loading={false}/>);
|
||||
await act(async () => {
|
||||
});
|
||||
expect(screen.getByText('Cooking')).toBeInTheDocument();
|
||||
expect(screen.getByText(/Could not fetch the repos/)).toBeInTheDocument();
|
||||
} finally {
|
||||
spy.mockRestore();
|
||||
}
|
||||
});
|
||||
|
||||
test('loaded: lists repos by the search, with their README headline', async () => {
|
||||
searchChannels.mockResolvedValue({channels: []});
|
||||
searchRepos.mockResolvedValue({
|
||||
total: 1, repos: [{
|
||||
id: 7, name: 'kiwix-tools', tag_name: null,
|
||||
// The server escapes the README; only the highlight is markup.
|
||||
readme_headline: 'Serve <b>Zim</b> files <script>',
|
||||
}],
|
||||
});
|
||||
const searchParams = new URLSearchParams('q=zim&tag=Software');
|
||||
const {container} = render(<OtherSearchView loading={false}/>, {query: {searchParams}});
|
||||
await act(async () => {
|
||||
});
|
||||
expect(searchRepos).toHaveBeenCalledWith('zim', ['Software']);
|
||||
expect(screen.getByText('kiwix-tools').closest('a')).toHaveAttribute('href', '/repos/7');
|
||||
expect(container.querySelector('u').textContent).toBe('Zim');
|
||||
expect(container.querySelector('script')).toBeNull();
|
||||
expect(screen.getByText(/files <script>/)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue