gitpoll 1.11.1
A tool to watch a GitHub repository for changes and perform actions before and after pulling updates.
Requires Python: >=3.5

# gitpoll

## Overview

`gitpoll` monitors the remote equivalent of a local Git repository branch for changes. It checks the repository at specified intervals, executing scripts or shell commands before and after pulling updates, suitable for simple automation of deployment or other tasks.

## Features

- Monitors a Git repository for changes at specified intervals.
- Executes pre-action and post-action scripts or shell commands before/atfer pulling changes.
- All behavior is configurable via command-line options.

## Installation

### Requirements

- Python 3.5 or higher

### Setup

#### Install from PyPI using pip:

```bash
pip install gitpoll
```

##### Clone the repository and install using pip:

```bash
git clone https://github.com/cc-d/gitpoll.git
cd gitpoll && pip install .
```

##### Install Dev Dependencies:

```bash
pip install gitpoll[dev]
```

## Usage

```
usage: gitpoll [-h] [-i INTERVAL] [-n] [-p PRE_ACTION] [-P POST_ACTION] [-f] [repo_path]

Monitors a Git repository for changes and executes scripts before and after pulling updates.

positional arguments:
  repo_path             Path to the Git repository to monitor.

options:
  -h, --help            show this help message and exit
  -i INTERVAL, --interval INTERVAL
                        Interval in seconds to check for changes.
  -n, --no-pull         Do not pull changes from the repository.
  -p PRE_ACTION, --pre-action PRE_ACTION
                        Command or path to the pre-action shell script or command.
  -P POST_ACTION, --post-action POST_ACTION
                        Command or path to the post-action shell script or command.
  -f, --force           Force execution pre and post actions regardless of changes.
```

### Environment Variables

- `GITPOLL_LOG_LEVEL`: Set the log level (default: `INFO`)

### Basic Usage

To monitor a repository and execute actions based on changes:

```bash
gitpoll /path/to/repo -i 300
```

To poll for changes/execute actions once simply leave out the --interval

```bash
mym2@Carys-MacBook-Pro gitpoll % gitpoll ~/gitpoll
Running once...
05-06 16:47:50 INFO main:_log_exit Single run completed.
```

### Advanced Usage

Monitor a repository at `/home/user/myrepo`, check every 300 seconds, and run specified scripts:

```bash
gitpoll /home/user/myrepo -i 300 -p /path/to/pre_script.sh -P /path/to/post_script.sh
```

### Pre/Post Actions

These are executed as if being executed from the current shell gitpoll is running within. Either a `.sh` script location or the shell command itself.

```
-p test.sh
```

is valid as well as

```
-p 'sudo systemctl restart x'
```

### No-Pull Mode

Execute pre and post actions without pulling changes from the repository:

```bash
gitpoll /path/to/repo --no-pull
```

### Force Mode

Force execution of pre and post actions even if no changes are detected:

```bash
gitpoll /path/to/repo --force
```

## Testing

Tests are not complete, I wrote these to have tests period, I'll probably redo them later.

Install the dev dependencies and run the tests:

```bash
pip install gitpoll[dev]
```

```
tests.py ..................   [100%]

---------- coverage: platform darwin, python 3.11.5-final-0 ----------
Name                  Stmts   Miss  Cover
-----------------------------------------
gitpoll/__init__.py       1      0   100%
gitpoll/args.py          11      0   100%
gitpoll/config.py         6      0   100%
gitpoll/git.py           24      2    92%
gitpoll/log.py           13      0   100%
gitpoll/main.py          58     11    81%
gitpoll/shell.py         48      5    90%
gitpoll/version.py        1      0   100%
-----------------------------------------
TOTAL                   162     18    89%
```

## Contributing

Contributions are welcome. Please fork the repository and submit pull requests, bug reports, feature requests, etc.

## License

MIT