Skip to content

Commit 9008469

Browse files
committed
feat(action): Separate origin and prefix repositories
1 parent 3468fa3 commit 9008469

11 files changed

+2060
-321
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ Parameter | Description | Required | Example
7676
---------|----------| ---------|----------
7777
PERSONAL_ACCESS_TOKEN | The PHP-Prefixer PAT/Personal Access Token. The token must be configured in the PHP-Prefixer account. | Yes | `789\|123456789...`
7878
PROJECT_ID | The project ID to process the source code. The project must be configured in your account in the PHP-Prefixer account. | Yes | `5432`
79-
TOKEN | The GitHub PAT/Personal Access Token to access private repositories. It is only required if the project, the library or the dependencies are private. | No | `ghp_F4fZ9Cq7QF...`
79+
TOKEN | The GitHub PAT/Personal Access Token to access private repositories. It is only required if the project, the library or the dependencies are private. | Yes | `ghp_F4fZ9Cq7QF...`
80+
SCHEMA | The PHP-Prefixer JSON configuration to be applied to the project. By default, the prefixer uses the configuration present in composer.json. If there is no extra configuration or the extra configuration must be replaced, this parameter overrides the `composer.json` extra configuration to define the PHP-Prefixer schema. | No | `{"project-name": "Prefixed Project","namespaces-prefix": "PPP","global-scope-prefix": "PPP_"}`
8081

8182
The Action integrates the [GitHub Action Checkout - actions/checkout](https://github.com/actions/checkout). The following parameters are also available:
8283

__tests__/Mock-Composer/composer.json

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
{
2-
"require": {
3-
"symfony/console": "^5.3"
2+
"require": {},
3+
"extra": {
4+
"php-prefixer": {
5+
"project-name": "Prefixed Project",
6+
"namespaces-prefix": "PPP",
7+
"global-scope-prefix": "PPP_"
48
}
5-
}
9+
}
10+
}

__tests__/git-helper.test.ts

+30-43
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ async function createTmpRepo(): Promise<IGitHelper> {
1818
await gitHelper.init()
1919

2020
await getExecOutput(`touch ${srcTmpPath}/composer.json`)
21-
await gitHelper.commitAll()
21+
await gitHelper.addAllAndCommit()
2222

2323
return gitHelper
2424
}
@@ -37,8 +37,8 @@ let gitHelper: IGitHelper
3737
beforeEach(async () => {
3838
sourceSettings = {
3939
repositoryPath: '',
40-
repositoryOwner: '',
41-
repositoryName: '',
40+
repositoryOwner: 'lorem',
41+
repositoryName: 'ipsum',
4242
ref: '',
4343
commit: '',
4444
clean: true,
@@ -93,12 +93,12 @@ test('checkout new branch', async () => {
9393
let branch = await tmpIGitHelper.currentBranch()
9494
expect(branch).toBe('master')
9595

96-
await tmpIGitHelper.checkoutToBranch(false, '', 'prefixed-1.0.0')
96+
await tmpIGitHelper.checkoutToBranch('', 'prefixed-1.0.0')
9797
branch = await tmpIGitHelper.currentBranch()
9898
expect(branch).toBe('prefixed-1.0.0')
9999

100100
await tmpIGitHelper.checkout('master', '')
101-
await tmpIGitHelper.checkoutToBranch(false, '', 'prefixed-1.0.0')
101+
await tmpIGitHelper.checkoutToBranch('', 'prefixed-1.0.0')
102102

103103
branch = await tmpIGitHelper.currentBranch()
104104
expect(branch).toBe('prefixed-1.0.0')
@@ -116,25 +116,6 @@ test('current revision', async () => {
116116
expect(result.length).toBe(40)
117117
})
118118

119-
test('current tag', async () => {
120-
const tmpIGitHelper = await createTmpRepo()
121-
122-
await tmpIGitHelper.tag('1.0.0')
123-
const result = await tmpIGitHelper.currentTag()
124-
expect(result).toBe('1.0.0')
125-
126-
destroyTmpRepo()
127-
})
128-
129-
test('current tag error', async () => {
130-
const tmpIGitHelper = await createTmpRepo()
131-
132-
const result = await tmpIGitHelper.currentTag()
133-
expect(result).toBeUndefined()
134-
135-
destroyTmpRepo()
136-
})
137-
138119
test('last matching tag', async () => {
139120
const tmpIGitHelper = await createTmpRepo()
140121

@@ -160,7 +141,7 @@ test('push', async () => {
160141
const gitHelper = await createGitHelper(settings)
161142
await gitHelper.init()
162143
await getExecOutput(`touch ${srcTmpPath}/composer.json`)
163-
await gitHelper.commitAll()
144+
await gitHelper.addAllAndCommit()
164145
await gitHelper.tag('1.2.3')
165146

166147
const upstreamTmpPath = await makeTempPath()
@@ -173,7 +154,7 @@ test('push', async () => {
173154
const targetIGitHelper = await createGitHelper(targetSettings)
174155
const licenseFile = `${targetTmpPath}/license.txt`
175156
await getExecOutput(`touch ${licenseFile}`)
176-
await targetIGitHelper.commitAll()
157+
await targetIGitHelper.addAllAndCommit()
177158
await targetIGitHelper.tag('1.2.4')
178159
await targetIGitHelper.push('origin', 'master')
179160

@@ -231,27 +212,33 @@ test('has changes', async () => {
231212
await fs.promises.rm(srcTmpPath, {recursive: true})
232213
})
233214

234-
test('remote add', async () => {
215+
test('remote add url', async () => {
235216
const tmpIGitHelper = await createTmpRepo()
236217

237-
await tmpIGitHelper.remoteAdd(false, 'prefixed-origin-1')
238-
const result1 = await tmpIGitHelper.remoteExists('prefixed-origin-1')
239-
expect(result1).toBeTruthy()
218+
const commandManager = await createCommandManager(
219+
srcTmpPath || '/undefined-path',
220+
false
221+
)
222+
await commandManager.config(
223+
'remote.origin.url',
224+
'git@github.com:PHP-Prefixer/php-prefixer-build-action.git'
225+
)
226+
await tmpIGitHelper.remoteAddUrl('prefixed-origin-3')
227+
const result = await tmpIGitHelper.remoteExists('prefixed-origin-3')
228+
expect(result).toBeTruthy()
240229

241-
await tmpIGitHelper.remoteAdd(true, 'prefixed-origin-2')
242-
const result2 = await tmpIGitHelper.remoteExists('prefixed-origin-2')
243-
expect(result2).toBeTruthy()
230+
destroyTmpRepo()
231+
})
244232

245-
if (srcTmpPath) {
246-
const commandManager = await createCommandManager(srcTmpPath, false)
247-
await commandManager.config(
248-
'remote.origin.url',
249-
'git@github.com:PHP-Prefixer/php-prefixer-build-action.git'
250-
)
251-
await tmpIGitHelper.remoteAdd(true, 'prefixed-origin-3')
252-
const result3 = await tmpIGitHelper.remoteExists('prefixed-origin-3')
253-
expect(result3).toBeTruthy()
254-
}
233+
test('remote add local path', async () => {
234+
const tmpIGitHelper = await createTmpRepo()
235+
236+
await tmpIGitHelper.remoteAddLocalPath(
237+
'prefixed-origin-1',
238+
srcTmpPath || '/undefined-path'
239+
)
240+
const result1 = await tmpIGitHelper.remoteExists('prefixed-origin-1')
241+
expect(result1).toBeTruthy()
255242

256243
destroyTmpRepo()
257244
})

__tests__/main-helper.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ test('main - prefix anibalsanchez/hello-wp-world', async () => {
3939
)
4040
const gitHelper = await createGitHelper(sourceSettings)
4141
const currentBranch = await gitHelper.currentBranch()
42-
await gitHelper.commitAll()
42+
await gitHelper.addAllAndCommit()
4343
await gitHelper.push('origin', currentBranch)
4444
await fs.promises.rm(sourceSettings.repositoryPath, {recursive: true})
4545
sourceSettings.repositoryPath = ''

0 commit comments

Comments
 (0)