-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(scm): defined the publicly browsable url when hosted on github
as defined by https://maven.apache.org/pom.html#SCM for #9
- Loading branch information
Showing
13 changed files
with
136 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
import {promises as fs} from 'node:fs'; | ||
import {XMLBuilder, XMLParser} from 'fast-xml-parser'; | ||
import {XMLParser} from 'fast-xml-parser'; | ||
|
||
import {write} from './xml/index.js'; | ||
import {getPathTo} from './file.js'; | ||
import defineScmDetails from './scm.js'; | ||
|
||
export default async function ({projectRoot}) { | ||
export default async function ({projectRoot, vcs}) { | ||
const pathToPom = getPathTo(projectRoot); | ||
const parser = new XMLParser(); | ||
const builder = new XMLBuilder({format: true}); | ||
const existingPomContents = parser.parse(await fs.readFile(pathToPom, 'utf-8')); | ||
existingPomContents.project.scm = {tag: 'HEAD'}; | ||
await fs.writeFile(pathToPom, builder.build(existingPomContents)); | ||
|
||
existingPomContents.project.scm = defineScmDetails(vcs); | ||
|
||
await write({path: pathToPom, contents: existingPomContents}); | ||
|
||
return {}; | ||
} |
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 |
---|---|---|
@@ -1,13 +1,14 @@ | ||
import {promises as fs} from 'node:fs'; | ||
import {XMLBuilder} from 'fast-xml-parser'; | ||
|
||
import {write} from './xml/index.js'; | ||
import {getPathTo} from './file.js'; | ||
|
||
export default async function ({projectRoot, projectName}) { | ||
const builder = new XMLBuilder({format: true}); | ||
|
||
await fs.writeFile( | ||
getPathTo(projectRoot), | ||
builder.build({project: {modelVersion: '4.0.0', artifactId: projectName}}) | ||
); | ||
await write({ | ||
path: getPathTo(projectRoot), | ||
contents: { | ||
project: { | ||
modelVersion: '4.0.0', | ||
artifactId: projectName | ||
} | ||
} | ||
}); | ||
} |
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,6 @@ | ||
export default function ({host, owner, name}) { | ||
return { | ||
tag: 'HEAD', | ||
...'github' === host && {url: `https://github.com/${owner}/${name}`} | ||
}; | ||
} |
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,21 @@ | ||
import {describe, expect, it} from 'vitest'; | ||
import any from '@travi/any'; | ||
|
||
import defineScmDetails from './scm.js'; | ||
|
||
describe('pom scm details', () => { | ||
it('should define scm details for a project hosted on github.com', () => { | ||
const owner = any.word(); | ||
const name = any.word(); | ||
|
||
expect(defineScmDetails({owner, name, host: 'github'})) | ||
.toEqual({tag: 'HEAD', url: `https://github.com/${owner}/${name}`}); | ||
}); | ||
|
||
it('should only define the tag for a project not hosted on github.com', () => { | ||
const owner = any.word(); | ||
const name = any.word(); | ||
|
||
expect(defineScmDetails({owner, name, host: any.word()})).toEqual({tag: 'HEAD'}); | ||
}); | ||
}); |
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 @@ | ||
export {default as write} from './writer.js'; |
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,8 @@ | ||
import {promises as fs} from 'node:fs'; | ||
import {XMLBuilder} from 'fast-xml-parser'; | ||
|
||
export default async function ({path, contents}) { | ||
const builder = new XMLBuilder({format: true}); | ||
|
||
await fs.writeFile(path, builder.build(contents)); | ||
} |
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 {promises as fs} from 'node:fs'; | ||
import {XMLBuilder} from 'fast-xml-parser'; | ||
|
||
import {afterEach, describe, expect, it, vi} from 'vitest'; | ||
import any from '@travi/any'; | ||
import {when} from 'jest-when'; | ||
|
||
import write from './writer.js'; | ||
|
||
vi.mock('node:fs'); | ||
vi.mock('fast-xml-parser'); | ||
|
||
describe('xml writer', () => { | ||
afterEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
it('should write the provided data to the xml file', async () => { | ||
const pathToFile = any.string(); | ||
const contents = any.simpleObject(); | ||
const build = vi.fn(); | ||
const renderedXml = any.string(); | ||
when(XMLBuilder).calledWith({format: true}).mockReturnValue({build}); | ||
when(build).calledWith(contents).mockReturnValue(renderedXml); | ||
|
||
await write({path: pathToFile, contents}); | ||
|
||
expect(fs.writeFile).toHaveBeenCalledWith(pathToFile, renderedXml); | ||
}); | ||
}); |
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
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 |
---|---|---|
@@ -1,16 +1,24 @@ | ||
import {promises as fs} from 'node:fs'; | ||
import {XMLParser} from 'fast-xml-parser'; | ||
|
||
import {Given, Then} from '@cucumber/cucumber'; | ||
import {XMLParser} from 'fast-xml-parser'; | ||
import {assert} from 'chai'; | ||
import any from '@travi/any'; | ||
|
||
Given('vcs details are not defined in the pom', async function () { | ||
await fs.writeFile(`${this.projectRoot}/pom.xml`, '<project><modelVersion>4.0.0</modelVersion></project>'); | ||
}); | ||
|
||
Given('the repository is hosted on github.com', async function () { | ||
const owner = any.word(); | ||
const repositoryName = any.word(); | ||
this.vcsDetails = {host: 'github', owner, name: repositoryName}; | ||
this.vcsUrl = `https://github.com/${owner}/${repositoryName}`; | ||
}); | ||
|
||
Then('vcs details are defined in the pom', async function () { | ||
const parser = new XMLParser(); | ||
const {project: {scm}} = parser.parse(await fs.readFile(`${this.projectRoot}/pom.xml`, 'utf-8')); | ||
|
||
assert.deepEqual(scm, {tag: 'HEAD'}); | ||
assert.deepEqual(scm, {tag: 'HEAD', url: this.vcsUrl}); | ||
}); |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
Feature: Version Control Details | ||
|
||
Scenario: No Details Defined | ||
Scenario: No Details Defined for a repository hosted on github.com | ||
Given vcs details are not defined in the pom | ||
And the repository is hosted on github.com | ||
When the project is lifted | ||
Then vcs details are defined in the pom |