mirror of
https://github.com/renovatebot/renovate.git
synced 2026-11-01 18:19:51 +00:00
7573fa98f2
* fix(platform/forgejo): replace getJsonUnchecked with validated getJson Migrate all getJsonUnchecked calls in the Forgejo platform module to use getJson with Zod schemas for response validation. Add comprehensive Zod schemas to schema.ts and update test mocks to use proper data formats. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * simplify by using infered types * first pass on reducing duplications * move PrStatus and CommitStatus to schema * remove code handling BranchStatus values now ensured by schema * remove now unreachable code * fix coverage * use forgejo schemas instead gitea for changelog fetching * feat: do not abort repo on unrecognized default merge style * refactor: instead of usages of `?? {}` with a default parameter * tighten required parameters and move contentString generation to schema * refactor: merge both content schemas and use a discriminated union * refactor: move patchJson and postJson to schema validation * Make body field required * make schema more strict * use DeepNullish * simplify catch * revert the gitea Content type change * unify User * log more nicely if accidentally not a file has been referenced * Use fakeSha and LongCommitSha schema --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
90 lines
2.7 KiB
TypeScript
90 lines
2.7 KiB
TypeScript
import { partial } from '~test/util.ts';
|
|
import { CONFIG_GIT_URL_UNAVAILABLE } from '../../../constants/error-messages.ts';
|
|
import type { Repo } from './schema.ts';
|
|
import {
|
|
getMergeMethod,
|
|
getRepoUrl,
|
|
trimTrailingApiPath,
|
|
usableRepo,
|
|
} from './utils.ts';
|
|
|
|
describe('modules/platform/forgejo/utils', () => {
|
|
const mockRepo = partial<Repo>({
|
|
allow_rebase: true,
|
|
clone_url: 'https://forgejo.renovatebot.com/some/repo.git',
|
|
ssh_url: 'git@forgejo.renovatebot.com/some/repo.git',
|
|
default_branch: 'master',
|
|
full_name: 'some/repo',
|
|
permissions: {
|
|
pull: true,
|
|
push: true,
|
|
admin: false,
|
|
},
|
|
has_pull_requests: true,
|
|
});
|
|
|
|
it('trimTrailingApiPath', () => {
|
|
expect(trimTrailingApiPath('https://forgejo.renovatebot.com/api/v1')).toBe(
|
|
'https://forgejo.renovatebot.com/',
|
|
);
|
|
expect(trimTrailingApiPath('https://forgejo.renovatebot.com/api/v1/')).toBe(
|
|
'https://forgejo.renovatebot.com/',
|
|
);
|
|
expect(trimTrailingApiPath('https://forgejo.renovatebot.com/')).toBe(
|
|
'https://forgejo.renovatebot.com/',
|
|
);
|
|
expect(trimTrailingApiPath('https://forgejo.renovatebot.com')).toBe(
|
|
'https://forgejo.renovatebot.com',
|
|
);
|
|
expect(
|
|
trimTrailingApiPath('https://forgejo.renovatebot.com/api/forgejo/api/v1'),
|
|
).toBe('https://forgejo.renovatebot.com/api/forgejo/');
|
|
});
|
|
|
|
describe('getRepoUrl', () => {
|
|
it('should abort when endpoint is not valid', () => {
|
|
expect.assertions(1);
|
|
expect(() => getRepoUrl(mockRepo, 'endpoint', 'abc')).toThrow(
|
|
CONFIG_GIT_URL_UNAVAILABLE,
|
|
);
|
|
});
|
|
});
|
|
|
|
it.each`
|
|
value | expected
|
|
${'auto'} | ${null}
|
|
${undefined} | ${null}
|
|
${'fast-forward'} | ${'rebase'}
|
|
${'merge-commit'} | ${'merge'}
|
|
${'rebase'} | ${'rebase-merge'}
|
|
${'squash'} | ${'squash'}
|
|
`('getMergeMethod("$value") == "$expected"', ({ value, expected }) => {
|
|
expect(getMergeMethod(value)).toBe(expected);
|
|
});
|
|
|
|
describe('usableRepo', () => {
|
|
it('should return true when repo is usable', () => {
|
|
expect(usableRepo(mockRepo)).toBe(true);
|
|
});
|
|
|
|
it('should return false when repo lacks permissions', () => {
|
|
expect(
|
|
usableRepo({
|
|
...mockRepo,
|
|
permissions: { pull: false, push: false, admin: true },
|
|
}),
|
|
).toBe(false);
|
|
expect(
|
|
usableRepo({
|
|
...mockRepo,
|
|
permissions: { pull: true, push: false, admin: true },
|
|
}),
|
|
).toBe(false);
|
|
});
|
|
|
|
it('should return false when repo has disabled pull requests', () => {
|
|
expect(usableRepo({ ...mockRepo, has_pull_requests: false })).toBe(false);
|
|
});
|
|
});
|
|
});
|