summaryrefslogtreecommitdiffstats
path: root/apex/build_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'apex/build_utils.py')
-rw-r--r--apex/build_utils.py50
1 files changed, 42 insertions, 8 deletions
diff --git a/apex/build_utils.py b/apex/build_utils.py
index c9d8472e..7457e561 100644
--- a/apex/build_utils.py
+++ b/apex/build_utils.py
@@ -27,7 +27,7 @@ def get_change(url, repo, branch, change_id):
:param repo: name of repo
:param branch: branch of repo
:param change_id: SHA change id
- :return: change if found and not abandoned, closed, or merged
+ :return: change if found and not abandoned, closed
"""
rest = GerritRestAPI(url=url)
change_path = "{}~{}~{}".format(quote_plus(repo), quote_plus(branch),
@@ -37,12 +37,8 @@ def get_change(url, repo, branch, change_id):
try:
assert change['status'] not in 'ABANDONED' 'CLOSED', \
'Change {} is in {} state'.format(change_id, change['status'])
- if change['status'] == 'MERGED':
- logging.info('Change {} is merged, ignoring...'
- .format(change_id))
- return None
- else:
- return change
+ logging.debug('Change found: {}'.format(change))
+ return change
except KeyError:
logging.error('Failed to get valid change data structure from url '
@@ -90,6 +86,44 @@ def clone_fork(args):
logging.info('Checked out commit:\n{}'.format(ws.head.commit.message))
+def strip_patch_sections(patch, sections=['releasenotes', 'tests']):
+ """
+ Removes patch sections from a diff which contain a file path
+ :param patch: patch to strip
+ :param sections: list of keywords to use to strip out of the patch file
+ :return: stripped patch
+ """
+
+ append_line = True
+ tmp_patch = []
+ for line in patch.split("\n"):
+ if re.match('diff\s', line):
+ for section in sections:
+ if re.search(section, line):
+ logging.debug("Stripping {} from patch: {}".format(
+ section, line))
+ append_line = False
+ break
+ else:
+ append_line = True
+ if append_line:
+ tmp_patch.append(line)
+ return '\n'.join(tmp_patch)
+
+
+def is_path_in_patch(patch, path):
+ """
+ Checks if a particular path is modified in a patch diff
+ :param patch: patch diff
+ :param path: path to check for in diff
+ :return: Boolean
+ """
+ for line in patch.split("\n"):
+ if re.match('^diff.*{}'.format(path), line):
+ return True
+ return False
+
+
def get_patch(change_id, repo, branch, url=con.OPENSTACK_GERRIT):
logging.info("Fetching patch for change id {}".format(change_id))
change = get_change(url, repo, branch, change_id)
@@ -100,7 +134,7 @@ def get_patch(change_id, repo, branch, url=con.OPENSTACK_GERRIT):
change_id)
patch_url = "changes/{}/revisions/{}/patch".format(change_path,
current_revision)
- return rest.get(patch_url)
+ return strip_patch_sections(rest.get(patch_url))
def get_parser():