Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(manager/scalafmt): implement manager (#28192)
Co-authored-by: Sebastian Poxhofer <secustor@users.noreply.github.com>
- Loading branch information
Showing
5 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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], | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Extracts scalafmt version from `.scalafmt.conf` file. | ||
|
||
New versions of Scalafmt are looked up on Github Releases. |