Skip to content

Commit 48874a1

Browse files
committed
new feature: CLI has been born
1 parent 3691de3 commit 48874a1

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ source /path/to/venv/bin/activate
3333
Settings
3434
--------
3535

36+
Extra CLI features
37+
------------------
38+
39+
To force both the pull and the execution of commands without a deployment, you can use
40+
the built-in `wh-git-trigger` command. Example usage:
41+
42+
wh-git-trigger /path/to/setings.yaml myrepoentry
43+
44+
This will force the git pull and execute the commands. Future versions of this tool will
45+
include more fine-grain control --e.g. avoid fetch, dry-run, display status information...
3646

3747
Implementation details
3848
----------------------

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="webhooks_git_automata",
8-
version="0.0.1",
8+
version="0.0.2",
99
author="Alex Barcelo",
1010
author_email="[email protected]",
1111
description="Webhook receiver for Git deployments",
@@ -17,6 +17,7 @@
1717
entry_points={
1818
'console_scripts': [
1919
'wh-gitd = webhooks_git_automata.webhooks:main_func',
20+
'wh-git-trigger = webhooks_git_automata.webhooks:manual_trigger',
2021
],
2122
},
2223
classifiers=[

webhooks_git_automata/automata.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ class MetaAutomata(type):
1010
1111
When Automata[<repo>, <branch>] is called, the corresponding Automaton
1212
instance is returned ready to be used by the worker.
13+
14+
The alias Automata[<name_as_in_yaml>] is also stored, and used by the
15+
manual trigger entrypoint. See also webhooks.manual_trigger
1316
"""
1417
actions = dict()
1518

@@ -23,7 +26,11 @@ def load_config(cls, actions):
2326
repo = automaton.pop("repo", name)
2427
branch = automaton.pop("branch", "master")
2528

26-
cls.actions[repo, branch] = cls(automaton, repo, branch)
29+
instance = cls(automaton, repo, branch)
30+
31+
# Store both lookups
32+
cls.actions[repo, branch] = instance
33+
cls.actions[name] = instance
2734

2835

2936
class Automata(object, metaclass=MetaAutomata):

webhooks_git_automata/webhooks.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from .settings import Configuration
99
from .worker import async_worker
10+
from .automata import Automata
1011
from . import providers
1112

1213

@@ -39,3 +40,18 @@ def main_func():
3940
app.add_url_rule('/webhook', 'webhook', webhook, methods=['POST'])
4041
app.run(host=Configuration.listen_ip,
4142
port=Configuration.listen_port)
43+
44+
45+
def manual_trigger():
46+
if len(sys.argv) != 3:
47+
raise RuntimeError("You should provide the path to the settings YAML file as first argument "
48+
"and the repository entry name (YAML key) that will be triggered")
49+
50+
Configuration.load(sys.argv[1])
51+
try:
52+
automaton = Automata[sys.argv[2]]
53+
except KeyError:
54+
raise RuntimeError("Unrecognized repository name '%s'" % sys.argv[2])
55+
56+
automaton.pull_sources()
57+
automaton.perform_commands()

0 commit comments

Comments
 (0)