Skip to content

Commit

Permalink
SCP-86 Sets token optional
Browse files Browse the repository at this point in the history
  • Loading branch information
francostramana committed Jan 29, 2024
1 parent be8bcbf commit 2cd86d5
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
with:
# sbom-ignore: 'scanoss-ignore.json'
with-dependencies: true
github-token: ${{ secrets.GITHUB_TOKEN }}
# github-token: ${{ secrets.GITHUB_TOKEN }}


- name: Print stdout scan command
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ jobs:
- name: Run SCANOSS analysis
id: scanoss-scan-action
uses: scanoss/actions-scan@main
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
```
For example workflow runs, check out the
Expand All @@ -53,7 +51,7 @@ For example workflow runs, check out the
| **Parameter** | **Description** | **Required** | **Default** |
|--------------|------------------------------------------------|--------------|-------------|
| github-token | Your GitHub token| Required | - |
| github-token | Your GitHub token | Optional | `${{ github.token }}` |
| output-path | Output result file name. | Optional | `results.json` |
| sbom-identify | Scan and identify components in SBOM file | Optional | - |
| sbom-ignore | Ignore components specified in the SBOM file | Optional | - |
Expand Down
3 changes: 2 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ branding:
inputs:
github-token:
description: 'Your GitHub token'
required: true
required: false
default: ${{ github.token }}
output-path:
description: 'Output result file name'
required: false
Expand Down
11 changes: 6 additions & 5 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/app.input.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as core from '@actions/core';

export const REPO_DIR = process.env.GITHUB_WORKSPACE as string;
export const GITHUB_TOKEN = core.getInput('github-token');
export const OUTPUT_PATH = core.getInput('output-path');
export const SBOM_INDENTIFY = core.getInput('sbom-identify');
export const SBOM_IGNORE = core.getInput('sbom-ignore');
Expand Down
5 changes: 2 additions & 3 deletions src/policies/policy-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as core from '@actions/core';
import { getSHA } from '../utils/github.utils';
import { ScannerResults } from '../services/result.interfaces';
import { GitHub } from '@actions/github/lib/utils';
import * as inputs from '../app.input';

const UNINITIALIZED = -1;

Expand All @@ -25,9 +26,7 @@ export abstract class PolicyCheck {
private checkRunId: number;

constructor(checkName: string) {
const GITHUB_TOKEN = core.getInput('github-token');

this.octokit = getOctokit(GITHUB_TOKEN);
this.octokit = getOctokit(inputs.GITHUB_TOKEN);
this.checkName = checkName;
this.checkRunId = UNINITIALIZED;
}
Expand Down
1 change: 1 addition & 0 deletions src/services/scan.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from 'path';
import * as input from '../app.input';
import { DefaultArtifactClient } from '@actions/artifact';

const artifact = new DefaultArtifactClient();

export async function uploadResults(): Promise<void> {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/github.utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { context, getOctokit } from '@actions/github';
import * as core from '@actions/core';
import * as inputs from '../app.input';

const prEvents = ['pull_request', 'pull_request_review', 'pull_request_review_comment'];

Expand All @@ -20,8 +21,7 @@ export function getSHA(): string {
}

export async function createCommentOnPR(message: string): Promise<void> {
const GITHUB_TOKEN = core.getInput('github-token');
const octokit = getOctokit(GITHUB_TOKEN);
const octokit = getOctokit(inputs.GITHUB_TOKEN);

core.debug('Creating comment on PR');
octokit.rest.issues.createComment({
Expand Down

0 comments on commit 2cd86d5

Please sign in to comment.