-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from gisce/convert_github-hooks_to_package
Convert GitHub hooks to package
- Loading branch information
Showing
20 changed files
with
335 additions
and
407 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
[run] | ||
source = | ||
./hooks | ||
./listener.py | ||
source = ./hookshub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
import listener | ||
import hooks |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
from __future__ import print_function | ||
from __future__ import unicode_literals | ||
|
||
import sys | ||
import json | ||
import tempfile | ||
import shutil | ||
from subprocess import Popen, PIPE | ||
from os.path import join | ||
|
||
|
||
class TempDir(object): | ||
def __init__(self): | ||
self.dir = tempfile.mkdtemp() | ||
|
||
def __enter__(self): | ||
return self | ||
|
||
def __exit__(self, exc_type, exc_val, exc_tb): | ||
shutil.rmtree(self.dir) | ||
|
||
|
||
# Carrega dels arguments. Conte els detalls del event | ||
def arguments(): | ||
with open(sys.argv[1], 'r') as jsf: | ||
payload = json.loads(jsf.read()) | ||
event = sys.argv[2] | ||
return payload, event | ||
|
||
payload, event = arguments() | ||
|
||
output = '' | ||
url = payload['ssh_url'] | ||
repo_name = payload['repo-name'] | ||
branch_name = payload['branch-name'] | ||
output += ('Rebut event de <{}> |'.format(event)) | ||
|
||
# Directori on tenim la documentació en format html | ||
docs_dir = '/tmp/builtin/powerp' | ||
|
||
# Mirem de quina branca es tracta i actualitzem el directori del build: | ||
# Si es master el directori sera /powerp/ | ||
# Altrament el directori sera /powerp_XXX/ | ||
# on XXX es el nom de la branca | ||
if branch_name != 'master' and branch_name != 'None': | ||
docs_dir += "_{}".format(branch_name) | ||
|
||
# Creem un directori temporal que guardarà les dades del clone | ||
# Per actualitzar la pagina de la documentacio | ||
with TempDir() as temp: | ||
output += ('Creat Directori temporal: {} |'.format(temp.dir)) | ||
|
||
# Primer clonem el repositori | ||
|
||
# Canviarà la forma de clonar segons tinguem o no branca: | ||
if branch_name != 'None': | ||
output += "Clonant el repositori '{0}', amb la branca '{1}' ...".format( | ||
repo_name, branch_name | ||
) | ||
command = 'git clone {0} --branch {1}'.format(url, branch_name) | ||
else: | ||
output += "Clonant el repositori '{0}' ...".format(repo_name) | ||
command = 'git clone {}'.format(url) | ||
|
||
new_clone = Popen( | ||
command.split(), cwd=temp.dir, stdout=PIPE, stderr=PIPE | ||
) | ||
out, err = new_clone.communicate() | ||
|
||
if new_clone.returncode != 0: | ||
# Could not clone >< => ABORT | ||
output += 'FAILED TO CLONE: {0}::{1}'.format(out, err) | ||
print(output) | ||
exit(-1) | ||
|
||
output += 'OK |' | ||
|
||
# Accedim al directori del clone utilitzant el nom del repositori | ||
|
||
clone_dir = join(temp.dir, repo_name) | ||
|
||
# Instalem dependencies | ||
|
||
output += 'Instal.lant dependencies...' | ||
command = 'pip install -r requirements.txt' | ||
dependencies = Popen( | ||
command.split(), cwd=clone_dir, stdout=PIPE, stderr=PIPE | ||
) | ||
out, err = dependencies.communicate() | ||
output += 'OK |' | ||
|
||
# Fem build al directori on tenim la pagina des del directori del clone | ||
|
||
command = 'mkdocs build -d {} --clean'.format(docs_dir) | ||
output += 'Building mkdocs on {}...'.format(docs_dir) | ||
new_build = Popen( | ||
command.split(), cwd=clone_dir, stdout=PIPE, stderr=PIPE | ||
) | ||
out, err = new_build.communicate() | ||
if new_build.returncode != 0: | ||
output += 'FAILED TO BUILD: {0}::{1}'.format(out, err) | ||
print(output) | ||
exit(-1) | ||
output += 'OK |' | ||
|
||
print(output) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.