@apexdevtools/git-ops 1.4.1 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,131 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2024 Certinia Inc. All rights reserved.
4
- */
5
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
- return new (P || (P = Promise))(function (resolve, reject) {
8
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
- step((generator = generator.apply(thisArg, _arguments || [])).next());
12
- });
13
- };
14
- var __importDefault = (this && this.__importDefault) || function (mod) {
15
- return (mod && mod.__esModule) ? mod : { "default": mod };
16
- };
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.RepoHelper = void 0;
19
- const simple_git_1 = __importDefault(require("simple-git"));
20
- const fs_1 = __importDefault(require("fs"));
21
- const path_1 = __importDefault(require("path"));
22
- class RepoHelper {
23
- constructor(rootDir) {
24
- this.isInit = false;
25
- this.rootDir = rootDir;
26
- this.remoteRepoDir = rootDir + '/remote.git';
27
- this.testRepoDir = rootDir + '/test-repo';
28
- }
29
- static getInstance(rootDir) {
30
- let mng = this.instances.get(rootDir);
31
- if (!mng) {
32
- mng = new RepoHelper(rootDir);
33
- this.instances.set(rootDir, mng);
34
- }
35
- return mng;
36
- }
37
- get git() {
38
- if (!this.isInit) {
39
- throw new Error('Cannot perform git operation before calling init()');
40
- }
41
- // eslint-disable-next-line
42
- return (0, simple_git_1.default)(this.testRepoDir);
43
- }
44
- initRemoteRepo() {
45
- return __awaiter(this, void 0, void 0, function* () {
46
- if (!fs_1.default.existsSync(this.remoteRepoDir)) {
47
- fs_1.default.mkdirSync(this.remoteRepoDir, { recursive: true });
48
- // eslint-disable-next-line
49
- const git = (0, simple_git_1.default)(this.remoteRepoDir);
50
- yield git.init(true);
51
- }
52
- });
53
- }
54
- cloneRepo() {
55
- return __awaiter(this, void 0, void 0, function* () {
56
- if (fs_1.default.existsSync(this.remoteRepoDir) && !fs_1.default.existsSync(this.testRepoDir)) {
57
- // eslint-disable-next-line
58
- yield (0, simple_git_1.default)().clone(this.remoteRepoDir, this.testRepoDir);
59
- }
60
- });
61
- }
62
- get repoDir() {
63
- return this.testRepoDir;
64
- }
65
- init() {
66
- return __awaiter(this, void 0, void 0, function* () {
67
- yield this.initRemoteRepo();
68
- yield this.cloneRepo();
69
- this.isInit = true;
70
- yield this.git.raw(['checkout', '-b', 'main']);
71
- });
72
- }
73
- setHead() {
74
- return __awaiter(this, void 0, void 0, function* () {
75
- return yield this.git
76
- .raw(['symbolic-ref', 'HEAD', 'refs/heads/main'])
77
- .then(() => this.git.remote(['set-head', 'origin', 'main']))
78
- .catch(err => console.log('set head failed ', err));
79
- });
80
- }
81
- push() {
82
- return __awaiter(this, void 0, void 0, function* () {
83
- return yield this.git
84
- .push('origin', 'main', ['-u'])
85
- .catch(err => console.log('push failed ', err));
86
- });
87
- }
88
- checkout(branchName, from) {
89
- return __awaiter(this, void 0, void 0, function* () {
90
- return this.git.checkoutBranch(branchName, from);
91
- });
92
- }
93
- stageAll(files = ['.']) {
94
- return __awaiter(this, void 0, void 0, function* () {
95
- return this.git.add(files);
96
- });
97
- }
98
- getGitLog() {
99
- return __awaiter(this, void 0, void 0, function* () {
100
- const log = yield this.git.log();
101
- return log.all;
102
- });
103
- }
104
- stageAndCommitAll(files) {
105
- return __awaiter(this, void 0, void 0, function* () {
106
- return this.stageAll(files).then(() => this.git.commit('commit message'));
107
- });
108
- }
109
- tearDown() {
110
- fs_1.default.rmSync(this.rootDir, { recursive: true, force: true });
111
- }
112
- createOrUpdateFile(fileName, content) {
113
- const fPath = path_1.default.join(this.testRepoDir, fileName);
114
- if (fs_1.default.existsSync(fPath)) {
115
- fs_1.default.appendFileSync(fPath, content);
116
- }
117
- else {
118
- fs_1.default.writeFileSync(fPath, content);
119
- }
120
- }
121
- rmFile(file) {
122
- fs_1.default.unlinkSync(path_1.default.join(this.testRepoDir, file));
123
- }
124
- renameFileInRepo(from, to) {
125
- const fromPath = path_1.default.join(this.testRepoDir, from);
126
- const toPath = path_1.default.join(this.testRepoDir, to);
127
- fs_1.default.renameSync(fromPath, toPath);
128
- }
129
- }
130
- exports.RepoHelper = RepoHelper;
131
- RepoHelper.instances = new Map();
@@ -1 +0,0 @@
1
- export {};
@@ -1,312 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2024 Certinia Inc. All rights reserved.
4
- */
5
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
- return new (P || (P = Promise))(function (resolve, reject) {
8
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
- step((generator = generator.apply(thisArg, _arguments || [])).next());
12
- });
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const src_1 = require("../src");
16
- const core_1 = require("@salesforce/core");
17
- const mockGetStatusData = [
18
- {
19
- fullName: 'SomeComponent',
20
- filePath: 'path/to/file',
21
- type: 'class',
22
- origin: 'local',
23
- ignored: false,
24
- conflict: false,
25
- state: 'add',
26
- },
27
- {
28
- fullName: 'SomeComponent1',
29
- filePath: 'path/to/file/1',
30
- type: 'class',
31
- origin: 'local',
32
- ignored: false,
33
- conflict: true,
34
- state: 'delete',
35
- },
36
- {
37
- fullName: 'SomeComponent2',
38
- filePath: 'path/to/file/2',
39
- type: 'class',
40
- origin: 'local',
41
- ignored: true,
42
- conflict: false,
43
- state: 'modify',
44
- },
45
- {
46
- fullName: 'SomeComponent3',
47
- filePath: 'path/to/file/3',
48
- type: 'class',
49
- origin: 'local',
50
- ignored: true,
51
- conflict: true,
52
- state: 'nondelete',
53
- },
54
- {
55
- fullName: 'NoPathComponent',
56
- filePath: undefined,
57
- type: 'metadata',
58
- origin: 'local',
59
- ignored: false,
60
- conflict: false,
61
- state: 'add',
62
- },
63
- ];
64
- const mockConflictsData = [
65
- {
66
- filenames: [
67
- 'path/to/file',
68
- 'path/to/file/3',
69
- { nonString: 'object' },
70
- 'path/to/file/non/existent',
71
- ],
72
- },
73
- ];
74
- jest.mock('@salesforce/core', () => {
75
- return {
76
- SfProject: { getInstance: jest.fn() },
77
- Org: { create: jest.fn() },
78
- };
79
- });
80
- const mockConnection = jest.fn();
81
- const mockSourceTracking = {
82
- ensureRemoteTracking: jest.fn(),
83
- getStatus: jest
84
- .fn()
85
- .mockImplementation(() => Promise.resolve(mockGetStatusData)),
86
- getConflicts: jest
87
- .fn()
88
- .mockImplementation(() => Promise.resolve(mockConflictsData)),
89
- updateTrackingFromDeploy: jest
90
- .fn()
91
- .mockImplementation(() => Promise.resolve()),
92
- };
93
- jest.mock('@salesforce/source-tracking', () => {
94
- return {
95
- SourceTracking: {
96
- create: jest
97
- .fn()
98
- .mockImplementation(() => Promise.resolve(Object.assign({}, mockSourceTracking))),
99
- },
100
- };
101
- });
102
- const mockDeploy = {
103
- onUpdate: jest.fn(),
104
- pollStatus: jest
105
- .fn()
106
- .mockImplementation(() => Promise.resolve(mockDeployResult)),
107
- };
108
- const mockDeployResult = { response: { success: true } };
109
- const mockComponentSet = {
110
- deploy: jest
111
- .fn()
112
- .mockImplementation(() => Promise.resolve(Object.assign({}, mockDeploy))),
113
- };
114
- jest.mock('@salesforce/source-deploy-retrieve', () => {
115
- return {
116
- ComponentSet: {
117
- fromSource: jest.fn().mockImplementation(() => {
118
- return Object.assign({}, mockComponentSet);
119
- }),
120
- },
121
- };
122
- });
123
- describe('OrgTracking', () => {
124
- const PROJECT_DIR = 'path/to/dir';
125
- let cwdSpy, chdirSpy;
126
- const sfCoreSpy = {
127
- SfProject: { getInstance: jest.spyOn(core_1.SfProject, 'getInstance') },
128
- Org: { create: jest.spyOn(core_1.Org, 'create') },
129
- };
130
- beforeEach(() => {
131
- jest.mock('process');
132
- cwdSpy = jest
133
- .spyOn(process, 'cwd')
134
- .mockImplementation(() => 'mocked/current/working/dir');
135
- chdirSpy = jest.spyOn(process, 'chdir').mockImplementation(() => {
136
- return;
137
- });
138
- });
139
- afterEach(() => {
140
- jest.clearAllMocks();
141
- });
142
- const mockLogger = {
143
- logDeployProgress: jest.fn(),
144
- logError: jest.fn(),
145
- logMessage: jest.fn(),
146
- };
147
- describe('getLocalStatus', () => {
148
- it('returns the correct status', () => __awaiter(void 0, void 0, void 0, function* () {
149
- const tracking = new src_1.OrgTracking({
150
- connection: mockConnection,
151
- projectDir: PROJECT_DIR,
152
- logger: mockLogger,
153
- });
154
- const res = yield tracking.getLocalStatus();
155
- expect(cwdSpy).toHaveBeenCalled();
156
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
157
- expect(chdirSpy.mock.calls).toEqual([
158
- [PROJECT_DIR],
159
- ['mocked/current/working/dir'],
160
- ]);
161
- expect(sfCoreSpy.Org.create).toHaveBeenCalledWith({
162
- connection: mockConnection,
163
- });
164
- expect(sfCoreSpy.SfProject.getInstance).toHaveBeenCalledWith(PROJECT_DIR);
165
- expect(mockSourceTracking.ensureRemoteTracking).toHaveBeenCalledWith(true);
166
- expect(mockSourceTracking.getStatus).toHaveBeenCalledWith({
167
- local: true,
168
- remote: false,
169
- });
170
- expect(mockSourceTracking.getConflicts).not.toBeCalled();
171
- expect(res).toEqual({
172
- local: [
173
- {
174
- fullName: 'SomeComponent',
175
- origin: 'local',
176
- path: 'path/to/file',
177
- state: ['add'],
178
- type: 'class',
179
- },
180
- {
181
- fullName: 'SomeComponent1',
182
- origin: 'local',
183
- path: 'path/to/file/1',
184
- state: ['conflict', 'delete'],
185
- type: 'class',
186
- },
187
- {
188
- fullName: 'SomeComponent2',
189
- origin: 'local',
190
- path: 'path/to/file/2',
191
- state: ['ignore', 'modify'],
192
- type: 'class',
193
- },
194
- {
195
- fullName: 'SomeComponent3',
196
- origin: 'local',
197
- path: 'path/to/file/3',
198
- state: ['ignore', 'conflict', 'nondelete'],
199
- type: 'class',
200
- },
201
- {
202
- fullName: 'NoPathComponent',
203
- path: undefined,
204
- type: 'metadata',
205
- origin: 'local',
206
- state: ['add'],
207
- },
208
- ],
209
- remote: [],
210
- });
211
- }));
212
- it('returns the correct status with conflicts', () => __awaiter(void 0, void 0, void 0, function* () {
213
- //Given
214
- const tracking = new src_1.OrgTracking({
215
- connection: mockConnection,
216
- projectDir: PROJECT_DIR,
217
- logger: mockLogger,
218
- });
219
- //When
220
- const res = yield tracking.getLocalStatus(true);
221
- //Then
222
- expect(cwdSpy).toHaveBeenCalled();
223
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
224
- expect(chdirSpy.mock.calls).toEqual([
225
- [PROJECT_DIR],
226
- ['mocked/current/working/dir'],
227
- ]);
228
- expect(sfCoreSpy.Org.create).toHaveBeenCalledWith({
229
- connection: mockConnection,
230
- });
231
- expect(sfCoreSpy.SfProject.getInstance).toHaveBeenCalledWith(PROJECT_DIR);
232
- expect(mockSourceTracking.ensureRemoteTracking).toHaveBeenCalledWith(true);
233
- expect(mockSourceTracking.getStatus).toHaveBeenCalledWith({
234
- local: true,
235
- remote: false,
236
- });
237
- expect(mockSourceTracking.getConflicts).toBeCalled();
238
- expect(res).toEqual({
239
- local: [
240
- {
241
- fullName: 'SomeComponent',
242
- origin: 'local',
243
- path: 'path/to/file',
244
- state: ['conflict', 'add'],
245
- type: 'class',
246
- },
247
- {
248
- fullName: 'SomeComponent1',
249
- origin: 'local',
250
- path: 'path/to/file/1',
251
- state: ['delete'],
252
- type: 'class',
253
- },
254
- {
255
- fullName: 'SomeComponent2',
256
- origin: 'local',
257
- path: 'path/to/file/2',
258
- state: ['ignore', 'modify'],
259
- type: 'class',
260
- },
261
- {
262
- fullName: 'SomeComponent3',
263
- origin: 'local',
264
- path: 'path/to/file/3',
265
- state: ['ignore', 'conflict', 'nondelete'],
266
- type: 'class',
267
- },
268
- {
269
- fullName: 'NoPathComponent',
270
- origin: 'local',
271
- path: undefined,
272
- state: ['add'],
273
- type: 'metadata',
274
- },
275
- ],
276
- remote: [],
277
- });
278
- }));
279
- });
280
- describe('deployAndUpdateSourceTracking', () => {
281
- it('deploys and update tracking given paths', () => __awaiter(void 0, void 0, void 0, function* () {
282
- //Given
283
- const paths = ['/path/to/component', '/path/to/component/1'];
284
- const tracking = new src_1.OrgTracking({
285
- connection: mockConnection,
286
- projectDir: PROJECT_DIR,
287
- logger: mockLogger,
288
- });
289
- //When
290
- yield tracking.deployAndUpdateSourceTracking(paths);
291
- //Then
292
- expect(cwdSpy).toHaveBeenCalled();
293
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
294
- expect(chdirSpy.mock.calls).toEqual([
295
- [PROJECT_DIR],
296
- ['mocked/current/working/dir'],
297
- ]);
298
- expect(mockComponentSet.deploy).toHaveBeenCalledWith({
299
- usernameOrConnection: mockConnection,
300
- });
301
- expect(mockDeploy.onUpdate).toHaveBeenCalled();
302
- expect(mockDeploy.pollStatus).toHaveBeenCalled();
303
- expect(sfCoreSpy.Org.create).toHaveBeenCalledWith({
304
- connection: mockConnection,
305
- });
306
- expect(sfCoreSpy.SfProject.getInstance).toHaveBeenCalledWith(PROJECT_DIR);
307
- expect(mockSourceTracking.updateTrackingFromDeploy).toHaveBeenCalledWith(mockDeployResult);
308
- // eslint-disable-next-line @typescript-eslint/unbound-method
309
- expect(mockLogger.logDeployProgress).toBeCalledWith('Starting deploy');
310
- }));
311
- });
312
- });
File without changes
File without changes
File without changes
File without changes