Skip to content

Add ESLint and NPM Audit workflow - #44

Merged
drtechie merged 1 commit into
PSMRI:developfrom
gupta-soham:feat/add-lint-audit-workflow
Dec 24, 2024
Merged

Add ESLint and NPM Audit workflow#44
drtechie merged 1 commit into
PSMRI:developfrom
gupta-soham:feat/add-lint-audit-workflow

Conversation

@gupta-soham

@gupta-soham gupta-soham commented Dec 24, 2024

Copy link
Copy Markdown
Contributor

Add automated workflow for ESLint and NPM Audit

References PSMRI/AMRIT#3

Summary by CodeRabbit

  • New Features
    • Introduced a new GitHub Actions workflow for linting and auditing the codebase.
  • Chores
    • Added a workflow file to automate code quality checks on specific branches and pull requests.

@coderabbitai

coderabbitai Bot commented Dec 24, 2024

Copy link
Copy Markdown

Walkthrough

A new GitHub Actions workflow file lint_audit.yml has been added to the repository's .github/workflows/ directory. This workflow is configured to run ESLint and perform an NPM audit automatically when code is pushed to main, master, or develop branches, or when pull requests target these branches. The workflow leverages a reusable workflow from the PSMRI/.github repository to execute these checks.

Changes

File Change Summary
.github/workflows/lint_audit.yml New workflow file added for linting and security auditing

Poem

🐰 A lint-loving rabbit hops with glee,
Checking code with auditing spree
ESLint running, security tight
Workflows dancing in GitHub's light
Clean code bouncing, errors take flight! 🔍


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sonarqubecloud

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 79127f4 and cb64ee7.

📒 Files selected for processing (1)
  • .github/workflows/lint_audit.yml (1 hunks)
🔇 Additional comments (1)
.github/workflows/lint_audit.yml (1)

9-11: 🛠️ Refactor suggestion

Consider pinning the reusable workflow version

The current configuration references the reusable workflow using @main, which automatically uses the latest version. This could lead to unexpected behavior if the workflow is updated.

Let's verify the reusable workflow's implementation and history:

Consider these improvements:

  1. Pin to a specific SHA commit instead of using @main:
-    uses: PSMRI/.github/.github/workflows/lint_audit.yml@main
+    uses: PSMRI/.github/.github/workflows/lint_audit.yml@{specific-sha}
  1. Add a timeout to prevent long-running jobs:
 jobs:
   lint-and-audit:
+    timeout-minutes: 10
     uses: PSMRI/.github/.github/workflows/lint_audit.yml@main

Comment on lines +3 to +7
on:
push:
branches: [main, master, develop]
pull_request:
branches: [main, master, develop]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Simplify branch triggers to match repository structure

The workflow configuration needs to be updated as it includes non-existent branches. Based on the verification:

  1. Only the develop branch exists and is set as the default branch
  2. Neither main nor master branches are present in the repository

The workflow triggers should be simplified to:

on:
  push:
    branches: [develop]
  pull_request:
    branches: [develop]
🔗 Analysis chain

Review branch protection and workflow trigger configuration

A few considerations regarding the workflow triggers:

  1. The presence of both main and master branches might lead to confusion. Consider standardizing on one primary branch name.
  2. Direct pushes to main/master/develop branches should typically be prevented through branch protection rules.
  3. Consider adding the pull_request_target event type if you need to handle PRs from forks securely.

Let's verify the branch protection settings:


Let me try another verification approach to check the branch structure:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check branch protection rules for main branches

# Check branch protection rules
for branch in "main" "master" "develop"; do
  echo "Checking protection rules for $branch:"
  gh api "/repos/PSMRI/Scheduler-UI/branches/$branch/protection" 2>/dev/null || echo "No protection rules found for $branch"
done

Length of output: 1311


Script:

#!/bin/bash
# Check if both main and master branches exist and their latest commits
echo "Checking branch structure:"
git branch -r

echo -e "\nChecking default branch:"
gh api /repos/PSMRI/Scheduler-UI 2>/dev/null | jq -r '.default_branch'

echo -e "\nChecking recent commits on main branches:"
for branch in "origin/main" "origin/master" "origin/develop"; do
  echo -e "\n$branch:"
  git log -n 1 --format="%h %s" $branch 2>/dev/null || echo "Branch not found"
done

Length of output: 680

Comment on lines +1 to +11
name: ESLint and NPM Audit

on:
push:
branches: [main, master, develop]
pull_request:
branches: [main, master, develop]

jobs:
lint-and-audit:
uses: PSMRI/.github/.github/workflows/lint_audit.yml@main

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Document local setup requirements and reusable workflow details

The repository has Angular-specific ESLint configuration:

  • Uses @angular-eslint/builder:lint for linting TypeScript and HTML files
  • Includes npm scripts: lint and lint:fix using the Angular CLI
  • Lints all .ts and .html files under the src directory

Consider adding:

  1. A comment block in the workflow file explaining that it uses Angular ESLint configuration
  2. A link to the reusable workflow at PSMRI/.github/.github/workflows/lint_audit.yml
  3. Instructions in the README.md for running linting locally using npm run lint and npm run lint:fix
  4. Any specific ESLint rules or configurations expected by the reusable workflow
🔗 Analysis chain

Document workflow requirements and behavior

The workflow relies entirely on a reusable workflow from another repository. Consider adding:

  1. A comment block explaining the workflow's behavior and requirements
  2. Links to the reusable workflow's documentation
  3. Required local configuration files (e.g., .eslintrc.js)
  4. Information about how to run these checks locally

Let's check for existing configuration files:


Let me verify the presence of Angular configuration files since the scripts use ng lint:


Let me check the content of angular.json for linting configuration:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for ESLint and npm configuration files

# Check for ESLint config files
echo "ESLint configuration files:"
fd -e js -e json -e yml -e yaml . -x basename {} \; | grep -i eslint || echo "No ESLint config found"

# Check for package.json and its lint-related scripts
echo -e "\nNPM scripts:"
if [ -f "package.json" ]; then
  jq '.scripts | with_entries(select(.key | contains("lint")))' package.json
else
  echo "No package.json found"
fi

Length of output: 392


Script:

#!/bin/bash
# Check for Angular-specific lint configuration
echo "Angular configuration files:"
fd -e json . -x basename {} \; | grep -E 'angular\.json|tslint\.json'

echo -e "\nTSLint rules (if exists):"
if [ -f "tslint.json" ]; then
    cat tslint.json
fi

echo -e "\nProject structure:"
fd -t f -d 1

Length of output: 445


Script:

#!/bin/bash
# Check Angular linting configuration
echo "Angular linting configuration:"
if [ -f "angular.json" ]; then
    jq '.projects[].architect.lint' angular.json
fi

echo -e "\nReadme content for any local setup instructions:"
if [ -f "README.md" ]; then
    cat README.md | grep -A 5 -i "lint"
fi

Length of output: 458

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants