Skip to content

Commit 5642178

Browse files
committed
fix: issue with optional types
1 parent 8cca7ea commit 5642178

File tree

11 files changed

+18
-30
lines changed

11 files changed

+18
-30
lines changed

client/src/app/components/deployment-selection/deployment-selection.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export class DeploymentSelectionComponent {
2121
queryClient = inject(QueryClient);
2222

2323
sourceRef = input.required<string>();
24+
commitSha = input.required<string>();
2425

2526
private currentEnvironmentId: number | null = null;
2627

@@ -40,6 +41,6 @@ export class DeploymentSelectionComponent {
4041

4142
handleDeploy = (environment: EnvironmentDto) => {
4243
this.currentEnvironmentId = environment.id;
43-
this.deployEnvironment.mutate({ body: { environmentId: environment.id, branchName: this.sourceRef() } });
44+
this.deployEnvironment.mutate({ body: { environmentId: environment.id, branchName: this.sourceRef(), commitSha: this.commitSha() } });
4445
};
4546
}

client/src/app/components/release-candidate-deployment-table/release-candidate-deployment-table.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class ReleaseCandidateDeploymentTableComponent {
6161
{
6262
body: {
6363
environmentId: environment.id,
64-
branchName: this.releaseCandidate().branch.name,
64+
branchName: this.releaseCandidate().branch?.name,
6565
commitSha: this.releaseCandidate().commit.sha,
6666
},
6767
},

client/src/app/core/modules/openapi/schemas.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ export const DeployRequestSchema = {
381381
type: 'string',
382382
},
383383
},
384-
required: ['branchName', 'environmentId'],
384+
required: ['commitSha', 'environmentId'],
385385
} as const;
386386

387387
export const WorkflowRunDtoSchema = {

client/src/app/core/modules/openapi/types.gen.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ export type ReleaseInfoListDto = {
122122

123123
export type DeployRequest = {
124124
environmentId: number;
125-
branchName: string;
126-
commitSha?: string;
125+
branchName?: string;
126+
commitSha: string;
127127
};
128128

129129
export type WorkflowRunDto = {

client/src/app/pages/branch-details/branch-details.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ <h2 class="text-2xl" [innerHTML]="commit()?.message | markdown"></h2>
3131
<div class="flex flex-col gap-6 max-w-6xl mr-4">
3232
<app-pipeline [selector]="pipelineSelector()" />
3333
@if (query.data(); as branch) {
34-
<app-deployment-selection [sourceRef]="branch.name" />
34+
<app-deployment-selection [sourceRef]="branch.name" [commitSha]="branch.commitSha" />
3535
}
3636
</div>
3737

client/src/app/pages/pull-request-details/pull-request-details.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ <h2 class="text-2xl">
4646
<app-pipeline [selector]="pipelineSelector()" />
4747
@if (query.data(); as pr) {
4848
@if (pr.headRefRepoNameWithOwner === pr.repository?.nameWithOwner) {
49-
<app-deployment-selection [sourceRef]="pr.headRefName" />
49+
<app-deployment-selection [sourceRef]="pr.headRefName" [commitSha]="pr.headSha" />
5050
}
5151
}
5252
</div>

client/src/app/pages/release-candidate-details/release-candidate-details.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ <h2 class="text-2xl flex items-center gap-2">
3232
<div class="flex gap-1 items-center text-sm">
3333
<div>created by</div>
3434
@if (releaseCandidate.createdBy?.avatarUrl) {
35-
<p-avatar class="size-4" shape="circle" [image]="releaseCandidate.createdBy.avatarUrl" />
35+
<p-avatar class="size-4" shape="circle" [image]="releaseCandidate.createdBy?.avatarUrl" />
3636
} @else {
3737
<i-tabler name="user" class="size-4 text-gray-600 border-2 rounded-full" />
3838
}

server/application-server/openapi.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1354,7 +1354,7 @@ components:
13541354
commitSha:
13551355
type: string
13561356
required:
1357-
- branchName
1357+
- commitSha
13581358
- environmentId
13591359
WorkflowRunDto:
13601360
type: object

server/application-server/src/main/java/de/tum/cit/aet/helios/deployment/DeployRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
import org.springframework.lang.NonNull;
44

55
public record DeployRequest(
6-
@NonNull Long environmentId, @NonNull String branchName, String commitSha) {}
6+
@NonNull Long environmentId, String branchName, @NonNull String commitSha) {}

server/application-server/src/main/java/de/tum/cit/aet/helios/deployment/DeploymentService.java

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ public void deployToEnvironment(DeployRequest deployRequest) {
7171
validateDeployRequest(deployRequest);
7272
validateEnvironmentAndPermissions(deployRequest.environmentId());
7373

74-
String commitSha = determineCommitSha(deployRequest);
75-
7674
Environment environment = lockEnvironment(deployRequest.environmentId());
7775
Workflow deploymentWorkflow = environment.getDeploymentWorkflow();
7876

@@ -83,19 +81,21 @@ public void deployToEnvironment(DeployRequest deployRequest) {
8381
// Set the PR associated with the deployment
8482
Optional<PullRequest> optionalPullRequest =
8583
pullRequestRepository.findOpenPrByBranchNameOrSha(
86-
RepositoryContext.getRepositoryId(), deployRequest.branchName(), commitSha);
84+
RepositoryContext.getRepositoryId(),
85+
deployRequest.branchName(),
86+
deployRequest.commitSha());
8787

8888
HeliosDeployment heliosDeployment =
89-
createHeliosDeployment(environment, deployRequest, commitSha, optionalPullRequest);
89+
createHeliosDeployment(environment, deployRequest, optionalPullRequest);
9090
Map<String, Object> workflowParams = createWorkflowParams(deployRequest, environment);
9191

9292
dispatchWorkflow(
9393
environment, deploymentWorkflow, deployRequest, workflowParams, heliosDeployment);
9494
}
9595

9696
private void validateDeployRequest(DeployRequest deployRequest) {
97-
if (deployRequest.environmentId() == null || deployRequest.branchName() == null) {
98-
throw new DeploymentException("Environment ID and branch name must not be null");
97+
if (deployRequest.environmentId() == null || deployRequest.commitSha() == null) {
98+
throw new DeploymentException("Environment ID and commit sha must not be null");
9999
}
100100
}
101101

@@ -110,18 +110,6 @@ private void validateEnvironmentAndPermissions(Long environmentId) {
110110
}
111111
}
112112

113-
private String determineCommitSha(DeployRequest deployRequest) {
114-
String commitSha = deployRequest.commitSha();
115-
116-
return commitSha != null
117-
? commitSha
118-
: this.branchService
119-
.getBranchByRepositoryIdAndName(
120-
RepositoryContext.getRepositoryId(), deployRequest.branchName())
121-
.orElseThrow(() -> new DeploymentException("Branch not found"))
122-
.commitSha();
123-
}
124-
125113
private Environment lockEnvironment(Long environmentId) {
126114
// First, get the environment
127115
Environment environment =
@@ -147,14 +135,13 @@ private Environment lockEnvironment(Long environmentId) {
147135
private HeliosDeployment createHeliosDeployment(
148136
Environment environment,
149137
DeployRequest deployRequest,
150-
String commitSha,
151138
Optional<PullRequest> optionalPullRequest) {
152139
HeliosDeployment heliosDeployment = new HeliosDeployment();
153140
heliosDeployment.setEnvironment(environment);
154141
heliosDeployment.setUser(authService.getUserId());
155142
heliosDeployment.setStatus(HeliosDeployment.Status.WAITING);
156143
heliosDeployment.setBranchName(deployRequest.branchName());
157-
heliosDeployment.setSha(commitSha);
144+
heliosDeployment.setSha(deployRequest.commitSha());
158145
heliosDeployment.setCreator(authService.getUserFromGithubId());
159146
heliosDeployment.setPullRequest(optionalPullRequest.orElse(null));
160147
return heliosDeploymentRepository.saveAndFlush(heliosDeployment);

0 commit comments

Comments
 (0)