Thank you for your interest in contributing to the CodeThreat GitHub Action! This document provides guidelines and information for contributors.
- Node.js 18+ and npm
- Git
- Access to a CodeThreat instance for testing
-
Clone the repository:
git clone https://github.com/CodeThreat/codethreat-appsec-github-action.git cd codethreat-appsec-github-action -
Install dependencies:
npm install
-
Build the action:
npm run build
-
Create a feature branch:
git checkout -b feature/your-feature-name
-
Make your changes in the
src/directory -
Test your changes:
npm run lint # Check code style npm run test # Run tests npm run build # Build the action
-
Commit your changes:
git add . git commit -m "feat: your feature description"
src/
├── index.ts # Main entry point
├── lib/
│ ├── action.ts # Core action logic
│ ├── inputs.ts # Input parsing and validation
│ ├── outputs.ts # Output setting
│ ├── logger.ts # Logging utilities
│ ├── api-client.ts # CodeThreat API client
│ └── sarif-uploader.ts # SARIF upload functionality
└── __tests__/
├── setup.ts # Test setup
└── *.test.ts # Test files
- Use TypeScript for all new code
- Follow existing naming conventions
- Add JSDoc comments for public functions
- Use meaningful variable and function names
- Keep functions focused and single-purpose
- Write tests for new functionality
- Update tests when modifying existing code
- Ensure all tests pass before submitting PR
- Aim for good test coverage
npm run test # Run all tests
npm run test -- --watch # Run tests in watch mode
npm run test -- --coverage # Generate coverage report- Inputs: Defined in
action.ymland parsed insrc/lib/inputs.ts - Outputs: Set in
src/lib/outputs.tsand defined inaction.yml - Logging: Use the Logger class for consistent output
- Error Handling: Always provide meaningful error messages
-
Build the action:
npm run build
This creates
dist/index.jswhich is the actual action entry point. -
Test locally (if possible):
# Set required environment variables export INPUT_API_KEY="your-test-key" export GITHUB_REPOSITORY="owner/repo" export GITHUB_REF="refs/heads/main" # Run the action node dist/index.js
-
Test in GitHub:
- Create a test repository
- Add the action as a workflow
- Test with real CodeThreat credentials
- Update version in
package.json - Update CHANGELOG.md with changes
- Build and commit the updated
dist/files:npm run build git add dist/ git commit -m "chore: update built action" - Create a release with appropriate tags
The action communicates with CodeThreat via REST API endpoints:
POST /api/v1/repositories/import- Import repositoryPOST /api/v1/scans/run- Execute scanGET /api/v1/scans/{id}/results- Export resultsGET /api/v1/cli/auth/validate- Validate authentication
- Always provide user-friendly error messages
- Log detailed error information in debug mode
- Handle network timeouts and API failures gracefully
- Don't expose sensitive information in error messages
- Test input parsing and validation
- Test API client functionality (with mocks)
- Test error handling scenarios
- Test output generation
- Test with real CodeThreat API (in CI)
- Test SARIF upload functionality
- Test various input combinations
- Test failure scenarios
describe('ActionInputs', () => {
it('should parse valid inputs correctly', () => {
// Mock core.getInput
(core.getInput as jest.Mock)
.mockReturnValueOnce('test-api-key')
.mockReturnValueOnce('sast,sca');
const inputs = parseInputs();
expect(inputs.apiKey).toBe('test-api-key');
expect(inputs.scanTypes).toEqual(['sast', 'sca']);
});
});- Ensure
action.ymlis in the root directory - Check that
runs.mainpoints to the correct file - Verify the action repository is public or accessible
- Run
npm run buildto create the bundleddist/index.js - Ensure all dependencies are listed in
package.json - Check that imports use correct paths
- Use test API keys and test servers when possible
- Mock API responses for unit tests
- Handle authentication errors gracefully
- Code follows the existing style
- Tests pass (
npm run test) - Linting passes (
npm run lint) - Build succeeds (
npm run build) - Documentation is updated if needed
-
dist/files are committed if code changed
Include:
- Description of changes made
- Reasoning for the changes
- Any breaking changes
- Testing performed
- Screenshots (if UI changes)
- Automated checks must pass
- Code review by maintainers
- Testing in real GitHub Action environment
- Approval and merge
Thank you for contributing to CodeThreat! 🚀