Skip to content

Commit 4cf89a2

Browse files
feat: set default ignored accounts and the ability to specify (RD-2964) (#79)
* feat(RD-2964): add support for ignored accounts in static analysis action Enhances the StaticAnalysis class to allow specifying accounts to ignore during commit hash checks. This addition improves the flexibility of the static analysis action by enabling users to exclude certain accounts from warnings related to commit hash usage. * feat(RD-2964): integrate ignored accounts into static analysis action Updates the static analysis action to accept a list of accounts to ignore during commit hash checks. This enhancement allows users to exclude specific accounts from warnings, improving the action's flexibility and usability. * feat(RD-2964): enhance static analysis action with ignored accounts input Adds an input parameter to the static analysis action for specifying a comma-separated list of accounts to ignore during analysis. This update improves the action's configurability and user experience by allowing exclusions of specific accounts from warnings. * feat(RD-2964): add logging for ignored accounts in static analysis action Enhances the static analysis action by adding console logging for ignored accounts and the current account being processed. This improvement aids in debugging and provides better visibility into the action's behavior during execution. * fix: correct indentation in static analysis action for ignored accounts logging This update fixes the indentation in the StaticAnalysis class constructor, ensuring proper formatting and readability of the code. The change enhances maintainability without altering functionality. * fix: update regex for account extraction in static analysis action This change modifies the regex used in the StaticAnalysis class to correctly capture the account and reference from the 'uses' field in GitHub Actions. The update ensures accurate logging of accounts during static analysis, enhancing the action's functionality and debugging capabilities. * fix: refine account extraction logic in static analysis action This update modifies the account extraction logic in the StaticAnalysis class to split the account string and capture only the relevant portion. This change enhances the accuracy of account logging during static analysis, improving the overall functionality of the action. * refactor: remove console logging for ignored accounts in static analysis action This update removes unnecessary console logging for ignored accounts and the current account being processed in the StaticAnalysis class. The change streamlines the code and enhances readability without affecting the action's functionality.
1 parent dce2b04 commit 4cf89a2

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

.github/actions/static-analysis/action.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
name: "Static Analysis"
22
description: "Runs static analysis on the code"
33

4+
inputs:
5+
ignored-accounts:
6+
description: "Comma-separated list of accounts to ignore"
7+
required: false
8+
default: "actions,VirdocsSoftware"
9+
410
runs:
511
using: "composite"
612
steps:
@@ -12,4 +18,6 @@ runs:
1218
echo "With the current working directory: $(pwd)"
1319
node ${{ github.action_path }}/scan_github_actions.js
1420
shell: bash
15-
working-directory: ${{ github.workspace }}
21+
working-directory: ${{ github.workspace }}
22+
env:
23+
IGNORED_ACCOUNTS: ${{ inputs.ignored-accounts }}

.github/actions/static-analysis/scan_github_actions.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
class StaticAnalysis {
2-
constructor(dataProvider, process) {
2+
constructor(dataProvider, process, ignoredAccounts = []) {
33
this.dataProvider = dataProvider;
44
this.process = process;
5+
this.ignoredAccounts = ignoredAccounts;
56
}
67

78
isCommitHash(ref) {
@@ -25,11 +26,15 @@ class StaticAnalysis {
2526

2627
scanFile(filePath) {
2728
const content = this.dataProvider.readFile(filePath);
28-
const regex = /uses:\s*[\w-]+\/[\w-]+@([\w-.]+)/g;
29+
const regex = /uses:\s*([\w-]+\/[\w-]+)@([\w-.]+)/g;
2930
let match;
3031
let warnings = [];
3132
while ((match = regex.exec(content)) !== null) {
32-
const ref = match[1];
33+
const ref = match[2];
34+
const account = match[1].split('/')[0];
35+
if (this.ignoredAccounts.includes(account)) {
36+
continue;
37+
}
3338
if (!this.isCommitHash(ref)) {
3439
warnings.push(`Warning: In file ${filePath}, '${match[0]}' does not use a commit hash.`);
3540
}
@@ -90,7 +95,8 @@ class DataProvider {
9095
const fs = require('fs');
9196
const path = require('path');
9297
const process = require('process');
98+
const ignoredAccounts = (process.env.IGNORED_ACCOUNTS || '').split(',');
9399

94100
const dataProvider = new DataProvider(fs, path);
95-
const staticAnalysis = new StaticAnalysis(dataProvider, process);
101+
const staticAnalysis = new StaticAnalysis(dataProvider, process, ignoredAccounts);
96102
staticAnalysis.run();

0 commit comments

Comments
 (0)