0
0
Fork 0
mirror of https://github.com/renovatebot/renovate.git synced 2025-01-11 21:59:05 +00:00

feat(manager/scalafmt): implement manager ()

Co-authored-by: Sebastian Poxhofer <secustor@users.noreply.github.com>
This commit is contained in:
Gaël Jourdan-Weil 2024-04-01 15:02:27 +02:00 committed by GitHub
parent 103e54a21c
commit 1119d609fd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 85 additions and 0 deletions

View file

@ -75,6 +75,7 @@ import * as puppet from './puppet';
import * as pyenv from './pyenv';
import * as rubyVersion from './ruby-version';
import * as sbt from './sbt';
import * as scalafmt from './scalafmt';
import * as setupCfg from './setup-cfg';
import * as swift from './swift';
import * as tekton from './tekton';
@ -169,6 +170,7 @@ api.set('puppet', puppet);
api.set('pyenv', pyenv);
api.set('ruby-version', rubyVersion);
api.set('sbt', sbt);
api.set('scalafmt', scalafmt);
api.set('setup-cfg', setupCfg);
api.set('swift', swift);
api.set('tekton', tekton);

View file

@ -0,0 +1,38 @@
import { codeBlock } from 'common-tags';
import { extractPackageFile } from './extract';
describe('modules/manager/scalafmt/extract', () => {
describe('extractPackageFile()', () => {
it('extracts version correctly', () => {
const scalafmtConf = codeBlock`
version = 3.8.0
`;
const packages = extractPackageFile(scalafmtConf);
expect(packages).toMatchObject({
deps: [
{
datasource: 'github-releases',
packageName: 'scalameta/scalafmt',
depName: 'scalafmt',
currentValue: '3.8.0',
versioning: 'semver',
extractVersion: '^v(?<version>\\S+)',
},
],
});
});
it('ignore file if no version specified', () => {
const scalafmtConf = codeBlock`
maxColumn = 80
`;
const packages = extractPackageFile(scalafmtConf);
expect(packages).toBeNull();
});
it('should return empty packagefiles is no content is provided', () => {
const packages = extractPackageFile('');
expect(packages).toBeNull();
});
});
});

View file

@ -0,0 +1,30 @@
import { regEx } from '../../../util/regex';
import { GithubReleasesDatasource } from '../../datasource/github-releases';
import * as semverVersioning from '../../versioning/semver';
import type { PackageDependency, PackageFileContent } from '../types';
const scalafmtVersionRegex = regEx(
'version *= *(?<version>\\d+\\.\\d+\\.\\d+)',
);
export function extractPackageFile(content: string): PackageFileContent | null {
const regexResult = scalafmtVersionRegex.exec(content);
const scalafmtVersion = regexResult?.groups?.version;
if (!scalafmtVersion) {
return null;
}
const scalafmtDependency: PackageDependency = {
datasource: GithubReleasesDatasource.id,
depName: 'scalafmt',
packageName: 'scalameta/scalafmt',
versioning: semverVersioning.id,
currentValue: scalafmtVersion,
extractVersion: '^v(?<version>\\S+)',
};
return {
deps: [scalafmtDependency],
};
}

View file

@ -0,0 +1,12 @@
import type { Category } from '../../../constants';
import { GithubReleasesDatasource } from '../../datasource/github-releases';
export { extractPackageFile } from './extract';
export const supportedDatasources = [GithubReleasesDatasource.id];
export const defaultConfig = {
fileMatch: ['(^|/)\\.scalafmt.conf$'],
};
export const categories: Category[] = ['java'];

View file

@ -0,0 +1,3 @@
Extracts scalafmt version from `.scalafmt.conf` file.
New versions of Scalafmt are looked up on Github Releases.