kriti21

Untitled

Apr 27th, 2018
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.86 KB | None | 0 0
  1.         revert_shortlog_regex = re.compile('^Revert\s\"[\S+\s*]*\"')
  2.         headline_regex = re.compile(
  3.             '^This reverts commit [0-9a-f]{40}')
  4.         sha_regex = re.compile(r'\b[0-9a-f]{40}\b')
  5.         if not allow_revert_commits and revert_shortlog_regex.match(shortlog):
  6.  
  7.             reverted_shortlog = shortlog.lstrip('Revert ')
  8.  
  9.             if len(body) != 0:
  10.                 body = body.strip('\n')
  11.                 blankline = body.find('\n\n')
  12.                 headline = body[:blankline] if blankline != -1 else body
  13.  
  14.                 if headline_regex.match(headline):
  15.                     commit_sha = re.search(sha_regex, headline)
  16.                     commit_sha = commit_sha.group(0)
  17.                     command = 'git log -n 1 ' + str(commit_sha)
  18.                     rstdout, rstderr = run_shell_command(command)
  19.  
  20.                     if rstderr:
  21.                         self.err('git:', repr(stderr))
  22.                         yield Result(self, 'Invalid revert commit.')
  23.  
  24.                     rstdout = rstdout.rstrip('\n')
  25.                     rpos = rstdout.find('\n')
  26.                     old_shortlog = rstdout[:rpos] if rpos != -1 else rstdout
  27.  
  28.                     if old_shortlog != reverted_shortlog:
  29.                         yield Result(self, 'Shortlog of revert commit does \
  30.                                            not match the original commit.')
  31.  
  32.                 reason = body[blankline+1:] if blankline != -1 else ''
  33.  
  34.                 if len(reason) == 0:
  35.                     yield Result(self, 'Revert commit does not have a reason.')
  36.  
  37.                 elif len(reason) > 50:
  38.                     yield Result(self, 'Reason of revert commit contains too \
  39.                                        long lines.')
  40.  
  41.             else:
  42.                 yield Result(self, 'Revert commit does not have a reason.')
  43.  
  44.             return
Add Comment
Please, Sign In to add comment