Esempio n. 1
0
 def _has_diff_expression(self):
     diffs = self._get_diffs_from_current()
     exp_dict = {}
     for target_diff in self.target_diffs:
         if type(target_diff) is not dict:
             raise ConfigError(
                 'Invalid diff configuration specified:\n{}'.format(
                     yaml.dump(target_diff)))
         id = get_or_default(target_diff, ID, None, str)
         if id is not None:
             path = get_or_default(target_diff, PATH, None, str)
             if path is not None:
                 for detected_diff in diffs:
                     if re.match(target_diff[PATH],
                                 detected_diff.a_rawpath.decode(UTF8)):
                         LOG.info('[{}] path pattern {} matches {}'.format(
                             self.id, target_diff[PATH],
                             detected_diff.a_rawpath.decode(UTF8)))
                         content = get_or_default(target_diff, CONTENT,
                                                  None, str)
                         if content is not None:
                             if id not in exp_dict or not exp_dict[id]:
                                 exp_dict[id] = self._has_content_diff(
                                     content, detected_diff)
                         else:
                             exp_dict[id] = True
                 if id not in exp_dict:
                     exp_dict[id] = False
     return evaluate_expression(self.expression, exp_dict)
Esempio n. 2
0
 def _has_diff(self):
     if COMMIT not in self.checkpoint:
         LOG.warning('[{}] no checkpoint found, pipe will be executed')
         return True
     if self.expression is not None:
         LOG.info('[{}] detecting through expression evaluation: {}'.format(
             self.id, self.expression))
         return self._has_diff_expression()
     else:
         LOG.info('[{}] detecting any of the diffs'.format(self.id))
         return self._has_diff_all()
Esempio n. 3
0
 def _get_diffs_from_current(self):
     if COMMIT not in self.checkpoint:
         return None
     found_diffs = list()
     commit_found = False
     for commit in self.repo.iter_commits():
         diffs = self.repo.head.commit.diff(commit)
         for diff in diffs:
             found_diffs.append(diff)
         commit_found = str(commit) == self.checkpoint[COMMIT]
         if commit_found:
             break
     if not commit_found:
         LOG.warn('[{}] traversed all git log, checkpoint commit not found'.
                  format(self.id))
     LOG.info('[{}] detected diffs since last run:\n{}\n'.format(
         self.id,
         ''.join(f'\n\t {l.a_rawpath.decode(UTF8)}' for l in found_diffs)))
     return found_diffs
Esempio n. 4
0
 def evaluate(self):
     if self.result is None:
         if self.active_branch is not None and str(
                 self.repo.active_branch) != self.active_branch:
             LOG.info(
                 '[{}] Not on active branch, conditional disabled'.format(
                     self.id))
             self.result = False
             return self.result
         if self.target_branch is not None and str(
                 self.repo.active_branch) != self.target_branch:
             previous_branch = str(self.repo.active_branch)
             try:
                 LOG.info('[{}] checking out target branch {}'.format(
                     self.id, self.target_branch))
                 self.repo.git.checkout(self.target_branch)
                 self.result = self._has_diff()
             finally:
                 self.repo.git.checkout(previous_branch)
         else:
             self.result = self._has_diff()
     return self.result
Esempio n. 5
0
 def _has_diff_all(self):
     diffs = self._get_diffs_from_current()
     for target_diff in self.target_diffs:
         if type(target_diff) is not dict:
             raise ConfigError(
                 'Invalid diff configuration specified:\n{}'.format(
                     yaml.dump(target_diff)))
         for detected_diff in diffs:
             path = get_or_default(target_diff, PATH, None, str)
             if path is not None:
                 if re.match(path, detected_diff.a_rawpath.decode(UTF8)):
                     LOG.info('[{}] path pattern {} matches {}'.format(
                         self.id, path,
                         detected_diff.a_rawpath.decode(UTF8)))
                     content = get_or_default(target_diff, CONTENT, None,
                                              str)
                     if content is not None:
                         if self._has_content_diff(content, detected_diff):
                             return True
                     else:
                         return True
     return False
Esempio n. 6
0
 def create_checkpoint(self):
     LOG.info('[{}] New checkpoint {}'.format(self.id, self.new_checkpoint))
     return {COMMIT: self.new_checkpoint}