Skip to content

Commit

Permalink
feat(manager/scalafmt): implement manager (#28192)
Browse files Browse the repository at this point in the history
Co-authored-by: Sebastian Poxhofer <secustor@users.noreply.github.com>
  • Loading branch information
gaeljw and secustor committed Apr 1, 2024
1 parent 103e54a commit 1119d60
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/modules/manager/api.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down
38 changes: 38 additions & 0 deletions lib/modules/manager/scalafmt/extract.spec.ts
@@ -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();
});
});
});
30 changes: 30 additions & 0 deletions lib/modules/manager/scalafmt/extract.ts
@@ -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],
};
}
12 changes: 12 additions & 0 deletions lib/modules/manager/scalafmt/index.ts
@@ -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'];
3 changes: 3 additions & 0 deletions lib/modules/manager/scalafmt/readme.md
@@ -0,0 +1,3 @@
Extracts scalafmt version from `.scalafmt.conf` file.

New versions of Scalafmt are looked up on Github Releases.

0 comments on commit 1119d60

Please sign in to comment.