A tool to watch a GitHub repository for changes and perform actions before and after pulling updates.
Project description
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:
pip install gitpoll
Clone the repository and install using pip:
git clone https://github.com/cc-d/gitpoll.git
cd gitpoll && pip install .
Install Dev Dependencies:
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:
gitpoll /path/to/repo -i 300
To poll for changes/execute actions once simply leave out the --interval
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:
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:
gitpoll /path/to/repo --no-pull
Force Mode
Force execution of pre and post actions even if no changes are detected:
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:
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file gitpoll-1.11.1.tar.gz
.
File metadata
- Download URL: gitpoll-1.11.1.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b16113a00a54cfc58571f9a2e332d288bd55318b9b052a260bc72c8c35e9361 |
|
MD5 | 7387e1684cc8cc4f607814770ecaf7f0 |
|
BLAKE2b-256 | 50ca63723181b7889b6697f2bde998ca08c1151263a084581416b0e3aeca654e |
File details
Details for the file gitpoll-1.11.1-py3-none-any.whl
.
File metadata
- Download URL: gitpoll-1.11.1-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a12b16f26e4399707f897fe0382a73369383d0c53bff0898cc47fdbd9e25ac1e |
|
MD5 | 23ad56fdb014201547073e357bfb4618 |
|
BLAKE2b-256 | 91274447e1f39d6d98673bad6d916b719bce46b93c1170a1c54cbbfe6d732400 |