-
Notifications
You must be signed in to change notification settings - Fork 295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Development
: Migrate build agents components
#9923
base: develop
Are you sure you want to change the base?
Conversation
WalkthroughThe changes in this pull request involve modifications to the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (10)
src/main/webapp/app/localci/build-agents/build-agents.service.ts (2)
Line range hint
22-38
: Inconsistent URL encoding across methodsWhile
pauseBuildAgent
andresumeBuildAgent
properly encode agent names usingencodeURIComponent
,getBuildAgentDetails
doesn't encode theagentName
parameter, which could cause issues with special characters.Apply this change:
getBuildAgentDetails(agentName: string): Observable<BuildAgentInformation> { - return this.http.get<BuildAgentInformation>(`${this.adminResourceUrl}/build-agent`, { params: { agentName } }).pipe( + const encodedAgentName = encodeURIComponent(agentName); + return this.http.get<BuildAgentInformation>(`${this.adminResourceUrl}/build-agent`, { params: { agentName: encodedAgentName } }).pipe( catchError((err) => { return throwError(() => new Error(`Failed to fetch build agent details ${agentName}\n${err.message}`)); }), ); }
Line range hint
22-75
: Consider extracting common error handling logicMultiple methods share similar error handling patterns. Consider extracting this into a reusable operator.
Create a utility operator:
private handleBuildAgentError(operation: string, agentName?: string) { return catchError((err) => { const context = agentName ? ` ${agentName}` : 's'; return throwError(() => new Error(`Failed to ${operation} build agent${context}\n${err.message}`)); }); }Then use it in methods:
getBuildAgentDetails(agentName: string): Observable<BuildAgentInformation> { const encodedAgentName = encodeURIComponent(agentName); return this.http.get<BuildAgentInformation>(`${this.adminResourceUrl}/build-agent`, { params: { agentName: encodedAgentName } }).pipe( - catchError((err) => { - return throwError(() => new Error(`Failed to fetch build agent details ${agentName}\n${err.message}`)); - }), + this.handleBuildAgentError('fetch', agentName) ); }src/test/javascript/spec/component/localci/build-agents/build-agent-summary.component.spec.ts (1)
Line range hint
146-151
: Consider using MockProvider consistentlyWhile
MockProvider
is used forAlertService
, other services are using manual mock objects. Consider usingMockProvider
consistently for all services.Replace manual mocks with MockProvider:
providers: [ - { provide: JhiWebsocketService, useValue: mockWebsocketService }, - { provide: BuildAgentsService, useValue: mockBuildAgentsService }, - { provide: DataTableComponent, useClass: DataTableComponent }, + MockProvider(JhiWebsocketService, mockWebsocketService), + MockProvider(BuildAgentsService, mockBuildAgentsService), + MockProvider(DataTableComponent), MockProvider(AlertService), ],src/test/javascript/spec/component/localci/build-agents/build-agent-details.component.spec.ts (1)
Line range hint
155-158
: Use more specific assertion methodsAccording to the coding guidelines, we should use more specific assertion methods. For example:
- Use
toHaveBeenCalledOnce()
instead of justtoHaveBeenCalled()
- Use
toStrictEqual()
instead oftoEqual()
for object comparisons- expect(mockBuildAgentsService.getBuildAgentDetails).toHaveBeenCalled(); - expect(component.buildAgent).toEqual(mockBuildAgent); + expect(mockBuildAgentsService.getBuildAgentDetails).toHaveBeenCalledOnce(); + expect(component.buildAgent).toStrictEqual(mockBuildAgent); - expect(component.buildAgent).toEqual(mockBuildAgent); + expect(component.buildAgent).toStrictEqual(mockBuildAgent);Also applies to: 166-169
src/main/webapp/app/localci/build-agents/build-agent-details/build-agent-details/build-agent-details.component.ts (5)
Line range hint
1-15
: Update import statements to use single quotes consistentlyPer the coding guidelines, string literals should use single quotes consistently.
-import { BuildAgentInformation } from "app/entities/programming/build-agent-information.model"; +import { BuildAgentInformation } from 'app/entities/programming/build-agent-information.model';
18-22
: Update component decorator to use styleUrls instead of styleUrlThe
styleUrl
property is newer but less flexible than the standardstyleUrls
array property. For consistency with Angular style guide, usestyleUrls
.@Component({ selector: 'jhi-build-agent-details', templateUrl: './build-agent-details.component.html', - styleUrl: './build-agent-details.component.scss', + styleUrls: ['./build-agent-details.component.scss'], standalone: true, imports: [ArtemisSharedModule, NgxDatatableModule, ArtemisDataTableModule, SubmissionResultStatusModule], })
Line range hint
39-44
: Improve comment formatting for better readabilityThe icons section comment could be formatted better.
- //icons + // Font Awesome icons for UI elements
Line range hint
124-126
: Consider moving URL construction to a serviceThe
viewBuildLogs
method directly constructs API URLs. Consider moving this to theBuildAgentsService
for better maintainability and reusability.+ // In BuildAgentsService + getBuildLogsUrl(resultId: number): string { + return `/api/build-log/${resultId}`; + } + // In component viewBuildLogs(resultId: number): void { - const url = `/api/build-log/${resultId}`; + const url = this.buildAgentsService.getBuildLogsUrl(resultId); window.open(url, '_blank'); }
Line range hint
128-183
: Refactor duplicate alert handling logicThe
pauseBuildAgent
andresumeBuildAgent
methods contain similar error handling patterns. Consider extracting this to a reusable method.+ private handleBuildAgentOperation( + operation: () => void, + successMessage: string, + failureMessage: string, + ): void { + if (!this.buildAgent.buildAgent?.name) { + this.alertService.addAlert({ + type: AlertType.WARNING, + message: 'artemisApp.buildAgents.alerts.buildAgentWithoutName', + }); + return; + } + + operation(); + } pauseBuildAgent(): void { - if (this.buildAgent.buildAgent?.name) { - this.buildAgentsService.pauseBuildAgent(this.buildAgent.buildAgent.name).subscribe({ + this.handleBuildAgentOperation( + () => this.buildAgentsService.pauseBuildAgent(this.buildAgent.buildAgent!.name).subscribe({ next: () => { this.alertService.addAlert({ type: AlertType.SUCCESS, message: 'artemisApp.buildAgents.alerts.buildAgentPaused', }); }, error: () => { this.alertService.addAlert({ type: AlertType.DANGER, message: 'artemisApp.buildAgents.alerts.buildAgentPauseFailed', }); }, - }); - } else { - this.alertService.addAlert({ - type: AlertType.WARNING, - message: 'artemisApp.buildAgents.alerts.buildAgentWithoutName', - }); - } + }), + 'artemisApp.buildAgents.alerts.buildAgentPaused', + 'artemisApp.buildAgents.alerts.buildAgentPauseFailed' + ); }src/main/webapp/app/localci/build-agents/build-agent-summary/build-agent-summary.component.ts (1)
Line range hint
31-37
: Consider implementing state management.Given the component manages multiple build agents and their states, consider implementing a state management solution (e.g., NgRx, RxJS BehaviorSubject) to:
- Centralize build agent state
- Improve state predictability
- Enable easier testing
- Facilitate future scalability
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (6)
src/main/webapp/app/admin/admin.module.ts
(1 hunks)src/main/webapp/app/localci/build-agents/build-agent-details/build-agent-details/build-agent-details.component.ts
(2 hunks)src/main/webapp/app/localci/build-agents/build-agent-summary/build-agent-summary.component.ts
(2 hunks)src/main/webapp/app/localci/build-agents/build-agents.service.ts
(2 hunks)src/test/javascript/spec/component/localci/build-agents/build-agent-details.component.spec.ts
(2 hunks)src/test/javascript/spec/component/localci/build-agents/build-agent-summary.component.spec.ts
(2 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
src/main/webapp/app/localci/build-agents/build-agents.service.ts (1)
src/main/webapp/app/admin/admin.module.ts (1)
src/test/javascript/spec/component/localci/build-agents/build-agent-details.component.spec.ts (1)
Pattern src/test/javascript/spec/**/*.ts
: jest: true; mock: NgMocks; bad_practices: avoid_full_module_import; perf_improvements: mock_irrelevant_deps; service_testing: mock_http_for_logic; no_schema: avoid_NO_ERRORS_SCHEMA; expectation_specificity: true; solutions: {boolean: toBeTrue/False, reference: toBe, existence: toBeNull/NotNull, undefined: toBeUndefined, class_obj: toContainEntries/toEqual, spy_calls: {not_called: not.toHaveBeenCalled, once: toHaveBeenCalledOnce, with_value: toHaveBeenCalledWith|toHaveBeenCalledExactlyOnceWith}}
src/test/javascript/spec/component/localci/build-agents/build-agent-summary.component.spec.ts (1)
Pattern src/test/javascript/spec/**/*.ts
: jest: true; mock: NgMocks; bad_practices: avoid_full_module_import; perf_improvements: mock_irrelevant_deps; service_testing: mock_http_for_logic; no_schema: avoid_NO_ERRORS_SCHEMA; expectation_specificity: true; solutions: {boolean: toBeTrue/False, reference: toBe, existence: toBeNull/NotNull, undefined: toBeUndefined, class_obj: toContainEntries/toEqual, spy_calls: {not_called: not.toHaveBeenCalled, once: toHaveBeenCalledOnce, with_value: toHaveBeenCalledWith|toHaveBeenCalledExactlyOnceWith}}
src/main/webapp/app/localci/build-agents/build-agent-summary/build-agent-summary.component.ts (1)
src/main/webapp/app/localci/build-agents/build-agent-details/build-agent-details/build-agent-details.component.ts (1)
🔇 Additional comments (7)
src/main/webapp/app/localci/build-agents/build-agents.service.ts (1)
1-1
: LGTM: Successful migration to modern DI pattern
The migration from constructor-based dependency injection to the new inject()
pattern aligns with modern Angular practices and reduces boilerplate code.
Also applies to: 11-11
src/main/webapp/app/admin/admin.module.ts (1)
78-79
: LGTM: Proper migration to standalone components
Moving BuildAgentSummaryComponent
and BuildAgentDetailsComponent
to the imports array correctly reflects their new standalone nature. This change:
- Improves tree-shaking capabilities
- Reduces bundle size
- Aligns with Angular's recommended architecture
src/test/javascript/spec/component/localci/build-agents/build-agent-summary.component.spec.ts (1)
144-145
: LGTM: Improved test configuration
The simplified test configuration with ArtemisTestModule
and empty declarations array aligns with best practices for testing standalone components.
src/main/webapp/app/localci/build-agents/build-agent-details/build-agent-details/build-agent-details.component.ts (1)
25-29
: LGTM! Modern dependency injection pattern implemented correctly
The migration to using inject()
function aligns well with modern Angular practices and improves code maintainability.
src/main/webapp/app/localci/build-agents/build-agent-summary/build-agent-summary.component.ts (3)
Line range hint 1-21
: LGTM! Component migration to standalone looks good.
The migration to a standalone component follows Angular's best practices. The necessary modules are correctly imported and the component decorator is properly configured.
24-29
: Verify memory management with inject pattern.
The migration to inject() function looks good, but let's ensure there are no memory leaks with the websocket subscriptions.
✅ Verification successful
Memory management is properly implemented
The component correctly handles websocket subscription cleanup in the ngOnDestroy
lifecycle hook by:
- Unsubscribing from the websocket channel
- Cleaning up the websocket subscription
- Cleaning up the REST subscription
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for proper cleanup of subscriptions in component
ast-grep --pattern 'ngOnDestroy() {
$$$
this.websocketSubscription?.unsubscribe();
$$$
}'
Length of output: 97
Script:
#!/bin/bash
# Let's search for websocket subscription and cleanup patterns more broadly
rg -A 10 "websocketService" src/main/webapp/app/localci/build-agents/build-agent-summary/build-agent-summary.component.ts
# Also search for any subscription cleanup patterns
rg -A 5 "ngOnDestroy|unsubscribe" src/main/webapp/app/localci/build-agents/build-agent-summary/build-agent-summary.component.ts
Length of output: 2236
Line range hint 116-146
: Verify translation keys for alert messages.
The alert messages use translation keys. Let's verify that these keys are properly defined in the translation files.
✅ Verification successful
Translation keys are properly defined and available
The translation keys used in the component are correctly defined in both English and German language files:
artemisApp.buildAgents.alerts.buildAgentPaused
artemisApp.buildAgents.alerts.buildAgentResumed
artemisApp.buildAgents.alerts.buildAgentPauseFailed
artemisApp.buildAgents.alerts.buildAgentResumeFailed
artemisApp.buildAgents.alerts.buildAgentWithoutName
All keys have corresponding translations in both src/main/webapp/i18n/en/buildAgents.json
and src/main/webapp/i18n/de/buildAgents.json
.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for translation keys in i18n files
rg "artemisApp.buildAgents.alerts" -g "*.json"
Length of output: 46
Script:
#!/bin/bash
# Let's try searching in all files, not just JSON, to understand the usage pattern
rg "artemisApp\.buildAgents\.alerts\." --type-add 'i18n:*.{json,ts,js}' -t i18n
# Also search for general i18n file patterns to ensure we're looking in the right places
fd -e json -e yml "i18n|translations|locale|messages"
Length of output: 3717
Script:
#!/bin/bash
# Let's check the src/main/webapp directory for i18n files specifically
fd -e json . src/main/webapp/i18n || fd -e json . src/main/webapp/app/i18n
# Also let's check the root directory for any translation files
fd -e json -e properties "messages|translations|i18n" .
Length of output: 13900
Script:
#!/bin/bash
# Let's check the content of buildAgents.json files for the specific alert messages
rg -A 5 "alerts" src/main/webapp/i18n/*/buildAgents.json
Length of output: 1904
Checklist
General
Client
authorities
to all new routes and checked the course groups for displaying navigation elements (links, buttons).Changes affecting Programming Exercises
Motivation and Context
Migrate build agent components to new Angular standars
Steps for Testing
Prerequisites:
Testserver States
Note
These badges show the state of the test servers.
Green = Currently available, Red = Currently locked
Click on the badges to get to the test servers.
Review Progress
Performance Review
Code Review
Manual Tests
Summary by CodeRabbit
Release Notes
New Features
BuildAgentSummaryComponent
andBuildAgentDetailsComponent
are now standalone components, enhancing modularity and reusability.Improvements
Bug Fixes