Skip to content

Commit

Permalink
don't rename label column since it causes too many conflicts and labe…
Browse files Browse the repository at this point in the history
…ls not only mean deployment env
  • Loading branch information
gbanu committed Feb 16, 2025
1 parent 8940400 commit 9073b4f
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import type { Options } from '@hey-api/client-fetch';
import { type MutationOptions, type DefaultError, queryOptions } from '@tanstack/angular-query-experimental';
import type {
UpdateDeploymentEnvironmentData,
UpdateLabelData,
GetGitRepoSettingsData,
UpdateGitRepoSettingsData,
UpdateWorkflowGroupsData,
Expand Down Expand Up @@ -52,7 +52,7 @@ import type {
DeleteWorkflowGroupData,
} from '../types.gen';
import {
updateDeploymentEnvironment,
updateLabel,
getGitRepoSettings,
updateGitRepoSettings,
updateWorkflowGroups,
Expand Down Expand Up @@ -99,10 +99,10 @@ import {
client,
} from '../sdk.gen';

export const updateDeploymentEnvironmentMutation = (options?: Partial<Options<UpdateDeploymentEnvironmentData>>) => {
const mutationOptions: MutationOptions<unknown, DefaultError, Options<UpdateDeploymentEnvironmentData>> = {
export const updateLabelMutation = (options?: Partial<Options<UpdateLabelData>>) => {
const mutationOptions: MutationOptions<unknown, DefaultError, Options<UpdateLabelData>> = {
mutationFn: async localOptions => {
const { data } = await updateDeploymentEnvironment({
const { data } = await updateLabel({
...options,
...localOptions,
throwOnError: true,
Expand Down
4 changes: 2 additions & 2 deletions client/src/app/core/modules/openapi/schemas.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ export const WorkflowDtoSchema = {
badgeUrl: {
type: 'string',
},
deploymentEnvironment: {
label: {
type: 'string',
enum: ['NONE', 'TEST_SERVER', 'STAGING_SERVER', 'PRODUCTION_SERVER'],
},
Expand All @@ -359,7 +359,7 @@ export const WorkflowDtoSchema = {
format: 'date-time',
},
},
required: ['deploymentEnvironment', 'id', 'name', 'path', 'state'],
required: ['id', 'label', 'name', 'path', 'state'],
} as const;

export const WorkflowRunDtoSchema = {
Expand Down
6 changes: 3 additions & 3 deletions client/src/app/core/modules/openapi/sdk.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { createClient, createConfig, type Options } from '@hey-api/client-fetch';
import type {
UpdateDeploymentEnvironmentData,
UpdateLabelData,
GetGitRepoSettingsData,
GetGitRepoSettingsResponse,
UpdateGitRepoSettingsData,
Expand Down Expand Up @@ -87,14 +87,14 @@ import type {

export const client = createClient(createConfig());

export const updateDeploymentEnvironment = <ThrowOnError extends boolean = false>(options: Options<UpdateDeploymentEnvironmentData, ThrowOnError>) => {
export const updateLabel = <ThrowOnError extends boolean = false>(options: Options<UpdateLabelData, ThrowOnError>) => {
return (options?.client ?? client).put<unknown, unknown, ThrowOnError>({
...options,
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
url: '/api/workflows/{workflowId}/deploymentEnvironment',
url: '/api/workflows/{workflowId}/label',
});
};

Expand Down
8 changes: 4 additions & 4 deletions client/src/app/core/modules/openapi/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export type WorkflowDto = {
url?: string;
htmlUrl?: string;
badgeUrl?: string;
deploymentEnvironment: 'NONE' | 'TEST_SERVER' | 'STAGING_SERVER' | 'PRODUCTION_SERVER';
label: 'NONE' | 'TEST_SERVER' | 'STAGING_SERVER' | 'PRODUCTION_SERVER';
createdAt?: string;
updatedAt?: string;
};
Expand Down Expand Up @@ -297,16 +297,16 @@ export type BranchDetailsDto = {
repository?: RepositoryInfoDto;
};

export type UpdateDeploymentEnvironmentData = {
export type UpdateLabelData = {
body: 'NONE' | 'TEST_SERVER' | 'STAGING_SERVER' | 'PRODUCTION_SERVER';
path: {
workflowId: number;
};
query?: never;
url: '/api/workflows/{workflowId}/deploymentEnvironment';
url: '/api/workflows/{workflowId}/label';
};

export type UpdateDeploymentEnvironmentResponses = {
export type UpdateLabelResponses = {
/**
* OK
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ <h3 class="text-xl mb-2">Workflows</h3>
<th>File Name</th>
<th>Workflow Name</th>
<th>Assign Group</th>
<th>Deployment Environment</th>
<th>Label</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-workflow>
Expand All @@ -111,8 +111,8 @@ <h3 class="text-xl mb-2">Workflows</h3>
</td>
<td>
<p-select
[options]="getWorkflowLabelOptions(workflow.deploymentEnvironment)"
[(ngModel)]="workflow.deploymentEnvironment"
[options]="getWorkflowLabelOptions(workflow.label)"
[(ngModel)]="workflow.label"
placeholder="Select Label"
(onClick)="storePreviousLabel(workflow)"
(onChange)="onChangeLabel(workflow)"
Expand Down
20 changes: 10 additions & 10 deletions client/src/app/pages/project-settings/project-settings.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
getGroupsWithWorkflowsQueryKey,
getWorkflowsByRepositoryIdOptions,
getWorkflowsByRepositoryIdQueryKey,
updateDeploymentEnvironmentMutation,
updateLabelMutation,
updateWorkflowGroupsMutation,
} from '@app/core/modules/openapi/@tanstack/angular-query-experimental.gen';
import { WorkflowDtoSchema } from '@app/core/modules/openapi/schemas.gen';
Expand Down Expand Up @@ -182,8 +182,8 @@ export class ProjectSettingsComponent {
enabled: () => !!this.repositoryId(),
}));

workflowDeploymentEnvironmentMutation = injectMutation(() => ({
...updateDeploymentEnvironmentMutation(),
workflowLabelMutation = injectMutation(() => ({
...updateLabelMutation(),
onSuccess: () => {
this.queryClient.invalidateQueries({ queryKey: getWorkflowsByRepositoryIdQueryKey({ path: { repositoryId: this.repositoryId() } }) });
this.messageService.add({ severity: 'success', summary: 'Success', detail: 'Workflow Label updated successfully' });
Expand Down Expand Up @@ -214,8 +214,8 @@ export class ProjectSettingsComponent {
}));

getWorkflowLabelOptions(currentLabel: string) {
const assignedLabels = this.workflows().map(wf => wf.deploymentEnvironment);
return Object.values(WorkflowDtoSchema.properties.deploymentEnvironment.enum).filter(label => {
const assignedLabels = this.workflows().map(wf => wf.label);
return Object.values(WorkflowDtoSchema.properties.label.enum).filter(label => {
const isTest = label === 'TEST_SERVER' && assignedLabels.includes('TEST_SERVER');
const isStaging = label === 'STAGING_SERVER' && assignedLabels.includes('STAGING_SERVER');
const isProduction = label === 'PRODUCTION_SERVER' && assignedLabels.includes('PRODUCTION_SERVER');
Expand All @@ -225,13 +225,13 @@ export class ProjectSettingsComponent {

storePreviousLabel(workflow: WorkflowDto) {
// Store the current label before change
this.previousLabel = workflow.deploymentEnvironment;
this.previousLabel = workflow.label;
}

onChangeLabel(workflow: WorkflowDto) {
const label = workflow.deploymentEnvironment;
const label = workflow.label;
if (deploymentLabels.includes(label)) {
const existingLabel = this.workflows().find(wf => wf.deploymentEnvironment === label && wf.id !== workflow.id);
const existingLabel = this.workflows().find(wf => wf.label === label && wf.id !== workflow.id);
if (existingLabel) {
console.warn(`Only one workflow can be labeled as ${label}.`);
return;
Expand Down Expand Up @@ -262,11 +262,11 @@ export class ProjectSettingsComponent {
</div>
`,
accept: () => {
this.workflowDeploymentEnvironmentMutation.mutate({ path: { workflowId: workflow.id }, body: label });
this.workflowLabelMutation.mutate({ path: { workflowId: workflow.id }, body: label });
},
reject: () => {
// Restore the previous label if the user cancels
workflow.deploymentEnvironment = this.previousLabel;
workflow.label = this.previousLabel;
},
});
}
Expand Down
8 changes: 4 additions & 4 deletions server/application-server/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ servers:
- url: /
description: Default Server URL
paths:
/api/workflows/{workflowId}/deploymentEnvironment:
/api/workflows/{workflowId}/label:
put:
tags:
- workflow-controller
operationId: updateDeploymentEnvironment
operationId: updateLabel
parameters:
- name: workflowId
in: path
Expand Down Expand Up @@ -1145,7 +1145,7 @@ components:
type: string
badgeUrl:
type: string
deploymentEnvironment:
label:
type: string
enum:
- NONE
Expand All @@ -1159,8 +1159,8 @@ components:
type: string
format: date-time
required:
- deploymentEnvironment
- id
- label
- name
- path
- state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class Workflow extends BaseGitServiceEntity {
// Custom field for Repository Settings
@NonNull
@Enumerated(EnumType.STRING)
private DeploymentEnvironment deploymentEnvironment = DeploymentEnvironment.NONE;
private Label label = Label.NONE;

public enum State {
ACTIVE,
Expand All @@ -51,7 +51,7 @@ public enum State {
UNKNOWN,
}

public enum DeploymentEnvironment {
public enum Label {
NONE,
TEST_SERVER,
STAGING_SERVER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ public ResponseEntity<WorkflowDto> getWorkflowById(@PathVariable Long id) {
}

@EnforceAtLeastMaintainer
@PutMapping("/{workflowId}/deploymentEnvironment")
public ResponseEntity<Void> updateDeploymentEnvironment(
@PathVariable Long workflowId, @RequestBody Workflow.DeploymentEnvironment environment) {
workflowService.updateWorkflowDeploymentEnvironment(workflowId, environment);
@PutMapping("/{workflowId}/label")
public ResponseEntity<Void> updateWorkflowLabel(
@PathVariable Long workflowId, @RequestBody Workflow.Label label) {
workflowService.updateWorkflowLabel(workflowId, label);
return ResponseEntity.noContent().build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public record WorkflowDto(
String url,
String htmlUrl,
String badgeUrl,
@NonNull Workflow.DeploymentEnvironment deploymentEnvironment,
@NonNull Workflow.Label label,
OffsetDateTime createdAt,
OffsetDateTime updatedAt) {

Expand All @@ -31,7 +31,7 @@ public static WorkflowDto fromWorkflow(Workflow workflow) {
workflow.getUrl(),
workflow.getHtmlUrl(),
workflow.getBadgeUrl(),
workflow.getDeploymentEnvironment(),
workflow.getLabel(),
workflow.getCreatedAt(),
workflow.getUpdatedAt());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.tum.cit.aet.helios.workflow;

import de.tum.cit.aet.helios.gitrepo.GitRepository;
import de.tum.cit.aet.helios.workflow.Workflow.Label;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
Expand All @@ -13,6 +14,6 @@ public interface WorkflowRepository extends JpaRepository<Workflow, Long> {

List<Workflow> findByStateOrderByCreatedAtDesc(Workflow.State state);

Workflow findFirstByRepositoryRepositoryIdAndDeploymentEnvironmentOrderByCreatedAtDesc(
Long repositoryId, Workflow.DeploymentEnvironment deploymentEnvironment);
Workflow findFirstByLabelAndRepositoryRepositoryIdOrderByCreatedAtDesc(
Label label, Long repositoryId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,51 +50,51 @@ public List<WorkflowDto> getWorkflowsByState(Workflow.State state) {
.collect(Collectors.toList());
}

public void updateWorkflowDeploymentEnvironment(
Long workflowId, Workflow.DeploymentEnvironment env) {
public void updateWorkflowLabel(Long workflowId, Workflow.Label label) {
Workflow workflow =
workflowRepository
.findById(workflowId)
.orElseThrow(() -> new IllegalArgumentException("Workflow not found!"));
workflow.setDeploymentEnvironment(env);
workflow.setLabel(label);
workflowRepository.save(workflow);
}

public Workflow getDeploymentWorkflowByEnvironment(
Workflow.DeploymentEnvironment environment, Long repositoryId) {
public Workflow getDeploymentWorkflowByLabel(Workflow.Label label, Long repositoryId) {
Workflow workflow =
workflowRepository
.findFirstByRepositoryRepositoryIdAndDeploymentEnvironmentOrderByCreatedAtDesc(
repositoryId, environment);
workflowRepository.findFirstByLabelAndRepositoryRepositoryIdOrderByCreatedAtDesc(
label, repositoryId);
return workflow;
}

public List<Workflow> getDeploymentWorkflowsForAllEnv(Long repositoryId) {

return Arrays.stream(Workflow.DeploymentEnvironment.values())
.filter(env -> env != Workflow.DeploymentEnvironment.NONE)
return Arrays.stream(Workflow.Label.values())
.filter(
label ->
label == Workflow.Label.TEST_SERVER
|| label == Workflow.Label.STAGING_SERVER
|| label == Workflow.Label.PRODUCTION_SERVER)
.map(
env ->
workflowRepository
.findFirstByRepositoryRepositoryIdAndDeploymentEnvironmentOrderByCreatedAtDesc(
repositoryId, env))
label ->
workflowRepository.findFirstByLabelAndRepositoryRepositoryIdOrderByCreatedAtDesc(
label, repositoryId))
.filter(Objects::nonNull)
.collect(Collectors.toList());
}

public Workflow.DeploymentEnvironment getDeploymentEnvironment(Environment.Type type) {
public Workflow.Label getLabel(Environment.Type type) {
switch (type) {
case PRODUCTION -> {
return Workflow.DeploymentEnvironment.PRODUCTION_SERVER;
return Workflow.Label.PRODUCTION_SERVER;
}
case STAGING -> {
return Workflow.DeploymentEnvironment.STAGING_SERVER;
return Workflow.Label.STAGING_SERVER;
}
case TEST -> {
return Workflow.DeploymentEnvironment.TEST_SERVER;
return Workflow.Label.TEST_SERVER;
}
default -> {
return Workflow.DeploymentEnvironment.NONE;
return null;
}
}
}
Expand All @@ -105,15 +105,13 @@ public Workflow getDeploymentWorkflowForEnv(Long environmentId) {
.getEnvironmentTypeById(environmentId)
.orElseThrow(() -> new EntityNotFoundException("Environment not found"));

Workflow.DeploymentEnvironment deploymentEnvironment =
this.getDeploymentEnvironment(environmentType);
if (deploymentEnvironment == null) {
Workflow.Label label = this.getLabel(environmentType);
if (label == null) {
throw new IllegalStateException("No workflow for this deployment environment found");
}

Workflow deploymentWorkflow =
this.getDeploymentWorkflowByEnvironment(
deploymentEnvironment, RepositoryContext.getRepositoryId());
this.getDeploymentWorkflowByLabel(label, RepositoryContext.getRepositoryId());
if (deploymentWorkflow == null) {
throw new NoSuchElementException("No deployment workflow found");
}
Expand Down
Loading

0 comments on commit 9073b4f

Please sign in to comment.