Skip to content

Commit 373420f

Browse files
add option for git info
1 parent 135757e commit 373420f

File tree

6 files changed

+29
-7
lines changed

6 files changed

+29
-7
lines changed

src/commander/mergeBranch.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import auth from '../tasks/auth.js';
55
import ctxInit from '../lib/ctx.js';
66
import fetchBranchInfo from '../tasks/fetchBranchInfo.js'
77
import mergeBuilds from '../tasks/mergeBuilds.js'
8+
import getGitInfo from '../tasks/getGitInfo.js'
89

910
const command = new Command();
1011

@@ -34,6 +35,7 @@ command
3435
let tasks = new Listr<Context>(
3536
[
3637
auth(ctx),
38+
getGitInfo(ctx),
3739
fetchBranchInfo(ctx),
3840
mergeBuilds(ctx),
3941
],

src/commander/mergeBuild.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import auth from '../tasks/auth.js';
55
import ctxInit from '../lib/ctx.js';
66
import fetchBuildInfo from '../tasks/fetchBuildInfo.js'
77
import mergeBuilds from '../tasks/mergeBuilds.js'
8+
import getGitInfo from '../tasks/getGitInfo.js'
89

910
const command = new Command();
1011

@@ -34,6 +35,7 @@ command
3435
let tasks = new Listr<Context>(
3536
[
3637
auth(ctx),
38+
getGitInfo(ctx),
3739
fetchBuildInfo(ctx),
3840
mergeBuilds(ctx),
3941
],

src/lib/httpClient.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,10 @@ export default class httpClient {
581581
}, ctx.log)
582582
}
583583

584-
mergeBuildsByBuildId(source: string, target: string, byBranch: boolean, byBuildName: boolean, sourceBranchName: string, targetBranchName: string, sourceBuildName: string, targetBuildName: string, ctx: Context) {
584+
mergeBuildsByBuildId(source: string, target: string, byBranch: boolean, byBuildName: boolean, sourceBranchName: string, targetBranchName: string, sourceBuildName: string, targetBuildName: string, git: Git, ctx: Context) {
585+
if (byBranch) {
586+
git.branch = targetBranchName
587+
}
585588
return this.request({
586589
url: `/mergeBuilds`,
587590
method: 'POST',
@@ -593,7 +596,8 @@ export default class httpClient {
593596
sourceBranchName,
594597
targetBranchName,
595598
sourceBuildName,
596-
targetBuildName
599+
targetBuildName,
600+
git
597601
}
598602
}, ctx.log)
599603
}

src/tasks/fetchBranchInfo.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ export default (ctx: Context): ListrTask<Context, ListrRendererFactory, ListrRen
1010
updateLogContext({task: 'fetchBranchInfo'});
1111

1212
try {
13+
if (ctx.mergeBranchSource === ctx.mergeBranchTarget) {
14+
ctx.log.error(`Merging two similar branch is not possible`)
15+
throw new Error(`Merging two similar branch is not possible`);
16+
}
1317
let resp = await ctx.client.fetchBranchInfo(ctx.mergeBranchSource, ctx.mergeBranchTarget, ctx);
1418
if (resp && resp.data && resp.data.source && resp.data.target) {
1519
ctx.mergeBuildSourceId = resp.data.source

src/tasks/fetchBuildInfo.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ export default (ctx: Context): ListrTask<Context, ListrRendererFactory, ListrRen
1111
updateLogContext({task: 'fetchBuildInfo'});
1212

1313
try {
14+
if (ctx.mergeBuildSource === ctx.mergeBuildTarget) {
15+
ctx.log.error(`Merging two similar build is not possible`)
16+
throw new Error(`Merging two similar build is not possible`);
17+
}
1418
let resp = await ctx.client.fetchBuildInfo(ctx.mergeBuildSource, ctx.mergeBuildTarget, ctx);
1519
if (resp && resp.data && resp.data.source && resp.data.target) {
1620
ctx.mergeBuildSourceId = resp.data.source

src/tasks/mergeBuilds.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,22 @@ export default (ctx: Context): ListrTask<Context, ListrRendererFactory, ListrRen
1212
try {
1313
let resp
1414
if (ctx.mergeByBranch) {
15-
resp = await ctx.client.mergeBuildsByBuildId(ctx.mergeBuildSourceId, ctx.mergeBuildTargetId, ctx.mergeByBranch, ctx.mergeByBuild, ctx.mergeBranchSource, ctx.mergeBranchTarget, '', '', ctx);
15+
resp = await ctx.client.mergeBuildsByBuildId(ctx.mergeBuildSourceId, ctx.mergeBuildTargetId, ctx.mergeByBranch, ctx.mergeByBuild, ctx.mergeBranchSource, ctx.mergeBranchTarget, '', '', ctx.git, ctx);
1616
} else {
17-
resp = await ctx.client.mergeBuildsByBuildId(ctx.mergeBuildSourceId, ctx.mergeBuildTargetId, ctx.mergeByBranch, ctx.mergeByBuild, '', '', ctx.mergeBuildSource, ctx.mergeBuildTarget, ctx);
17+
resp = await ctx.client.mergeBuildsByBuildId(ctx.mergeBuildSourceId, ctx.mergeBuildTargetId, ctx.mergeByBranch, ctx.mergeByBuild, '', '', ctx.mergeBuildSource, ctx.mergeBuildTarget, ctx.git, ctx);
1818
}
19-
20-
task.title = 'Merging smartui branch initiated';
19+
if (resp && resp.data && resp.data.message) {
20+
ctx.log.debug(`${resp.data.message}`)
21+
} else {
22+
ctx.log.error(`Error while initiating merging process: ${resp.error.message}`)
23+
throw new Error(`Error while initiating merging process: ${resp.error.message}`);
24+
}
25+
task.title = 'Merging SmartUI builds initiated';
26+
task.output = chalk.gray(`${resp.data.message}`);
2127
} catch (error: any) {
2228
ctx.log.debug(error);
2329
task.output = chalk.gray(error.message);
24-
throw new Error('Merging smartui branch failed');
30+
throw new Error('Merging SmartUI build failed');
2531
}
2632
},
2733
rendererOptions: { persistentOutput: true }

0 commit comments

Comments
 (0)