@apexdevtools/git-ops 1.3.0 → 1.4.1

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # git-ops - Changelog
2
2
 
3
+ ## 1.4.1 - 2024-11-22
4
+
5
+ - Fix missing deploy error reporting
6
+
7
+ ## 1.4.0 - 2024-02-07
8
+
9
+ - Add `getDeployableClasses` API for native based tracking
10
+
3
11
  ## 1.3.0 - 2023-10-13
4
12
 
5
13
  - Upgrade SF Core dependencies
@@ -30,3 +30,12 @@ export declare function getDiffRange(dir: string, fromRef: string, toRef: string
30
30
  * @returns set of absolute paths of un committed files
31
31
  */
32
32
  export declare function getLocalChanges(dir: string): Promise<Set<string>>;
33
+ /**
34
+ * Get the locally changed class files, based on source tracking repo. Note that it does
35
+ * not respect the `.forceignore` yet.
36
+ *
37
+ * @param projectDir SF project dir path
38
+ * @param orgId SF org ID, used to select tracking repo
39
+ * @returns paths of class files that may need deploying
40
+ */
41
+ export declare function getDeployableClasses(projectDir: string, orgId: string): Promise<Set<string>>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- * Copyright (c) 2023, FinancialForce.com, inc. All rights reserved.
3
+ * Copyright (c) 2024 Certinia Inc. All rights reserved.
4
4
  */
5
5
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
6
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -15,9 +15,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
15
15
  return (mod && mod.__esModule) ? mod : { "default": mod };
16
16
  };
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.getLocalChanges = exports.getDiffRange = exports.getDefaultBranchDiffByRef = exports.getDefaultBranchDiff = void 0;
18
+ exports.getDeployableClasses = exports.getLocalChanges = exports.getDiffRange = exports.getDefaultBranchDiffByRef = exports.getDefaultBranchDiff = void 0;
19
19
  const path_1 = __importDefault(require("path"));
20
- const Git_1 = require("../Git/Git");
20
+ const git_1 = require("./git");
21
21
  /**
22
22
  * Works out a set of changed files by performing getDefaultBranchDiffByRef(repoRootDir, 'HEAD')
23
23
  * @param dir: string of the directory thr operation should be performed on
@@ -41,7 +41,7 @@ exports.getDefaultBranchDiff = getDefaultBranchDiff;
41
41
  */
42
42
  function getDefaultBranchDiffByRef(dir, refTo) {
43
43
  return __awaiter(this, void 0, void 0, function* () {
44
- const git = new Git_1.Git(dir);
44
+ const git = new git_1.Git(dir);
45
45
  return git
46
46
  .getDefaultBranchName()
47
47
  .then(branch => getDiffRange(dir, branch, refTo))
@@ -60,7 +60,7 @@ exports.getDefaultBranchDiffByRef = getDefaultBranchDiffByRef;
60
60
  */
61
61
  function getDiffRange(dir, fromRef, toRef) {
62
62
  return __awaiter(this, void 0, void 0, function* () {
63
- const git = new Git_1.Git(dir);
63
+ const git = new git_1.Git(dir);
64
64
  const root = yield git.gitRoot();
65
65
  return getDiffChanges(git, fromRef, toRef)
66
66
  .then(changes => resolvePaths(changes, root))
@@ -78,7 +78,7 @@ exports.getDiffRange = getDiffRange;
78
78
  */
79
79
  function getLocalChanges(dir) {
80
80
  return __awaiter(this, void 0, void 0, function* () {
81
- const git = new Git_1.Git(dir);
81
+ const git = new git_1.Git(dir);
82
82
  const root = yield git.gitRoot();
83
83
  return git
84
84
  .getLocalChangedAndCreated()
@@ -89,8 +89,36 @@ function getLocalChanges(dir) {
89
89
  });
90
90
  }
91
91
  exports.getLocalChanges = getLocalChanges;
92
+ /**
93
+ * Get the locally changed class files, based on source tracking repo. Note that it does
94
+ * not respect the `.forceignore` yet.
95
+ *
96
+ * @param projectDir SF project dir path
97
+ * @param orgId SF org ID, used to select tracking repo
98
+ * @returns paths of class files that may need deploying
99
+ */
100
+ function getDeployableClasses(projectDir, orgId) {
101
+ return __awaiter(this, void 0, void 0, function* () {
102
+ const git = new git_1.Git(projectDir);
103
+ const trackingDir = getTrackingGitDir(projectDir, orgId);
104
+ const stats = [
105
+ git_1.FileStatus.Modified,
106
+ git_1.FileStatus.Added,
107
+ git_1.FileStatus.Renamed,
108
+ git_1.FileStatus.Copied,
109
+ git_1.FileStatus.Untracked,
110
+ ];
111
+ return git
112
+ .getFilteredStatus(f => f.path.endsWith('.cls') && stats.includes(f.working_dir), trackingDir)
113
+ .then(changes => resolvePaths(changes, projectDir))
114
+ .catch(er => {
115
+ throw new LocalChangeException(er);
116
+ });
117
+ });
118
+ }
119
+ exports.getDeployableClasses = getDeployableClasses;
92
120
  function resolvePaths(paths, root) {
93
- const fullPaths = [...paths].map(p => path_1.default.resolve(path_1.default.join(root, p)));
121
+ const fullPaths = [...paths].map(p => path_1.default.resolve(root, p));
94
122
  return new Set(fullPaths);
95
123
  }
96
124
  function getDiffChanges(git, ref1, ref2) {
@@ -104,6 +132,9 @@ function getDiffChanges(git, ref1, ref2) {
104
132
  return allChanges;
105
133
  });
106
134
  }
135
+ function getTrackingGitDir(projectDir, orgId) {
136
+ return path_1.default.resolve(projectDir, '.sf', 'orgs', orgId, 'localSourceTracking');
137
+ }
107
138
  class GitException extends Error {
108
139
  constructor(msg, err) {
109
140
  if (err instanceof Error) {
@@ -1,5 +1,4 @@
1
- import { SimpleGit } from 'simple-git';
2
- import { IGit } from '../api/IGit';
1
+ import { FileStatusResult, SimpleGit } from 'simple-git';
3
2
  export declare enum FileStatus {
4
3
  Unmodified = " ",
5
4
  Modified = "M",
@@ -12,7 +11,7 @@ export declare enum FileStatus {
12
11
  Untracked = "?",
13
12
  Ignore = "!"
14
13
  }
15
- export declare class Git implements IGit {
14
+ export declare class Git {
16
15
  private static MIN_GIT_VERSION_MAJOR;
17
16
  private static MIN_GIT_VERSION_MINOR;
18
17
  private gitInstance;
@@ -24,4 +23,5 @@ export declare class Git implements IGit {
24
23
  getDefaultBranchName(): Promise<string>;
25
24
  diffRange(fromRef: string, toRef: string): Promise<Set<string>>;
26
25
  getLocalChangedAndCreated(): Promise<Set<string>>;
26
+ getFilteredStatus(filterFn: (result: FileStatusResult) => boolean, gitDir?: string | undefined): Promise<Set<string>>;
27
27
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- * Copyright (c) 2022, FinancialForce.com, inc. All rights reserved.
3
+ * Copyright (c) 2024 Certinia Inc. All rights reserved.
4
4
  */
5
5
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
6
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -93,14 +93,18 @@ class Git {
93
93
  getLocalChangedAndCreated() {
94
94
  return __awaiter(this, void 0, void 0, function* () {
95
95
  const excludeStatus = [FileStatus.Deleted, FileStatus.Ignore];
96
+ return this.getFilteredStatus(f => !excludeStatus.includes(f.index) &&
97
+ !excludeStatus.includes(f.working_dir));
98
+ });
99
+ }
100
+ getFilteredStatus(filterFn, gitDir) {
101
+ return __awaiter(this, void 0, void 0, function* () {
96
102
  return this.git
97
- .then(git => git.status())
103
+ .then(git => {
104
+ return gitDir ? git.env('GIT_DIR', gitDir).status() : git.status();
105
+ })
98
106
  .then(status => {
99
- const changedFiles = status.files
100
- .filter(f => !excludeStatus.includes(f.index) &&
101
- !excludeStatus.includes(f.working_dir))
102
- .map(f => f.path);
103
- return new Set(...[changedFiles]);
107
+ return new Set(...[status.files.filter(filterFn).map(f => f.path)]);
104
108
  });
105
109
  });
106
110
  }
@@ -1,5 +1,3 @@
1
- export { getDefaultBranchDiff, getDefaultBranchDiffByRef, getDiffRange, getLocalChanges, } from './FilesChanged/BranchChanges';
2
- export { OrgTracking, OrgTrackingOptions, FileState, SyncStatusRow, SyncStatus, } from './OrgTracking/Tracking';
3
- export { Logger } from './logger/Logger';
4
- export { IGit } from './api/IGit';
5
- export { Git } from './Git/Git';
1
+ export { getDefaultBranchDiff, getDefaultBranchDiffByRef, getDiffRange, getLocalChanges, getDeployableClasses, } from './changes';
2
+ export { OrgTracking, OrgTrackingOptions, OrgTrackingLogger, FileState, SyncStatusRow, SyncStatus, } from './tracking';
3
+ export { Git } from './git';
package/lib/src/index.js CHANGED
@@ -1,16 +1,17 @@
1
1
  "use strict";
2
2
  /*
3
- * Copyright (c) 2023, FinancialForce.com, inc. All rights reserved.
3
+ * Copyright (c) 2024 Certinia Inc. All rights reserved.
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Git = exports.FileState = exports.OrgTracking = exports.getLocalChanges = exports.getDiffRange = exports.getDefaultBranchDiffByRef = exports.getDefaultBranchDiff = void 0;
7
- var BranchChanges_1 = require("./FilesChanged/BranchChanges");
8
- Object.defineProperty(exports, "getDefaultBranchDiff", { enumerable: true, get: function () { return BranchChanges_1.getDefaultBranchDiff; } });
9
- Object.defineProperty(exports, "getDefaultBranchDiffByRef", { enumerable: true, get: function () { return BranchChanges_1.getDefaultBranchDiffByRef; } });
10
- Object.defineProperty(exports, "getDiffRange", { enumerable: true, get: function () { return BranchChanges_1.getDiffRange; } });
11
- Object.defineProperty(exports, "getLocalChanges", { enumerable: true, get: function () { return BranchChanges_1.getLocalChanges; } });
12
- var Tracking_1 = require("./OrgTracking/Tracking");
13
- Object.defineProperty(exports, "OrgTracking", { enumerable: true, get: function () { return Tracking_1.OrgTracking; } });
14
- Object.defineProperty(exports, "FileState", { enumerable: true, get: function () { return Tracking_1.FileState; } });
15
- var Git_1 = require("./Git/Git");
16
- Object.defineProperty(exports, "Git", { enumerable: true, get: function () { return Git_1.Git; } });
6
+ exports.Git = exports.FileState = exports.OrgTracking = exports.getDeployableClasses = exports.getLocalChanges = exports.getDiffRange = exports.getDefaultBranchDiffByRef = exports.getDefaultBranchDiff = void 0;
7
+ var changes_1 = require("./changes");
8
+ Object.defineProperty(exports, "getDefaultBranchDiff", { enumerable: true, get: function () { return changes_1.getDefaultBranchDiff; } });
9
+ Object.defineProperty(exports, "getDefaultBranchDiffByRef", { enumerable: true, get: function () { return changes_1.getDefaultBranchDiffByRef; } });
10
+ Object.defineProperty(exports, "getDiffRange", { enumerable: true, get: function () { return changes_1.getDiffRange; } });
11
+ Object.defineProperty(exports, "getLocalChanges", { enumerable: true, get: function () { return changes_1.getLocalChanges; } });
12
+ Object.defineProperty(exports, "getDeployableClasses", { enumerable: true, get: function () { return changes_1.getDeployableClasses; } });
13
+ var tracking_1 = require("./tracking");
14
+ Object.defineProperty(exports, "OrgTracking", { enumerable: true, get: function () { return tracking_1.OrgTracking; } });
15
+ Object.defineProperty(exports, "FileState", { enumerable: true, get: function () { return tracking_1.FileState; } });
16
+ var git_1 = require("./git");
17
+ Object.defineProperty(exports, "Git", { enumerable: true, get: function () { return git_1.Git; } });
@@ -1,5 +1,4 @@
1
1
  import { Connection } from '@salesforce/core';
2
- import { Logger } from '../logger/Logger';
3
2
  export declare enum FileState {
4
3
  Added = "add",
5
4
  Modified = "modify",
@@ -22,7 +21,12 @@ export interface SyncStatus {
22
21
  export interface OrgTrackingOptions {
23
22
  connection: Connection;
24
23
  projectDir: string;
25
- logger: Logger;
24
+ logger: OrgTrackingLogger;
25
+ }
26
+ export interface OrgTrackingLogger {
27
+ logError(error: any): void;
28
+ logMessage(message: any): void;
29
+ logDeployProgress(status: string): void;
26
30
  }
27
31
  export declare class OrgTracking {
28
32
  private options;
@@ -31,6 +35,8 @@ export declare class OrgTracking {
31
35
  getLocalStatus(withConflicts?: boolean): Promise<SyncStatus>;
32
36
  deployAndUpdateSourceTracking(paths: Array<string>): Promise<void>;
33
37
  private deploy;
38
+ private reportDeployStatus;
39
+ private reportDeployErrors;
34
40
  private updateSourceTracking;
35
41
  private toSyncStatusRow;
36
42
  private withWorkingDir;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- * Copyright (c) 2023 Certinia Inc. All rights reserved.
3
+ * Copyright (c) 2024 Certinia Inc. All rights reserved.
4
4
  */
5
5
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
6
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -69,33 +69,55 @@ class OrgTracking {
69
69
  deployAndUpdateSourceTracking(paths) {
70
70
  return __awaiter(this, void 0, void 0, function* () {
71
71
  return yield this.withWorkingDir(this.options.projectDir, () => __awaiter(this, void 0, void 0, function* () {
72
- return this.deploy(paths)
73
- .then(res => this.updateSourceTracking(res))
74
- .catch(e => this.logger.logError(e));
72
+ try {
73
+ this.logger.logDeployProgress('Starting deploy');
74
+ const result = yield this.deploy(paths);
75
+ if (result.response.success) {
76
+ yield this.updateSourceTracking(result);
77
+ }
78
+ else {
79
+ this.reportDeployErrors(result);
80
+ }
81
+ this.logger.logDeployProgress('Finished deploy');
82
+ }
83
+ catch (e) {
84
+ this.logger.logError(e);
85
+ }
75
86
  }));
76
87
  });
77
88
  }
78
89
  deploy(paths) {
79
90
  return __awaiter(this, void 0, void 0, function* () {
80
- const set = source_deploy_retrieve_1.ComponentSet.fromSource(paths);
81
- const deploy = yield set.deploy({
91
+ const deploy = yield source_deploy_retrieve_1.ComponentSet.fromSource(paths).deploy({
82
92
  usernameOrConnection: this.options.connection,
83
93
  });
84
- this.logger.logDeployProgress('Starting deploy');
85
- deploy.onUpdate(response => {
86
- const { status, numberComponentsDeployed, numberComponentsTotal, } = response;
87
- const progress = `${numberComponentsDeployed}/${numberComponentsTotal}`;
88
- const message = `Status: ${status} Progress: ${progress}`;
89
- this.logger.logDeployProgress(message);
90
- });
91
- return yield deploy.pollStatus().then(res => {
92
- this.logger.logMessage('Finished deploy');
93
- return res;
94
- });
94
+ deploy.onUpdate(response => this.reportDeployStatus(response));
95
+ const result = yield deploy.pollStatus();
96
+ this.reportDeployStatus(result.response);
97
+ return result;
95
98
  });
96
99
  }
100
+ reportDeployStatus(response) {
101
+ const { status, numberComponentsDeployed, numberComponentsTotal, numberComponentErrors, } = response;
102
+ const progress = `${numberComponentsDeployed}/${numberComponentsTotal}`;
103
+ const message = `Status: ${status} | Progress: ${progress} | Errors: ${numberComponentErrors}`;
104
+ this.logger.logDeployProgress(message);
105
+ }
106
+ reportDeployErrors(result) {
107
+ const errors = result.getFileResponses().reduce((a, c) => {
108
+ if (c.state === source_deploy_retrieve_1.ComponentStatus.Failed) {
109
+ a.push(new Error(`${c.fullName}: ${c.error}`));
110
+ }
111
+ return a;
112
+ }, []);
113
+ if (errors.length) {
114
+ this.logger.logDeployProgress('Deploy errors:');
115
+ errors.forEach(err => this.logger.logError(err));
116
+ }
117
+ }
97
118
  updateSourceTracking(result) {
98
119
  return __awaiter(this, void 0, void 0, function* () {
120
+ this.logger.logDeployProgress('Starting source tracking update');
99
121
  const project = core_1.SfProject.getInstance(this.options.projectDir);
100
122
  const org = yield core_1.Org.create({ connection: this.options.connection });
101
123
  const tracking = yield source_tracking_1.SourceTracking.create({
@@ -104,6 +126,7 @@ class OrgTracking {
104
126
  ignoreLocalCache: true,
105
127
  });
106
128
  yield tracking.updateTrackingFromDeploy(result);
129
+ this.logger.logDeployProgress('Finished source tracking update');
107
130
  });
108
131
  }
109
132
  toSyncStatusRow(from) {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- * Copyright (c) 2023, FinancialForce.com, inc. All rights reserved.
3
+ * Copyright (c) 2024 Certinia Inc. All rights reserved.
4
4
  */
5
5
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
6
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -11,37 +11,34 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  step((generator = generator.apply(thisArg, _arguments || [])).next());
12
12
  });
13
13
  };
14
- var __importDefault = (this && this.__importDefault) || function (mod) {
15
- return (mod && mod.__esModule) ? mod : { "default": mod };
16
- };
17
14
  Object.defineProperty(exports, "__esModule", { value: true });
18
- const Git_1 = require("../../src/Git/Git");
19
- const BranchChanges_1 = require("../../src/FilesChanged/BranchChanges");
20
- const path_1 = __importDefault(require("path"));
21
- jest.mock('path');
15
+ const src_1 = require("../src");
22
16
  const mockGitImpl = {
23
17
  getDefaultBranchName: jest.fn(),
24
18
  getLocalChangedAndCreated: jest.fn(),
25
19
  diffRange: jest.fn(),
26
20
  gitRoot: jest.fn(),
21
+ getFilteredStatus: jest.fn(),
27
22
  };
28
- jest.mock('../../src/Git/Git', () => {
23
+ jest.mock('../src/git', () => {
24
+ const { FileStatus } = jest.requireActual('../src/git');
29
25
  return {
30
26
  Git: jest.fn().mockImplementation(() => mockGitImpl),
27
+ FileStatus,
31
28
  };
32
29
  });
33
- const mockedGit = jest.mocked(Git_1.Git, { shallow: true });
34
30
  describe('Branch changes', () => {
35
- const mockRootDir = 'user/fake/path';
36
- beforeAll(() => {
37
- mockGitImpl.gitRoot.mockResolvedValue('abs/path/to/repo');
38
- jest
39
- .spyOn(path_1.default, 'resolve')
40
- .mockImplementation(dir => `${mockRootDir}/${dir}`);
41
- jest.spyOn(path_1.default, 'join').mockImplementation((a, b) => `${a}/${b}`);
31
+ const mockRootDir = '/reporoot';
32
+ beforeEach(() => {
33
+ mockGitImpl.gitRoot.mockResolvedValue(mockRootDir);
42
34
  });
43
35
  afterEach(() => {
44
36
  jest.clearAllMocks();
37
+ mockGitImpl.getDefaultBranchName.mockReset();
38
+ mockGitImpl.getLocalChangedAndCreated.mockReset();
39
+ mockGitImpl.diffRange.mockReset();
40
+ mockGitImpl.gitRoot.mockReset();
41
+ mockGitImpl.getFilteredStatus.mockReset();
45
42
  });
46
43
  describe('getDefaultBranchDiffByRef', () => {
47
44
  it('returns the correct set of files when git ops resolve', () => __awaiter(void 0, void 0, void 0, function* () {
@@ -50,23 +47,22 @@ describe('Branch changes', () => {
50
47
  mockGitImpl.diffRange.mockResolvedValue(new Set(['File.txt', 'AnotherClass.txt']));
51
48
  mockGitImpl.getLocalChangedAndCreated.mockResolvedValue(new Set(['SomeFile.txt']));
52
49
  //When
53
- const res = yield (0, BranchChanges_1.getDefaultBranchDiffByRef)('./some/path/to/dir', 'abc12fcd');
50
+ const res = yield (0, src_1.getDefaultBranchDiffByRef)('./some/path/to/dir', 'abc12fcd');
54
51
  //Then
55
- expect(mockedGit).toHaveBeenCalledWith('./some/path/to/dir');
56
52
  expect(mockGitImpl.getDefaultBranchName).toBeCalledTimes(1);
57
53
  expect(mockGitImpl.getLocalChangedAndCreated).toBeCalledTimes(1);
58
54
  expect(mockGitImpl.diffRange).toHaveBeenCalledWith('default/branch/name', 'abc12fcd');
59
55
  expect(res).toEqual(new Set([
60
- `${mockRootDir}/abs/path/to/repo/File.txt`,
61
- `${mockRootDir}/abs/path/to/repo/AnotherClass.txt`,
62
- `${mockRootDir}/abs/path/to/repo/SomeFile.txt`,
56
+ `${mockRootDir}/File.txt`,
57
+ `${mockRootDir}/AnotherClass.txt`,
58
+ `${mockRootDir}/SomeFile.txt`,
63
59
  ]));
64
60
  }));
65
61
  it('rejects and throws error when "getDefaultBranchName" fails', () => __awaiter(void 0, void 0, void 0, function* () {
66
62
  //Given
67
63
  mockGitImpl.getDefaultBranchName.mockRejectedValue(Error('no head ref error'));
68
64
  //When/Then
69
- yield expect((0, BranchChanges_1.getDefaultBranchDiffByRef)('./some/path/to/dir', 'abc12fcd')).rejects.toEqual(Error("Local branch operation failed. Cause: 'no head ref error'"));
65
+ yield expect((0, src_1.getDefaultBranchDiffByRef)('./some/path/to/dir', 'abc12fcd')).rejects.toEqual(Error("Local branch operation failed. Cause: 'no head ref error'"));
70
66
  }));
71
67
  it('rejects and throws error when "getLocalChangedAndCreated" fails', () => __awaiter(void 0, void 0, void 0, function* () {
72
68
  //Given
@@ -74,7 +70,7 @@ describe('Branch changes', () => {
74
70
  mockGitImpl.diffRange.mockResolvedValue(new Set(['File.txt', 'AnotherClass.txt']));
75
71
  mockGitImpl.getLocalChangedAndCreated.mockRejectedValue(Error('op failed'));
76
72
  //When/Then
77
- yield expect((0, BranchChanges_1.getDefaultBranchDiffByRef)('./some/path/to/dir', 'abc12fcd')).rejects.toEqual(Error("Local branch operation failed. Cause: 'Getting diff operation failed. Cause: 'op failed''"));
73
+ yield expect((0, src_1.getDefaultBranchDiffByRef)('./some/path/to/dir', 'abc12fcd')).rejects.toEqual(Error("Local branch operation failed. Cause: 'Getting diff operation failed. Cause: 'op failed''"));
78
74
  }));
79
75
  });
80
76
  describe('getDefaultBranchDiff', () => {
@@ -84,16 +80,15 @@ describe('Branch changes', () => {
84
80
  mockGitImpl.diffRange.mockResolvedValue(new Set(['File.txt', 'AnotherClass.txt']));
85
81
  mockGitImpl.getLocalChangedAndCreated.mockResolvedValue(new Set(['SomeFile.txt']));
86
82
  //When
87
- const res = yield (0, BranchChanges_1.getDefaultBranchDiff)('./some/path/to/dir');
83
+ const res = yield (0, src_1.getDefaultBranchDiff)('./some/path/to/dir');
88
84
  //Then
89
- expect(mockedGit).toHaveBeenCalledWith('./some/path/to/dir');
90
85
  expect(mockGitImpl.getDefaultBranchName).toBeCalledTimes(1);
91
86
  expect(mockGitImpl.getLocalChangedAndCreated).toBeCalledTimes(1);
92
87
  expect(mockGitImpl.diffRange).toHaveBeenCalledWith('default/branch/name', 'HEAD');
93
88
  expect(res).toEqual(new Set([
94
- `${mockRootDir}/abs/path/to/repo/File.txt`,
95
- `${mockRootDir}/abs/path/to/repo/AnotherClass.txt`,
96
- `${mockRootDir}/abs/path/to/repo/SomeFile.txt`,
89
+ `${mockRootDir}/File.txt`,
90
+ `${mockRootDir}/AnotherClass.txt`,
91
+ `${mockRootDir}/SomeFile.txt`,
97
92
  ]));
98
93
  }));
99
94
  it('rejects and throws error when "getLocalChangedAndCreated" fails', () => __awaiter(void 0, void 0, void 0, function* () {
@@ -102,7 +97,7 @@ describe('Branch changes', () => {
102
97
  mockGitImpl.diffRange.mockResolvedValue(new Set(['File.txt', 'AnotherClass.txt']));
103
98
  mockGitImpl.getLocalChangedAndCreated.mockRejectedValue(Error('op failed'));
104
99
  //When/Then
105
- yield expect((0, BranchChanges_1.getDefaultBranchDiff)('./some/path/to/dir')).rejects.toEqual(Error("Local branch operation failed. Cause: 'Getting diff operation failed. Cause: 'op failed''"));
100
+ yield expect((0, src_1.getDefaultBranchDiff)('./some/path/to/dir')).rejects.toEqual(Error("Local branch operation failed. Cause: 'Getting diff operation failed. Cause: 'op failed''"));
106
101
  }));
107
102
  });
108
103
  describe('getDiffRange', () => {
@@ -111,15 +106,14 @@ describe('Branch changes', () => {
111
106
  mockGitImpl.diffRange.mockResolvedValue(new Set(['File.txt', 'AnotherClass.txt']));
112
107
  mockGitImpl.getLocalChangedAndCreated.mockResolvedValue(new Set(['SomeFile.txt']));
113
108
  //When
114
- const res = yield (0, BranchChanges_1.getDiffRange)('./some/path/to/dir', 'ref1', 'ref2');
109
+ const res = yield (0, src_1.getDiffRange)('./some/path/to/dir', 'ref1', 'ref2');
115
110
  //Then
116
- expect(mockedGit).toHaveBeenCalledWith('./some/path/to/dir');
117
111
  expect(mockGitImpl.getLocalChangedAndCreated).toBeCalledTimes(1);
118
112
  expect(mockGitImpl.diffRange).toHaveBeenCalledWith('ref1', 'ref2');
119
113
  expect(res).toEqual(new Set([
120
- `${mockRootDir}/abs/path/to/repo/File.txt`,
121
- `${mockRootDir}/abs/path/to/repo/AnotherClass.txt`,
122
- `${mockRootDir}/abs/path/to/repo/SomeFile.txt`,
114
+ `${mockRootDir}/File.txt`,
115
+ `${mockRootDir}/AnotherClass.txt`,
116
+ `${mockRootDir}/SomeFile.txt`,
123
117
  ]));
124
118
  }));
125
119
  it('rejects and throws error when "getLocalChangedAndCreated" fails', () => __awaiter(void 0, void 0, void 0, function* () {
@@ -128,7 +122,7 @@ describe('Branch changes', () => {
128
122
  mockGitImpl.diffRange.mockResolvedValue(new Set(['File.txt', 'AnotherClass.txt']));
129
123
  mockGitImpl.getLocalChangedAndCreated.mockRejectedValue(Error('op failed'));
130
124
  //When/Then
131
- yield expect((0, BranchChanges_1.getDiffRange)('./some/path/to/dir', 'ref1', 'ref2')).rejects.toEqual(Error("Getting diff operation failed. Cause: 'op failed'"));
125
+ yield expect((0, src_1.getDiffRange)('./some/path/to/dir', 'ref1', 'ref2')).rejects.toEqual(Error("Getting diff operation failed. Cause: 'op failed'"));
132
126
  }));
133
127
  });
134
128
  describe('getLocalChanges', () => {
@@ -136,17 +130,66 @@ describe('Branch changes', () => {
136
130
  //Given
137
131
  mockGitImpl.getLocalChangedAndCreated.mockResolvedValue(new Set(['SomeFile.txt']));
138
132
  //When
139
- const res = yield (0, BranchChanges_1.getLocalChanges)('./some/path/to/dir');
133
+ const res = yield (0, src_1.getLocalChanges)('./some/path/to/dir');
140
134
  //Then
141
- expect(mockedGit).toHaveBeenCalledWith('./some/path/to/dir');
142
135
  expect(mockGitImpl.getLocalChangedAndCreated).toBeCalledTimes(1);
143
- expect(res).toEqual(new Set([`${mockRootDir}/abs/path/to/repo/SomeFile.txt`]));
136
+ expect(res).toEqual(new Set([`${mockRootDir}/SomeFile.txt`]));
144
137
  }));
145
138
  it('rejects and throws error when op fails', () => __awaiter(void 0, void 0, void 0, function* () {
146
139
  //Given
147
140
  mockGitImpl.getLocalChangedAndCreated.mockRejectedValue(Error('op failed'));
148
141
  //When/Then
149
- yield expect((0, BranchChanges_1.getLocalChanges)('./some/path/to/dir')).rejects.toEqual(Error("Getting local changes operation failed. Cause: 'op failed'"));
142
+ yield expect((0, src_1.getLocalChanges)('./some/path/to/dir')).rejects.toEqual(Error("Getting local changes operation failed. Cause: 'op failed'"));
143
+ }));
144
+ });
145
+ describe('getDeployableClasses', () => {
146
+ it('returns the correct set of files', () => __awaiter(void 0, void 0, void 0, function* () {
147
+ //Given
148
+ const pdir = `${mockRootDir}/project/dir`;
149
+ mockGitImpl.getFilteredStatus.mockImplementation(fn => {
150
+ const files = [
151
+ {
152
+ path: `${pdir}/SomeFile.cls`,
153
+ working_dir: 'M',
154
+ },
155
+ ];
156
+ return Promise.resolve(new Set(files.filter(fn).map(p => p.path)));
157
+ });
158
+ //When
159
+ const res = yield (0, src_1.getDeployableClasses)(pdir, 'orgId');
160
+ //Then
161
+ expect(mockGitImpl.getFilteredStatus).toBeCalledTimes(1);
162
+ expect(mockGitImpl.getFilteredStatus).toHaveBeenCalledWith(expect.anything(), `${pdir}/.sf/orgs/orgId/localSourceTracking`);
163
+ expect(res).toEqual(new Set([`${pdir}/SomeFile.cls`]));
164
+ }));
165
+ it('filters non classes and deleted', () => __awaiter(void 0, void 0, void 0, function* () {
166
+ //Given
167
+ const pdir = `${mockRootDir}/project/dir`;
168
+ mockGitImpl.getFilteredStatus.mockImplementation(fn => {
169
+ const files = [
170
+ {
171
+ path: `${pdir}/SomeFile.txt`,
172
+ working_dir: 'M',
173
+ },
174
+ {
175
+ path: `${pdir}/SomeFile2.cls`,
176
+ working_dir: 'D',
177
+ },
178
+ ];
179
+ return Promise.resolve(new Set(files.filter(fn).map(p => p.path)));
180
+ });
181
+ //When
182
+ const res = yield (0, src_1.getDeployableClasses)(pdir, 'orgId');
183
+ //Then
184
+ expect(mockGitImpl.getFilteredStatus).toBeCalledTimes(1);
185
+ expect(mockGitImpl.getFilteredStatus).toHaveBeenCalledWith(expect.anything(), `${pdir}/.sf/orgs/orgId/localSourceTracking`);
186
+ expect(res).toEqual(new Set());
187
+ }));
188
+ it('rejects and throws error when op fails', () => __awaiter(void 0, void 0, void 0, function* () {
189
+ //Given
190
+ mockGitImpl.getFilteredStatus.mockRejectedValue(Error('op failed'));
191
+ //When/Then
192
+ yield expect((0, src_1.getDeployableClasses)('/project/dir', 'orgId')).rejects.toEqual(Error("Getting local changes operation failed. Cause: 'op failed'"));
150
193
  }));
151
194
  });
152
195
  });
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- * Copyright (c) 2023, FinancialForce.com, inc. All rights reserved.
3
+ * Copyright (c) 2024 Certinia Inc. All rights reserved.
4
4
  */
5
5
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
6
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -16,17 +16,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
16
16
  };
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  const path_1 = __importDefault(require("path"));
19
- const Git_1 = require("../../src/Git/Git");
20
- const RepoManager_1 = require("../FsUtils/RepoManager");
19
+ const src_1 = require("../src");
20
+ const repo_1 = require("./helpers/repo");
21
21
  describe('Git', () => {
22
22
  const dir = './test/repos';
23
- const repoManager = RepoManager_1.RepoManager.getInstance(dir);
23
+ const repoHelper = repo_1.RepoHelper.getInstance(dir);
24
24
  beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
25
- yield repoManager.init();
26
- }));
27
- afterEach(() => __awaiter(void 0, void 0, void 0, function* () {
28
- yield repoManager.tearDown();
25
+ yield repoHelper.init();
29
26
  }));
27
+ afterEach(() => {
28
+ repoHelper.tearDown();
29
+ });
30
30
  describe('version check', () => {
31
31
  it('does not fail when Git version is equal to 2.20.0', () => {
32
32
  //Given/When
@@ -38,7 +38,7 @@ describe('Git', () => {
38
38
  patch: 0,
39
39
  }),
40
40
  };
41
- expect(Git_1.Git.versionCheck(mock)).resolves;
41
+ expect(src_1.Git.versionCheck(mock)).resolves;
42
42
  });
43
43
  it('does not fail when Git version is higher', () => {
44
44
  //Given/When
@@ -51,7 +51,7 @@ describe('Git', () => {
51
51
  }),
52
52
  };
53
53
  //Then
54
- expect(Git_1.Git.versionCheck(mock)).resolves;
54
+ expect(src_1.Git.versionCheck(mock)).resolves;
55
55
  });
56
56
  it('fails when Git is not installed', () => __awaiter(void 0, void 0, void 0, function* () {
57
57
  //Given/When
@@ -59,7 +59,7 @@ describe('Git', () => {
59
59
  version: jest.fn().mockReturnValue({ installed: false }),
60
60
  };
61
61
  //Then
62
- yield expect(Git_1.Git.versionCheck(mock)).rejects.toThrow(Error('"git" is not installed or available on the PATH'));
62
+ yield expect(src_1.Git.versionCheck(mock)).rejects.toThrow(Error('"git" is not installed or available on the PATH'));
63
63
  }));
64
64
  it('fails when Git major version is lower', () => __awaiter(void 0, void 0, void 0, function* () {
65
65
  //Given/When
@@ -70,7 +70,7 @@ describe('Git', () => {
70
70
  }),
71
71
  };
72
72
  //Then
73
- yield expect(Git_1.Git.versionCheck(mock)).rejects.toThrow(Error('Unsupported version of git. Min version must be 2.20'));
73
+ yield expect(src_1.Git.versionCheck(mock)).rejects.toThrow(Error('Unsupported version of git. Min version must be 2.20'));
74
74
  }));
75
75
  it('fails when Git minor version is lower', () => __awaiter(void 0, void 0, void 0, function* () {
76
76
  //Given/When
@@ -82,130 +82,126 @@ describe('Git', () => {
82
82
  }),
83
83
  };
84
84
  //Then
85
- yield expect(Git_1.Git.versionCheck(mock)).rejects.toThrow(Error('Unsupported version of git. Min version must be 2.20'));
85
+ yield expect(src_1.Git.versionCheck(mock)).rejects.toThrow(Error('Unsupported version of git. Min version must be 2.20'));
86
86
  }));
87
87
  });
88
88
  describe('rev parse', () => {
89
89
  it('get git root', () => __awaiter(void 0, void 0, void 0, function* () {
90
- const repoDirPath = path_1.default.resolve(repoManager.repoDir);
91
- const revParse = yield new Git_1.Git(repoManager.repoDir).gitRoot();
90
+ const repoDirPath = path_1.default.resolve(repoHelper.repoDir);
91
+ const revParse = yield new src_1.Git(repoHelper.repoDir).gitRoot();
92
92
  expect(revParse).toBe(repoDirPath);
93
93
  }));
94
94
  });
95
95
  describe('branch operation', () => {
96
96
  it('fails to find default branch name when head is not set', () => __awaiter(void 0, void 0, void 0, function* () {
97
97
  //Given/When/Then
98
- yield expect(new Git_1.Git(repoManager.repoDir).getDefaultBranchName()).rejects.toThrow(Error("Failed to find symbolic ref no remote HEAD with message: 'fatal: ref refs/remotes/origin/HEAD is not a symbolic ref'"));
98
+ yield expect(new src_1.Git(repoHelper.repoDir).getDefaultBranchName()).rejects.toThrow(Error("Failed to find symbolic ref no remote HEAD with message: 'fatal: ref refs/remotes/origin/HEAD is not a symbolic ref'"));
99
99
  }));
100
100
  it('find default branch name when head is set', () => __awaiter(void 0, void 0, void 0, function* () {
101
101
  //Given
102
- yield repoManager
103
- .createOrUpdateFile('file.txt', 'Test Text')
104
- .then(() => repoManager.stageAndCommitAll(['file.txt']))
105
- .then(() => repoManager.push())
106
- .then(() => repoManager.setHead());
102
+ repoHelper.createOrUpdateFile('file.txt', 'Test Text');
103
+ yield repoHelper
104
+ .stageAndCommitAll(['file.txt'])
105
+ .then(() => repoHelper.push())
106
+ .then(() => repoHelper.setHead());
107
107
  //When
108
- const branchName = yield new Git_1.Git(repoManager.repoDir).getDefaultBranchName();
108
+ const branchName = yield new src_1.Git(repoHelper.repoDir).getDefaultBranchName();
109
109
  //Then
110
110
  expect(branchName).toBe('origin/main');
111
111
  }));
112
112
  it('find default branch name when head is set', () => __awaiter(void 0, void 0, void 0, function* () {
113
113
  //Given
114
- yield repoManager
115
- .createOrUpdateFile('file.txt', 'Test Text')
116
- .then(() => repoManager.stageAndCommitAll(['file.txt']))
117
- .then(() => repoManager.push())
118
- .then(() => repoManager.setHead());
114
+ repoHelper.createOrUpdateFile('file.txt', 'Test Text');
115
+ yield repoHelper
116
+ .stageAndCommitAll(['file.txt'])
117
+ .then(() => repoHelper.push())
118
+ .then(() => repoHelper.setHead());
119
119
  //When
120
- const branchName = yield new Git_1.Git(repoManager.repoDir).getDefaultBranchName();
120
+ const branchName = yield new src_1.Git(repoHelper.repoDir).getDefaultBranchName();
121
121
  //Then
122
122
  expect(branchName).toBe('origin/main');
123
123
  }));
124
124
  });
125
125
  describe('file change operations', () => {
126
126
  beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
127
- yield repoManager
128
- .createOrUpdateFile('file.txt', 'text')
129
- .then(() => repoManager.stageAndCommitAll(['file.txt']))
130
- .then(() => repoManager.push())
131
- .then(() => repoManager.setHead());
127
+ repoHelper.createOrUpdateFile('file.txt', 'text');
128
+ yield repoHelper
129
+ .stageAndCommitAll(['file.txt'])
130
+ .then(() => repoHelper.push())
131
+ .then(() => repoHelper.setHead());
132
132
  }));
133
133
  describe('local changes', () => {
134
134
  it('finds modified files', () => __awaiter(void 0, void 0, void 0, function* () {
135
135
  //Given
136
- yield repoManager.createOrUpdateFile('file.txt', 'modify');
136
+ repoHelper.createOrUpdateFile('file.txt', 'modify');
137
137
  //When
138
- const files = yield new Git_1.Git(repoManager.repoDir).getLocalChangedAndCreated();
138
+ const files = yield new src_1.Git(repoHelper.repoDir).getLocalChangedAndCreated();
139
139
  //Then
140
140
  expect(files).toEqual(new Set(['file.txt']));
141
141
  }));
142
142
  it('finds unstaged renamed files', () => __awaiter(void 0, void 0, void 0, function* () {
143
143
  //Given
144
- repoManager.renameFileInRepo('file.txt', 'renamed.txt');
145
- // await repoManager.gitStage();
144
+ repoHelper.renameFileInRepo('file.txt', 'renamed.txt');
145
+ // await repoHelper.gitStage();
146
146
  //When
147
- const files = yield new Git_1.Git(repoManager.repoDir).getLocalChangedAndCreated();
147
+ const files = yield new src_1.Git(repoHelper.repoDir).getLocalChangedAndCreated();
148
148
  //Then
149
149
  expect(files).toEqual(new Set(['renamed.txt']));
150
150
  }));
151
151
  it('finds unstaged new files', () => __awaiter(void 0, void 0, void 0, function* () {
152
152
  //Given
153
- yield repoManager.createOrUpdateFile('newFile.txt', 'content');
153
+ repoHelper.createOrUpdateFile('newFile.txt', 'content');
154
154
  //When
155
- const files = yield new Git_1.Git(repoManager.repoDir).getLocalChangedAndCreated();
155
+ const files = yield new src_1.Git(repoHelper.repoDir).getLocalChangedAndCreated();
156
156
  //Then
157
157
  expect(files).toEqual(new Set(['newFile.txt']));
158
158
  }));
159
159
  it('does not include deleted files', () => __awaiter(void 0, void 0, void 0, function* () {
160
160
  //Given
161
- repoManager.rmFile('file.txt');
161
+ repoHelper.rmFile('file.txt');
162
162
  //When
163
- const files = yield new Git_1.Git(repoManager.repoDir).getLocalChangedAndCreated();
163
+ const files = yield new src_1.Git(repoHelper.repoDir).getLocalChangedAndCreated();
164
164
  //Then
165
165
  expect(files).toEqual(new Set());
166
166
  }));
167
167
  it('finds staged renamed, modified and new files ', () => __awaiter(void 0, void 0, void 0, function* () {
168
168
  //Setup for renamed file
169
- yield repoManager
170
- .createOrUpdateFile('second.txt', 'txt')
171
- .then(() => repoManager.stageAndCommitAll(['second.txt']));
169
+ repoHelper.createOrUpdateFile('second.txt', 'txt');
170
+ yield repoHelper.stageAndCommitAll(['second.txt']);
172
171
  //Given
173
- yield repoManager
174
- .createOrUpdateFile('file.txt', 'modifiy')
175
- .then(() => repoManager.renameFileInRepo('second.txt', 'renamed.txt'))
176
- .then(() => repoManager.createOrUpdateFile('newFile.txt', 'content'))
177
- .then(() => repoManager.stageAll());
172
+ repoHelper.createOrUpdateFile('file.txt', 'modifiy');
173
+ repoHelper.renameFileInRepo('second.txt', 'renamed.txt');
174
+ repoHelper.createOrUpdateFile('newFile.txt', 'content');
175
+ yield repoHelper.stageAll();
178
176
  //When
179
- const files = yield new Git_1.Git(repoManager.repoDir).getLocalChangedAndCreated();
177
+ const files = yield new src_1.Git(repoHelper.repoDir).getLocalChangedAndCreated();
180
178
  //Then
181
179
  expect(files).toEqual(new Set(['file.txt', 'renamed.txt', 'newFile.txt']));
182
180
  }));
183
181
  });
184
182
  describe('branch diff changes', () => {
185
183
  beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
186
- yield repoManager
184
+ yield repoHelper
187
185
  .checkout('dev', 'main')
188
- .then(() => repoManager.createOrUpdateFile('newFile.txt', 'text'))
189
- .then(() => repoManager.stageAndCommitAll(['newFile.txt']));
186
+ .then(() => repoHelper.createOrUpdateFile('newFile.txt', 'text'))
187
+ .then(() => repoHelper.stageAndCommitAll(['newFile.txt']));
190
188
  }));
191
189
  it('finds diff against for default branch and HEAD', () => __awaiter(void 0, void 0, void 0, function* () {
192
190
  //Given
193
- yield repoManager
194
- .createOrUpdateFile('anotherFileForCommit.txt', 'text')
195
- .then(() => repoManager.stageAndCommitAll(['anotherFileForCommit.txt']));
191
+ repoHelper.createOrUpdateFile('anotherFileForCommit.txt', 'text');
192
+ yield repoHelper.stageAndCommitAll(['anotherFileForCommit.txt']);
196
193
  //When
197
- const files = yield new Git_1.Git(repoManager.repoDir).diffRange('origin/main', 'HEAD');
194
+ const files = yield new src_1.Git(repoHelper.repoDir).diffRange('origin/main', 'HEAD');
198
195
  //Then
199
196
  expect(files).toEqual(new Set(['newFile.txt', 'anotherFileForCommit.txt']));
200
197
  }));
201
198
  it('finds diff against default branch and commit ref', () => __awaiter(void 0, void 0, void 0, function* () {
202
199
  //Given
203
- const currentRef = (yield repoManager.getGitLog())[0].hash;
204
- yield repoManager
205
- .createOrUpdateFile('anotherFileForCommit.txt', 'text')
206
- .then(() => repoManager.stageAndCommitAll(['anotherFileForCommit.txt']));
200
+ const currentRef = (yield repoHelper.getGitLog())[0].hash;
201
+ repoHelper.createOrUpdateFile('anotherFileForCommit.txt', 'text');
202
+ yield repoHelper.stageAndCommitAll(['anotherFileForCommit.txt']);
207
203
  //When
208
- const files = yield new Git_1.Git(repoManager.repoDir).diffRange('origin/main', currentRef);
204
+ const files = yield new src_1.Git(repoHelper.repoDir).diffRange('origin/main', currentRef);
209
205
  //Then
210
206
  expect(files).toEqual(new Set(['newFile.txt']));
211
207
  }));
@@ -1,11 +1,11 @@
1
- export declare class RepoManager {
1
+ export declare class RepoHelper {
2
2
  private isInit;
3
3
  private rootDir;
4
4
  private remoteRepoDir;
5
5
  private testRepoDir;
6
6
  private static instances;
7
7
  private constructor();
8
- static getInstance(rootDir: string): RepoManager;
8
+ static getInstance(rootDir: string): RepoHelper;
9
9
  private get git();
10
10
  private initRemoteRepo;
11
11
  private cloneRepo;
@@ -17,8 +17,8 @@ export declare class RepoManager {
17
17
  stageAll(files?: string[]): Promise<string>;
18
18
  getGitLog(): Promise<readonly (import("simple-git").DefaultLogFields & import("simple-git").ListLogLine)[]>;
19
19
  stageAndCommitAll(files?: string[]): Promise<import("simple-git").CommitResult>;
20
- tearDown(): Promise<void>;
21
- createOrUpdateFile(fileName: string, content: string): Promise<void>;
20
+ tearDown(): void;
21
+ createOrUpdateFile(fileName: string, content: string): void;
22
22
  rmFile(file: string): void;
23
23
  renameFileInRepo(from: string, to: string): void;
24
24
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- * Copyright (c) 2023, FinancialForce.com, inc. All rights reserved.
3
+ * Copyright (c) 2024 Certinia Inc. All rights reserved.
4
4
  */
5
5
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
6
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -15,11 +15,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
15
15
  return (mod && mod.__esModule) ? mod : { "default": mod };
16
16
  };
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.RepoManager = void 0;
18
+ exports.RepoHelper = void 0;
19
19
  const simple_git_1 = __importDefault(require("simple-git"));
20
20
  const fs_1 = __importDefault(require("fs"));
21
21
  const path_1 = __importDefault(require("path"));
22
- class RepoManager {
22
+ class RepoHelper {
23
23
  constructor(rootDir) {
24
24
  this.isInit = false;
25
25
  this.rootDir = rootDir;
@@ -27,10 +27,12 @@ class RepoManager {
27
27
  this.testRepoDir = rootDir + '/test-repo';
28
28
  }
29
29
  static getInstance(rootDir) {
30
- if (!this.instances.has(rootDir)) {
31
- this.instances.set(rootDir, new RepoManager(rootDir));
30
+ let mng = this.instances.get(rootDir);
31
+ if (!mng) {
32
+ mng = new RepoHelper(rootDir);
33
+ this.instances.set(rootDir, mng);
32
34
  }
33
- return this.instances.get(rootDir);
35
+ return mng;
34
36
  }
35
37
  get git() {
36
38
  if (!this.isInit) {
@@ -105,20 +107,16 @@ class RepoManager {
105
107
  });
106
108
  }
107
109
  tearDown() {
108
- return __awaiter(this, void 0, void 0, function* () {
109
- yield fs_1.default.promises.rm(this.rootDir, { recursive: true, force: true });
110
- });
110
+ fs_1.default.rmSync(this.rootDir, { recursive: true, force: true });
111
111
  }
112
112
  createOrUpdateFile(fileName, content) {
113
- return __awaiter(this, void 0, void 0, function* () {
114
- const fPath = path_1.default.join(this.testRepoDir, fileName);
115
- if (fs_1.default.existsSync(fPath)) {
116
- yield fs_1.default.promises.appendFile(fPath, content);
117
- }
118
- else {
119
- yield fs_1.default.promises.writeFile(fPath, content);
120
- }
121
- });
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
+ }
122
120
  }
123
121
  rmFile(file) {
124
122
  fs_1.default.unlinkSync(path_1.default.join(this.testRepoDir, file));
@@ -129,5 +127,5 @@ class RepoManager {
129
127
  fs_1.default.renameSync(fromPath, toPath);
130
128
  }
131
129
  }
132
- exports.RepoManager = RepoManager;
133
- RepoManager.instances = new Map();
130
+ exports.RepoHelper = RepoHelper;
131
+ RepoHelper.instances = new Map();
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- * Copyright (c) 2023 Certinia Inc. All rights reserved.
3
+ * Copyright (c) 2024 Certinia Inc. All rights reserved.
4
4
  */
5
5
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
6
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -12,7 +12,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
12
12
  });
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const src_1 = require("../../src");
15
+ const src_1 = require("../src");
16
16
  const core_1 = require("@salesforce/core");
17
17
  const mockGetStatusData = [
18
18
  {
@@ -105,7 +105,7 @@ const mockDeploy = {
105
105
  .fn()
106
106
  .mockImplementation(() => Promise.resolve(mockDeployResult)),
107
107
  };
108
- const mockDeployResult = { done: true };
108
+ const mockDeployResult = { response: { success: true } };
109
109
  const mockComponentSet = {
110
110
  deploy: jest
111
111
  .fn()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apexdevtools/git-ops",
3
- "version": "1.3.0",
3
+ "version": "1.4.1",
4
4
  "description": "Library to do git operations to find changed files in a given git repository",
5
5
  "author": {
6
6
  "name": "Apex Dev Tools Team",
@@ -25,7 +25,7 @@
25
25
  "url": "https://github.com/apex-dev-tools/git-ops/issues"
26
26
  },
27
27
  "homepage": "https://github.com/apex-dev-tools/git-ops#readme",
28
- "packageManager": "pnpm@8.2.0",
28
+ "packageManager": "pnpm@8.9.2",
29
29
  "dependencies": {
30
30
  "@salesforce/core": "^4.3.11",
31
31
  "@salesforce/source-deploy-retrieve": "^9.2.8",
@@ -1,6 +0,0 @@
1
- export interface IGit {
2
- getDefaultBranchName(): Promise<string>;
3
- getLocalChangedAndCreated(): Promise<Set<string>>;
4
- diffRange(fromRef: string, toRef: string): Promise<Set<string>>;
5
- gitRoot(): Promise<string>;
6
- }
@@ -1,5 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2023, FinancialForce.com, inc. All rights reserved.
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +0,0 @@
1
- export interface Logger {
2
- logError(error: any): void;
3
- logMessage(message: any): void;
4
- logDeployProgress(status: string): void;
5
- }
@@ -1,5 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2023 Certinia Inc. All rights reserved.
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
File without changes