Skip to content

Commit

Permalink
feat: initial
Browse files Browse the repository at this point in the history
  • Loading branch information
yigitcukuren committed Aug 24, 2024
0 parents commit f2b80be
Show file tree
Hide file tree
Showing 18 changed files with 1,002 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: CI

on:
pull_request:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
extensions: mbstring, dom
coverage: none

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest --no-interaction

- name: Check code style
run: composer check-cs

- name: Analyze code with PHPStan
run: composer analyse

- name: Run PHPUnit tests
run: composer test
33 changes: 33 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Composer dependencies
/vendor/
composer.lock

# PHPStorm / JetBrains IDEs
/.idea/
/*.iml

# VSCode
.vscode/

# Coverage reports
/coverage/
/.clover
.php_cs.cache
/.php_cs.cache
/.php_cs_fixer.cache

# Log files
*.log

# Cache and temp files
*.cache
*.tmp

# OS-specific files
.DS_Store
Thumbs.db

# Environment variables
.env
.env.local
.env.*.local
25 changes: 25 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

use PhpCsFixer\Config;
use PhpCsFixer\Finder;

$finder = Finder::create()
->in(__DIR__ . '/') // Scans the src directory for PHP files
->name('*.php')
->exclude('vendor'); // Excludes vendor files

return (new Config())
->setRules([
'@PSR12' => true, // Enforces PSR12 standards
'array_syntax' => ['syntax' => 'short'], // Enforces short array syntax
'binary_operator_spaces' => [
'default' => 'single_space'
],
'blank_line_after_namespace' => true, // Adds blank line after the namespace declaration
'blank_line_after_opening_tag' => true,
'no_unused_imports' => true, // Removes unused imports
'ordered_imports' => ['sort_algorithm' => 'alpha'], // Orders imports alphabetically
'phpdoc_align' => ['align' => 'vertical'], // Aligns PHPDoc tags vertically
'single_trait_insert_per_statement' => true // Enforces one trait per statement
])
->setFinder($finder);
9 changes: 9 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The MIT License (MIT)

Copyright (c) Yigit Cukuren [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
155 changes: 155 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# TimeLock

**TimeLock** is a command-line tool designed to help developers identify files in a Git repository that have remained unchanged since a specific date. It can be configured to exclude specific authors, paths, and file types using regex patterns.

## Table of Contents

- [Features](#features)
- [Installation](#installation)
- [Usage](#usage)
- [Configuration](#configuration)
- [Examples](#examples)
- [Example Output](#example-output)
- [Running Tests](#running-tests)
- [Contributing](#contributing)
- [License](#license)

## Features

- **File Detection**: Detects files in a Git repository that have not changed since a specified date.
- **Author Exclusion**: Exclude files from specific authors.
- **Path and Regex Exclusions**: Exclude files based on paths or regex patterns.
- **Output Formats**: Supports both table and JSON output formats.
- **Customizable**: Easily extendable to support other version control systems.

## Installation

To install **TimeLock** via Composer, run the following command:

```bash
composer require timelock/timelock
```

After installation, the `timelock` binary will be available in the `vendor/bin` directory.

## Usage

The `check` command is the main CLI tool provided by TimeLock. Below is an example of how to use it:

```bash
vendor/bin/timelock check --config=path/to/timelock.yml
```

### Command-Line Options

- `path` (optional): The directory path to check. Defaults to the current directory.
- `--config` (optional): The path to the configuration file. Defaults to `timelock.yml` in the current directory.
- `--output-format` (optional): The output format (`table` or `json`). Defaults to `table`.

## Configuration

TimeLock is configured using a YAML file (`timelock.yml`). Below is an example configuration file:

```yaml
since: '5 years ago' # Files unchanged since this date will be flagged
excludeAuthors: # Authors to exclude from the check
- 'John Doe'
- 'Jane Smith'
exclude: # Paths to exclude from the check
- 'vendor/'
- 'tests/'
excludeRegex: # Regex patterns to exclude from the check
- '/.*Controller\.php$/'
vcs: 'git' # Version control system to use (default is 'git')
```
### Configuration Options
- `since`: A date string or timestamp to check files against.
- `excludeAuthors`: A list of author names to exclude.
- `exclude`: A list of paths to exclude.
- `excludeRegex`: A list of regex patterns to exclude specific files.
- `vcs`: The version control system to use. Currently supports `git`.

## Examples

### Basic Usage

Check for files unchanged in the current directory:

```bash
vendor/bin/timelock check
```

### Custom Configuration

Use a specific configuration file:

```bash
vendor/bin/timelock check --config=/path/to/your-config.yml
```

### JSON Output

Get the output in JSON format:

```bash
vendor/bin/timelock check --output-format=json
```

### Example Output

Here’s an example of what the output might look like when using the `table` format:

```bash
vendor/bin/timelock check --config=path/to/timelock.yml
```

Output:

```
+------------+-----------+---------------------+---------+
| File | Author | Last Modified | Changes |
+------------+-----------+---------------------+---------+
| file1.txt | John Doe | 2017-06-01 12:00:00 | 1 |
+------------+-----------+---------------------+---------+
| file2.txt | Jane Doe | 2019-03-15 15:30:00 | 3 |
+------------+-----------+---------------------+---------+
Check completed.
Execution time: 0.42 seconds
```

In this example:

- `File`: The name of the file that has been unchanged since the specified date.
- `Author`: The author of the last commit to that file.
- `Last Modified`: The date and time when the file was last modified.
- `Changes`: The number of changes made to the file.

## Running Tests

To run the test suite, use PHPUnit. If you haven’t installed PHPUnit globally, you can use the local installation:

```bash
composer test
```

The tests are located in the `tests` directory and cover the core functionality of the TimeLock tool, including Git integration and configuration handling.

## Contributing

We welcome contributions! Here’s how you can get involved:

1. Fork the repository.
2. Create a new branch (`git checkout -b feature/your-feature`).
3. Make your changes.
4. Commit your changes (`git commit -m 'Add some feature'`).
5. Push to the branch (`git push origin feature/your-feature`).
6. Open a pull request.

Please make sure to write tests for your changes and ensure all existing tests pass.

## License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
20 changes: 20 additions & 0 deletions bin/timelock
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env php
<?php
use TimeLock\VCSFactory;
foreach ([__DIR__ . '/../../../autoload.php', __DIR__ . '/../vendor/autoload.php'] as $file) {
if (file_exists($file)) {
require $file;
break;
}
}

use TimeLock\Command\CheckCommand;
use Symfony\Component\Console\Application;

$application = new Application('TimeLock', '0.1.0');

// Register your command here
$application->add(new CheckCommand(new VCSFactory));

// Run the application
$application->run();
38 changes: 38 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "timelock/timelock",
"description": "A PHP package to find files unchanged since a specified date.",
"type": "library",
"version": "0.1.0",
"license": "MIT",
"autoload": {
"psr-4": {
"TimeLock\\": "src/"
}
},
"authors": [
{
"name": "Yigit Cukuren",
"email": "[email protected]"
}
],
"require": {
"php": ">=8.2",
"symfony/yaml": "^7.1",
"symfony/console": "^7.1",
"symfony/process": "^7.1"
},
"require-dev": {
"phpstan/phpstan": "^1.11",
"phpunit/phpunit": "^11.3",
"friendsofphp/php-cs-fixer": "^3.62"
},
"scripts": {
"check-cs": "php-cs-fixer fix --dry-run --diff",
"fix-cs": "php-cs-fixer fix",
"analyse": "phpstan analyse",
"test": "phpunit"
},
"bin": [
"bin/timelock"
]
}
4 changes: 4 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
parameters:
level: 5
paths:
- src
13 changes: 13 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.3/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true">
<testsuites>
<testsuite name="TimeLock Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
Loading

0 comments on commit f2b80be

Please sign in to comment.