Skip to content

Commit b8efb7b

Browse files
committed
RM-35685: Fixed circular imports of calling config in tics-cli and tics-cli in config
1 parent 52047dd commit b8efb7b

4 files changed

Lines changed: 36 additions & 27 deletions

File tree

dist/index.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ const github_1 = __nccwpck_require__(54406);
10391039
exports.actionConfig = new action_1.ActionConfiguration();
10401040
exports.githubConfig = new github_1.GithubConfig();
10411041
exports.ticsConfig = new tics_1.TicsConfiguration();
1042-
exports.ticsCli = new tics_cli_1.TicsCli(exports.ticsConfig.mode);
1042+
exports.ticsCli = new tics_cli_1.TicsCli(exports.ticsConfig.mode, exports.githubConfig.reponame);
10431043

10441044

10451045
/***/ }),
@@ -1194,7 +1194,6 @@ exports.CliOptions = exports.TicsCli = void 0;
11941194
const core_1 = __nccwpck_require__(37484);
11951195
const tics_1 = __nccwpck_require__(5232);
11961196
const logger_1 = __nccwpck_require__(66113);
1197-
const config_1 = __nccwpck_require__(34151);
11981197
class TicsCli {
11991198
project;
12001199
branchname;
@@ -1207,8 +1206,8 @@ class TicsCli {
12071206
recalc;
12081207
tmpdir;
12091208
additionalFlags;
1210-
constructor(mode) {
1211-
this.project = this.getProject((0, core_1.getInput)('project'), mode);
1209+
constructor(mode, repoName) {
1210+
this.project = this.getProject((0, core_1.getInput)('project'), mode, repoName);
12121211
this.branchname = (0, core_1.getInput)('branchname');
12131212
this.branchdir = (0, core_1.getInput)('branchdir');
12141213
this.cdtoken = (0, core_1.getInput)('cdtoken');
@@ -1228,12 +1227,12 @@ class TicsCli {
12281227
this.branchdir = process.env.GITHUB_WORKSPACE;
12291228
}
12301229
}
1231-
getProject(input, mode) {
1230+
getProject(input, mode, repoName) {
12321231
// validate project
12331232
if (mode === tics_1.Mode.QSERVER) {
12341233
if (input === 'auto') {
1235-
logger_1.logger.info(`Parameter 'project' is not set, using the repository name (${config_1.githubConfig.reponame}) instead.`);
1236-
return config_1.githubConfig.reponame;
1234+
logger_1.logger.info(`Parameter 'project' is not set, using the repository name (${repoName}) instead.`);
1235+
return repoName;
12371236
}
12381237
}
12391238
return input;

src/configuration/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ export const actionConfig = new ActionConfiguration();
77
export const githubConfig = new GithubConfig();
88

99
export const ticsConfig = new TicsConfiguration();
10-
export const ticsCli = new TicsCli(ticsConfig.mode);
10+
export const ticsCli = new TicsCli(ticsConfig.mode, githubConfig.reponame);

src/configuration/tics-cli.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { getInput } from '@actions/core';
33
import { CliOption } from './interfaces';
44
import { Mode } from './tics';
55
import { logger } from '../helper/logger';
6-
import { githubConfig } from './config';
76

87
export class TicsCli {
98
readonly project: string;
@@ -18,8 +17,8 @@ export class TicsCli {
1817
readonly tmpdir: string;
1918
readonly additionalFlags: string;
2019

21-
constructor(mode: Mode) {
22-
this.project = this.getProject(getInput('project'), mode);
20+
constructor(mode: Mode, repoName: string) {
21+
this.project = this.getProject(getInput('project'), mode, repoName);
2322
this.branchname = getInput('branchname');
2423
this.branchdir = getInput('branchdir');
2524
this.cdtoken = getInput('cdtoken');
@@ -42,12 +41,12 @@ export class TicsCli {
4241
}
4342
}
4443

45-
private getProject(input: string, mode: Mode): string {
44+
private getProject(input: string, mode: Mode, repoName: string): string {
4645
// validate project
4746
if (mode === Mode.QSERVER) {
4847
if (input === 'auto') {
49-
logger.info(`Parameter 'project' is not set, using the repository name (${githubConfig.reponame}) instead.`);
50-
return githubConfig.reponame;
48+
logger.info(`Parameter 'project' is not set, using the repository name (${repoName}) instead.`);
49+
return repoName;
5150
}
5251
}
5352
return input;

test/unit/configuration/tics-cli.test.ts

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ describe('cli Configuration', () => {
4646
project: 'auto'
4747
};
4848

49-
const cliClient = new TicsCli(Mode.CLIENT);
50-
const cliDiagnostic = new TicsCli(Mode.DIAGNOSTIC);
49+
const cliClient = new TicsCli(Mode.CLIENT, 'repoName');
50+
const cliDiagnostic = new TicsCli(Mode.DIAGNOSTIC, 'repoName');
5151

5252
expect(cliClient).toMatchObject({ ...expectCli, project: 'auto', calc: 'GATE' });
5353
expect(cliDiagnostic).toMatchObject({ ...expectCli, project: 'auto' });
@@ -58,8 +58,8 @@ describe('cli Configuration', () => {
5858
project: 'project'
5959
};
6060

61-
const cliClient = new TicsCli(Mode.CLIENT);
62-
const cliDiagnostic = new TicsCli(Mode.DIAGNOSTIC);
61+
const cliClient = new TicsCli(Mode.CLIENT, 'repoName');
62+
const cliDiagnostic = new TicsCli(Mode.DIAGNOSTIC, 'repoName');
6363

6464
expect(cliClient).toMatchObject({ ...expectCli, project: 'project', calc: 'GATE' });
6565
expect(cliDiagnostic).toMatchObject({ ...expectCli, project: 'project' });
@@ -71,21 +71,32 @@ describe('cli Configuration', () => {
7171
branchdir: 'dir'
7272
};
7373

74-
const cliServer = new TicsCli(Mode.QSERVER);
74+
const cliServer = new TicsCli(Mode.QSERVER, 'repoName');
7575

7676
expect(cliServer).toMatchObject({ ...expectCli, branchdir: 'dir', project: 'project' });
7777
});
7878

79-
it('should throw error if mode is qserver, project is auto and GITHUB_WORKSPACE is not available', () => {
79+
it('should use repository name when mode is qserver and project is auto', () => {
8080
values = {
81-
project: 'auto'
81+
project: 'auto',
82+
branchdir: 'dir'
8283
};
8384

85+
const cliServer = new TicsCli(Mode.QSERVER, 'repoName');
86+
87+
expect(cliServer).toMatchObject({ ...expectCli, branchdir: 'dir', project: 'repoName' });
88+
});
89+
90+
it('should throw error if mode is qserver, branchdir is not given and GITHUB_WORKSPACE is not available', () => {
8491
const GITHUB_WORKSPACE = process.env.GITHUB_WORKSPACE;
8592
delete process.env.GITHUB_WORKSPACE;
93+
values = {
94+
branchdir: ''
95+
};
96+
8697
let error: any;
8798
try {
88-
new TicsCli(Mode.QSERVER);
99+
new TicsCli(Mode.QSERVER, 'repoName');
89100
} catch (err) {
90101
error = err;
91102
}
@@ -100,7 +111,7 @@ describe('cli Configuration', () => {
100111
project: 'project'
101112
};
102113
process.env.GITHUB_WORKSPACE = '/workspace/project';
103-
const cliServer = new TicsCli(Mode.QSERVER);
114+
const cliServer = new TicsCli(Mode.QSERVER, 'repoName');
104115

105116
expect(cliServer).toMatchObject({ project: 'project', branchdir: '/workspace/project' });
106117
});
@@ -113,7 +124,7 @@ describe('cli Configuration', () => {
113124

114125
let error: any;
115126
try {
116-
new TicsCli(Mode.QSERVER);
127+
new TicsCli(Mode.QSERVER, 'repoName');
117128
} catch (err) {
118129
error = err;
119130
}
@@ -137,7 +148,7 @@ describe('cli Configuration', () => {
137148
additionalFlags: '-log 9'
138149
};
139150

140-
const cliServer = new TicsCli(Mode.QSERVER);
151+
const cliServer = new TicsCli(Mode.QSERVER, 'repoName');
141152

142153
expect(cliServer).toMatchObject({
143154
project: 'project',
@@ -173,7 +184,7 @@ describe('cli Configuration', () => {
173184
additionalFlags: '-log 9'
174185
};
175186

176-
const cliClient = new TicsCli(Mode.CLIENT);
187+
const cliClient = new TicsCli(Mode.CLIENT, 'repoName');
177188

178189
expect(cliClient).toMatchObject({
179190
project: 'project',
@@ -208,7 +219,7 @@ describe('cli Configuration', () => {
208219
additionalFlags: '-log 9'
209220
};
210221

211-
const cliDiagnostic = new TicsCli(Mode.DIAGNOSTIC);
222+
const cliDiagnostic = new TicsCli(Mode.DIAGNOSTIC, 'repoName');
212223

213224
expect(cliDiagnostic).toMatchObject({
214225
project: 'project',

0 commit comments

Comments
 (0)