Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gitpoll-1.11.1.tar.gz (8.7 kB view hashes)

Uploaded Source

Built Distribution

gitpoll-1.11.1-py3-none-any.whl (8.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page