2
0
Fork 0
mirror of https://code.forgejo.org/docker/build-push-action.git synced 2025-09-16 18:06:55 +00:00

refactor: only report metrics when using Blacksmith builder

- Rename reportBuildMetrics to reportBuildStart for clarity
- Check if builder name contains 'blacksmith' before reporting
- Log warning when not using a Blacksmith builder
- Skip build start and completion reporting for non-Blacksmith builders
- Update tests to reflect function rename

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Claude 2025-08-03 15:59:22 -04:00
parent 99fce0de47
commit 61dd93325b
4 changed files with 25 additions and 16 deletions

View file

@ -28,7 +28,7 @@ jest.mock('../reporter', () => {
};
});
describe('reportBuildMetrics', () => {
describe('reportBuildStart', () => {
let mockInputs;
beforeEach(() => {
@ -42,7 +42,7 @@ describe('reportBuildMetrics', () => {
test('should handle missing dockerfile path', async () => {
(getDockerfilePath as jest.Mock).mockReturnValue(null);
const result = await main.reportBuildMetrics(mockInputs);
const result = await main.reportBuildStart(mockInputs);
expect(result).toBeNull();
expect(core.warning).toHaveBeenCalledWith('Error when reporting build metrics: Failed to resolve dockerfile path');
@ -54,7 +54,7 @@ describe('reportBuildMetrics', () => {
(getDockerfilePath as jest.Mock).mockReturnValue('/path/to/Dockerfile');
(reporter.reportBuild as jest.Mock).mockResolvedValue({docker_build_id: mockBuildId});
const result = await main.reportBuildMetrics(mockInputs);
const result = await main.reportBuildStart(mockInputs);
expect(result).toBe(mockBuildId);
expect(reporter.reportBuild).toHaveBeenCalledWith('/path/to/Dockerfile');
@ -65,7 +65,7 @@ describe('reportBuildMetrics', () => {
(getDockerfilePath as jest.Mock).mockReturnValue('/path/to/Dockerfile');
(reporter.reportBuild as jest.Mock).mockResolvedValue(null);
const result = await main.reportBuildMetrics(mockInputs);
const result = await main.reportBuildStart(mockInputs);
expect(result).toBeNull();
expect(reporter.reportBuild).toHaveBeenCalledWith('/path/to/Dockerfile');
@ -76,7 +76,7 @@ describe('reportBuildMetrics', () => {
(getDockerfilePath as jest.Mock).mockReturnValue('/path/to/Dockerfile');
(reporter.reportBuild as jest.Mock).mockRejectedValue(new Error('API error'));
const result = await main.reportBuildMetrics(mockInputs);
const result = await main.reportBuildStart(mockInputs);
expect(result).toBeNull();
expect(core.warning).toHaveBeenCalledWith('Error reporting build start: API error');