Created
April 8, 2016 15:08
-
-
Save elukey/0a7bcaf0e3d2ee5ae44afe2897fd660d to your computer and use it in GitHub Desktop.
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
diff --git a/puppet_compiler/prepare.py b/puppet_compiler/prepare.py | |
index 6a61b21..76ab043 100644 | |
--- a/puppet_compiler/prepare.py | |
+++ b/puppet_compiler/prepare.py | |
@@ -2,6 +2,7 @@ from contextlib import contextmanager | |
import json | |
import subprocess | |
import os | |
+import re | |
import shutil | |
import requests | |
from puppet_compiler import _log | |
@@ -128,20 +129,57 @@ class ManageCode(object): | |
json_data = change.text.split("\n")[-2:][0] | |
res = json.loads(json_data) | |
revision = res["revisions"].values()[0]["_number"] | |
+ project = res["project"] | |
ref = 'refs/changes/%02d/%d/%d' % ( | |
self.change_id % 100, | |
self.change_id, | |
revision) | |
_log.debug( | |
- 'Downloading patch for change %d, revision %d', | |
- self.change_id, revision) | |
- git.fetch('-q', 'https://gerrit.wikimedia.org/r/operations/puppet', | |
- ref) | |
- git.checkout('FETCH_HEAD') | |
- git.pull('--rebase', 'origin', 'production') | |
+ 'Downloading patch for project %s, change %d, revision %d', | |
+ project, self.change_id, revision) | |
+ | |
+ # Assumption: | |
+ # Gerrit suported repo names and branches: | |
+ # 1) operations/puppet - origin/production | |
+ # 2) operations/puppet/submodulename - origin/master | |
+ if project == 'operations/puppet': | |
+ git.fetch('-q', 'https://gerrit.wikimedia.org/r/operations/puppet', | |
+ ref) | |
+ git.checkout('FETCH_HEAD') | |
+ git.pull('--rebase', 'origin', 'production') | |
+ else: | |
+ _log.debug('The change has not been filed for the main puppet repo.\ | |
+ Checking submodule repository matching the regex operations/puppet/(\w*)') | |
+ submodule_matcher = re.search('operations/puppet/(\w*)', project) | |
+ if submodule_matcher: | |
+ submodule_name = submodule_matcher.group(1) | |
+ submodule_path = 'modules/' + submodule_name | |
+ _log.debug('Submodule repository name: %s path: %s', | |
+ submodule_name, submodule_path) | |
+ base_repo_dir = os.getcwd | |
+ if os.path.exists(base_repo_dir + '/' + submodule_path): | |
+ _log.debug('Change directory to: %s', | |
+ base_repo_dir + '/' + submodule_path_) | |
+ os.chdir(base_repo_dir + '/' + submodule_path) | |
+ git.fetch('-q', 'https://gerrit.wikimedia.org/r/' + project, | |
+ ref) | |
+ git.checkout('FETCH_HEAD') | |
+ git.pull('--rebase', 'origin', 'master') | |
+ _log.debug('Change directory to: %s', base_repo_dir) | |
+ os.chdir(base_repo_dir) | |
+ else: | |
+ _log.debug('Cannot access the submodule directory: %s', | |
+ base_repo_dir + '/' + submodule_path) | |
+ return | |
+ else: | |
+ _log.debug('No gerrit repository found!') | |
+ return | |
+ | |
# Update submodules according to the last hash of the parent repo. | |
+ _log.debug('Running submodule init') | |
git.submodule('update', '--init') | |
+ | |
def _sh(command): | |
try: | |
subprocess.check_call(command, shell=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment