Skip to content

Commit a6ddbd0

Browse files
authored
Merge pull request #14 from vtex/extend/conflict-resolver
Extend conflict resolver to handle all pages-graphql files(on promote)
2 parents 97354bb + 1ef23e6 commit a6ddbd0

12 files changed

+1156
-93
lines changed

.github/workflows/ci.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- uses: actions/checkout@v2
1515
- uses: actions/setup-node@v1
1616
with:
17-
node-version: 12
17+
node-version: 20
1818
- run: yarn install --ignore-scripts
1919
- run: yarn run ci:prettier-check
2020
- run: yarn run lint
@@ -25,7 +25,7 @@ jobs:
2525
strategy:
2626
fail-fast: true
2727
matrix:
28-
node-version: [12]
28+
node-version: [20]
2929
os: [ubuntu-latest, windows-latest, macOS-latest]
3030

3131
steps:
@@ -34,4 +34,4 @@ jobs:
3434
with:
3535
node-version: ${{ matrix.node-version }}
3636
- run: yarn install --ignore-scripts
37-
- run: yarn run ci:test
37+
- run: yarn run ci:test

.github/workflows/publish-prerelease-npm.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ jobs:
1414
- uses: actions/checkout@v2
1515
- uses: actions/setup-node@v1
1616
with:
17-
node-version: 12
18-
registry-url: https://registry.npmjs.org/
17+
node-version: 20
18+
registry-url: https://registry.npmjs.org/
1919
- run: yarn install --ignore-scripts
2020
- run: yarn build
2121
- run: npm publish --access=public --tag beta
2222
env:
23-
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
24-
IS_CI: "true"
23+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
24+
IS_CI: 'true'

.github/workflows/publish-stable-npm.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ jobs:
1414
- uses: actions/checkout@v2
1515
- uses: actions/setup-node@v1
1616
with:
17-
node-version: 12
18-
registry-url: https://registry.npmjs.org/
17+
node-version: 20
18+
registry-url: https://registry.npmjs.org/
1919
- run: yarn install --ignore-scripts
2020
- run: yarn build
2121
- run: npm publish --access=public
2222
env:
23-
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
24-
IS_CI: "true"
23+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
24+
IS_CI: 'true'

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Changed
9+
- Improve conflict resolver on promote
810

911
## [1.0.1] - 2021-03-30
1012

README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ $ npm install -g @vtex/cli-plugin-workspace
2929
$ oclif-example COMMAND
3030
running command...
3131
$ oclif-example (-v|--version|version)
32-
@vtex/cli-plugin-workspace/1.0.1 linux-x64 node-v12.21.0
32+
@vtex/cli-plugin-workspace/1.1.0 linux-x64 node-v12.22.12
3333
$ oclif-example --help [COMMAND]
3434
USAGE
3535
$ oclif-example COMMAND
@@ -69,7 +69,7 @@ EXAMPLES
6969
vtex workspace delete workspaceName1 workspaceName2
7070
```
7171

72-
_See code: [build/commands/workspace/delete.ts](https://github.com/vtex/cli-plugin-workspace/blob/v1.0.1/build/commands/workspace/delete.ts)_
72+
_See code: [build/commands/workspace/delete.ts](https://github.com/vtex/cli-plugin-workspace/blob/v1.1.0/build/commands/workspace/delete.ts)_
7373

7474
## `oclif-example workspace:list`
7575

@@ -92,11 +92,11 @@ EXAMPLES
9292
vtex workspace ls
9393
```
9494

95-
_See code: [build/commands/workspace/list.ts](https://github.com/vtex/cli-plugin-workspace/blob/v1.0.1/build/commands/workspace/list.ts)_
95+
_See code: [build/commands/workspace/list.ts](https://github.com/vtex/cli-plugin-workspace/blob/v1.1.0/build/commands/workspace/list.ts)_
9696

9797
## `oclif-example workspace:promote`
9898

99-
Promotes the current workspace to master. (Only works for production workspaces.) Run [38;5;205mvtex promote --help to see how to deal with data conflicts.
99+
Promotes the current workspace to master. (Only works for production workspaces.) Run mvtex promote --help to see how to deal with data conflicts.
100100

101101
```
102102
USAGE
@@ -126,7 +126,7 @@ EXAMPLES
126126
vtex promote
127127
```
128128

129-
_See code: [build/commands/workspace/promote.ts](https://github.com/vtex/cli-plugin-workspace/blob/v1.0.1/build/commands/workspace/promote.ts)_
129+
_See code: [build/commands/workspace/promote.ts](https://github.com/vtex/cli-plugin-workspace/blob/v1.1.0/build/commands/workspace/promote.ts)_
130130

131131
## `oclif-example workspace:reset [WORKSPACENAME]`
132132

@@ -151,7 +151,7 @@ EXAMPLES
151151
vtex workspace reset workspaceName
152152
```
153153

154-
_See code: [build/commands/workspace/reset.ts](https://github.com/vtex/cli-plugin-workspace/blob/v1.0.1/build/commands/workspace/reset.ts)_
154+
_See code: [build/commands/workspace/reset.ts](https://github.com/vtex/cli-plugin-workspace/blob/v1.1.0/build/commands/workspace/reset.ts)_
155155

156156
## `oclif-example workspace:status [WORKSPACENAME]`
157157

@@ -173,7 +173,7 @@ EXAMPLE
173173
vtex workspace status
174174
```
175175

176-
_See code: [build/commands/workspace/status.ts](https://github.com/vtex/cli-plugin-workspace/blob/v1.0.1/build/commands/workspace/status.ts)_
176+
_See code: [build/commands/workspace/status.ts](https://github.com/vtex/cli-plugin-workspace/blob/v1.1.0/build/commands/workspace/status.ts)_
177177

178178
## `oclif-example workspace:use WORKSPACE`
179179

@@ -201,5 +201,5 @@ EXAMPLES
201201
vtex use workspaceName
202202
```
203203

204-
_See code: [build/commands/workspace/use.ts](https://github.com/vtex/cli-plugin-workspace/blob/v1.0.1/build/commands/workspace/use.ts)_
204+
_See code: [build/commands/workspace/use.ts](https://github.com/vtex/cli-plugin-workspace/blob/v1.1.0/build/commands/workspace/use.ts)_
205205
<!-- commandsstop -->

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@vtex/cli-plugin-workspace",
33
"description": "vtex plugin workspace",
4-
"version": "1.0.1",
4+
"version": "1.1.0",
55
"bugs": "https://github.com/vtex/cli-plugin-workspace/issues",
66
"dependencies": {
77
"@oclif/command": "^1",
@@ -28,7 +28,9 @@
2828
"ts-jest": "^25.2.1",
2929
"ts-node": "^8",
3030
"typescript": "^3.8.2",
31-
"vtex": "2.111.2-beta"
31+
"vtex-latest": "npm:[email protected]",
32+
"vtex": "npm:[email protected]",
33+
"@vtex/api": "npm:@vtex/[email protected]"
3234
},
3335
"engines": {
3436
"node": ">=8.0.0"

src/commands/workspace/delete.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default class WorkspaceDelete extends CustomCommand {
1313
`${ColorifyConstants.COMMAND_OR_VTEX_REF('vtex workspace delete')} workspaceName1 workspaceName2`,
1414
]
1515

16-
static flags = {
16+
static flags: oclifFlags.Input<any> = {
1717
...CustomCommand.globalFlags,
1818
force: oclifFlags.boolean({
1919
char: 'f',

src/commands/workspace/reset.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default class WorkspaceReset extends CustomCommand {
1414
`${ColorifyConstants.COMMAND_OR_VTEX_REF('vtex workspace reset')} workspaceName`,
1515
]
1616

17-
static flags = {
17+
static flags: oclifFlags.Input<any> = {
1818
...CustomCommand.globalFlags,
1919
production: oclifFlags.boolean({
2020
char: 'p',

src/commands/workspace/use.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default class WorkspaceUse extends CustomCommand {
1414

1515
static aliases = ['use']
1616

17-
static flags = {
17+
static flags: oclifFlags.Input<any> = {
1818
...CustomCommand.globalFlags,
1919
production: oclifFlags.boolean({
2020
char: 'p',

src/modules/delete.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Workspaces } from '@vtex/api'
1+
import { Workspaces } from 'vtex/node_modules/@vtex/api/lib/clients/Workspaces'
22
import chalk from 'chalk'
33
import { contains, flatten, tail } from 'ramda'
44
import { createWorkspacesClient, SessionManager, logger, promptConfirm, workspaceUse } from 'vtex'

src/modules/promote.ts

+19-6
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@ import {
88
SessionManager,
99
logger,
1010
promptConfirm,
11-
VBase,
1211
authUrl,
1312
workspaceUse,
1413
COLORS,
1514
} from 'vtex'
1615

17-
const { checkForConflicts } = VBase.createClient()
16+
import { VBase } from 'vtex-latest'
17+
import { MineWinsConflictsResolver } from '@vtex/api'
18+
19+
const vbase = VBase.createClient(undefined, {
20+
timeout: 120 * 1000,
21+
})
22+
1823
const { promote, get } = createWorkspacesClient()
1924
const { account, workspace: currentWorkspace } = SessionManager.getSingleton()
2025
const workspaceUrl = authUrl()
@@ -25,12 +30,20 @@ const throwIfIsMaster = (workspace: string) => {
2530
}
2631
}
2732

33+
/* This function is very specific to solve conflicts in the pages graphql app.
34+
The primary conflict resolution strategy at the file level
35+
is insufficient for safely resolving conflicts in the pages GraphQL application.
36+
All conflicts resolved here is using a mineWins strategy at the content json level.
37+
*/
2838
const handleConflict = async () => {
29-
const conflictsFound = await checkForConflicts()
39+
// Forcing rebase to avoid conflicts
40+
await axios.get(workspaceUrl)
3041

31-
if (conflictsFound) {
32-
await axios.get(workspaceUrl)
33-
}
42+
// @vtex/api expects a full implementation of the client, so we need to cast it to any.
43+
// The partial implementation is enough to solve conflicts.
44+
const conflictsResolver = new MineWinsConflictsResolver((vbase as Partial<VBase>) as any, 'userData', '')
45+
46+
return conflictsResolver.resolveAll()
3447
}
3548

3649
const isPromotable = async (workspace: string) => {

0 commit comments

Comments
 (0)