Skip to content

Commit f2ddaa4

Browse files
authored
feat/annotations
* Added snippet and full file annotations * Added comment in conversation with link to detailed match comments * Added direct link to edit scanoss.json in undeclared policy check * Added link to auto create scanoss.json file * Chore: updated scanoss-py version to v1.32.0 * Added function to merge existing components in scanoss.json with undeclared components * changed policies.halt_on_failure to false for test action
1 parent 0215485 commit f2ddaa4

26 files changed

+4341
-732
lines changed

.github/workflows/test-action.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
- '*'
88

99
permissions:
10-
contents: read
10+
contents: write
1111
pull-requests: write
1212
checks: write
1313
actions: read
@@ -27,7 +27,9 @@ jobs:
2727
uses: ./
2828
with:
2929
dependencies.enabled: false
30-
policies: copyleft
30+
policies: copyleft, und
31+
policies.halt_on_failure: 'false'
32+
api.key: ${{ secrets.SC_API_KEY }}
3133

3234

3335
- name: Print stdout scan command

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.2.3] - 2025-09-18
9+
### Added
10+
- Added annotations for file and snippet matches
11+
- Added commit comment for each match
12+
- Added link to auto create scanoss.json file
13+
814
## [1.2.2] - 2025-09-09
915
### Added
1016
- Added policies input trimming
@@ -125,3 +131,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
125131
[1.2.0]: https://github.com/scanoss/gha-code-scan/compare/v1.1.0...v1.2.0
126132
[1.2.1]: https://github.com/scanoss/gha-code-scan/compare/v1.2.0...v1.2.1
127133
[1.2.2]: https://github.com/scanoss/gha-code-scan/compare/v1.2.1...v1.2.2
134+
[1.2.3]: https://github.com/scanoss/gha-code-scan/compare/v1.2.2...v1.2.3

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ For example workflow runs, check out our
103103
| licenses.copyleft.include | List of Copyleft licenses to append to the default list. Provide licenses as a comma-separated list. | Optional | - |
104104
| licenses.copyleft.exclude | List of Copyleft licenses to remove from default list. Provide licenses as a comma-separated list. | Optional | - |
105105
| licenses.copyleft.explicit | Explicit list of Copyleft licenses to consider. Provide licenses as a comma-separated list. | Optional | - |
106-
| runtimeContainer | Runtime URL | Optional | `ghcr.io/scanoss/scanoss-py:v1.31.5` |
106+
| runtimeContainer | Runtime URL | Optional | `ghcr.io/scanoss/scanoss-py:v1.32.0` |
107107
| skipSnippets | Skip the generation of snippets. (scanFiles option must be enabled) | Optional | `false` |
108108
| scanFiles | Enable or disable file and snippet scanning | Optional | `true` |
109109
| scanossSettings | Settings file to use for scanning. See the SCANOSS settings [documentation](https://scanoss.readthedocs.io/projects/scanoss-py/en/latest/#settings-file) | Optional | `true` |

__tests__/github.utils.test.ts

Lines changed: 5 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
*/
2323

2424
import { context, getOctokit } from '@actions/github';
25-
import * as core from '@actions/core';
2625
import { getSHA, isPullRequest, createCommentOnPR, getFirstRunId } from '../src/utils/github.utils';
2726

2827
// Mock external dependencies
@@ -34,10 +33,6 @@ jest.mock('../src/app.input', () => ({
3433

3534
const mockOctokit = {
3635
rest: {
37-
actions: {
38-
getWorkflowRun: jest.fn(),
39-
listWorkflowRuns: jest.fn()
40-
},
4136
issues: {
4237
createComment: jest.fn()
4338
}
@@ -182,80 +177,22 @@ describe('GitHub Utils', () => {
182177
});
183178

184179
describe('getFirstRunId', () => {
185-
it('should return current runId for non-workflow_dispatch events', async () => {
186-
(context.eventName as any) = 'push';
180+
it('should always return current runId', async () => {
187181
(context.runId as any) = 98765;
182+
(context.eventName as any) = 'push'; // Not workflow_dispatch
188183

189184
const result = await getFirstRunId();
190185

191186
expect(result).toBe(98765);
192-
expect(mockOctokit.rest.actions.getWorkflowRun).not.toHaveBeenCalled();
193-
});
194-
195-
it('should find first run for workflow_dispatch events', async () => {
196-
(context.eventName as any) = 'workflow_dispatch';
197-
(context.runId as any) = 12345;
198-
(context.repo as any) = { owner: 'test-owner', repo: 'test-repo' };
199-
(context.sha as any) = 'test-sha-123';
200-
201-
// Mock current workflow run
202-
mockOctokit.rest.actions.getWorkflowRun.mockResolvedValue({
203-
data: {
204-
workflow_id: 'test-workflow',
205-
head_sha: 'test-sha-123'
206-
}
207-
});
208-
209-
// Mock workflow runs list
210-
mockOctokit.rest.actions.listWorkflowRuns.mockResolvedValue({
211-
data: {
212-
workflow_runs: [
213-
{ id: 11111, created_at: '2023-01-03T10:00:00Z', event: 'push', head_sha: 'test-sha-123' },
214-
{ id: 22222, created_at: '2023-01-02T10:00:00Z', event: 'push', head_sha: 'test-sha-123' },
215-
{ id: 33333, created_at: '2023-01-01T10:00:00Z', event: 'push', head_sha: 'test-sha-123' } // Oldest
216-
]
217-
}
218-
});
219-
220-
const infoSpy = jest.spyOn(core, 'info').mockImplementation();
221-
222-
const result = await getFirstRunId();
223-
224-
expect(result).toBe(33333); // Should return the oldest run
225-
expect(infoSpy).toHaveBeenCalledWith('First Run ID found: 33333');
226-
227-
infoSpy.mockRestore();
228187
});
229188

230-
it('should return current runId if no first run is found', async () => {
231-
(context.eventName as any) = 'workflow_dispatch';
189+
it('should handle different run IDs', async () => {
232190
(context.runId as any) = 12345;
233-
234-
mockOctokit.rest.actions.getWorkflowRun.mockResolvedValue({
235-
data: {
236-
workflow_id: 'test-workflow',
237-
head_sha: 'test-sha-123'
238-
}
239-
});
240-
241-
mockOctokit.rest.actions.listWorkflowRuns.mockResolvedValue({
242-
data: {
243-
workflow_runs: []
244-
}
245-
});
191+
(context.eventName as any) = 'pull_request'; // Not workflow_dispatch
246192

247193
const result = await getFirstRunId();
248194

249-
expect(result).toBe(12345); // Should return current runId as fallback
250-
});
251-
252-
it('should throw API errors (no error handling in implementation)', async () => {
253-
(context.eventName as any) = 'workflow_dispatch';
254-
(context.runId as any) = 12345;
255-
256-
mockOctokit.rest.actions.getWorkflowRun.mockRejectedValue(new Error('API Error'));
257-
258-
await expect(getFirstRunId()).rejects.toThrow('API Error');
195+
expect(result).toBe(12345);
259196
});
260197
});
261198
});

__tests__/undeclared-policy-check.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ jest.mock('@actions/github', () => ({
4343
context: {
4444
repo: { owner: 'mock-owner', repo: 'mock-repo' },
4545
serverUrl: 'github',
46-
runId: 12345678
46+
runId: 12345678,
47+
ref: 'refs/heads/test-branch'
4748
// Add other properties as needed
4849
},
4950
getOctokit: jest.fn().mockReturnValue({

action.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ inputs:
5959
required: false
6060
runtimeContainer:
6161
description: 'Specify runtime container to perform the scan.'
62-
default: 'ghcr.io/scanoss/scanoss-py:v1.31.5'
62+
default: 'ghcr.io/scanoss/scanoss-py:v1.32.0'
6363
required: false
6464
skipSnippets:
6565
description: 'Skip the generation of snippets.'
@@ -100,6 +100,10 @@ inputs:
100100
deptrack.projectversion:
101101
description: 'Dependency Track project version'
102102
required: false
103+
matchAnnotations:
104+
description: 'Enable or disable match annotations'
105+
required: false
106+
default: 'true'
103107

104108
outputs:
105109
result-filepath:

0 commit comments

Comments
 (0)