WIP fix minor issues with github_pr and friends (bug 1288282) draft
authorbyron jones <glob@mozilla.com>
Wed, 27 Sep 2017 15:08:13 +0800
changeset 11720 e9a10bb0d99a9606670cc935a3cbd9df095d946d
parent 11719 c9c8686da29e38b558c4f916344b66cf02989f16
child 11721 11714c4a857758dc5afb0cb59b11fba0e594f3b7
push id1805
push userbjones@mozilla.com
push dateWed, 27 Sep 2017 07:33:57 +0000
bugs1288282
WIP fix minor issues with github_pr and friends (bug 1288282) MozReview-Commit-ID: KMbEyBj1lF9
vcssync/mozvcssync/github_pr.py
vcssync/mozvcssync/gitutil.py
--- a/vcssync/mozvcssync/github_pr.py
+++ b/vcssync/mozvcssync/github_pr.py
@@ -71,17 +71,17 @@ class GitHubPR(object):
                                  state=state)
 
     def update_or_create_pr(self, repo, user, branch, title, body,
                             title_multiple=None):
         head = "%s:%s" % (user, branch)
 
         try:
             # Find existing pull request.
-            pr = self._previous_pr(repo, head)
+            pr = self._previous_pr(repo, head, state='open')
 
             if pr:
                 logger.info('updating pull request %s' % pr.html_url)
                 # This PR may contain multiple different changes.  Update
                 # the title to reflect that, and append the new backout to
                 # the current PR body.
                 pr.update(
                     title=title_multiple or title,
@@ -169,17 +169,17 @@ class GitHubPR(object):
 
         # Create/checkout branch.
         git.cmd('checkout', '-B', branch_name)
         git.cmd('clean', '-d', '--force')
         git.cmd('merge', 'refs/upstream/master')
 
         # Apply changes.
         if patch_file:
-            git.cmd('apply', patch_file, '--verbose')
+            git.cmd('apply', patch_file)
         if callable(patch_callback):
             patch_callback(git)
 
         # Stage changes.
         git.cmd('add', '--all', '--verbose')
 
         # If there are no changes staged this means either there's actually
         # nothing changed, or the changes were pushed to github however
--- a/vcssync/mozvcssync/gitutil.py
+++ b/vcssync/mozvcssync/gitutil.py
@@ -35,20 +35,17 @@ class GitCommand(object):
         """
         assert command and len(command)
         command = ['git'] + list(command)
         if self.logger:
             command_str = ' '.join(map(pipes.quote, command))
             if self.secret:
                 command_str = command_str.replace(self.secret, 'xxx')
             self.logger.info('$ %s' % command_str)
-
-        subprocess.check_call(
-            command,
-            cwd=self.repo_path if os.path.exists(self.repo_path) else None)
+        _check_stderr(command, cwd=self.repo_path if os.path.exists(self.repo_path) else None)
 
     def get(self, *command):
         """ Run the specified command with git and return the result.
 
         eg. diff = git.cmd('diff', '--no-color')
         """
         assert command and len(command)
         command = ['git'] + list(command)
@@ -106,8 +103,24 @@ def update_git_refs(repo, reason, *actio
     for command in commands:
         p.stdin.write(command)
         p.stdin.write(b'\0')
     p.stdin.close()
     res = p.wait()
     # TODO could use a more rich exception type that captures output.
     if res:
         raise Exception('failed to update git refs')
+
+
+def _check_stderr(*popenargs, **kwargs):
+    """Same as subprocess.check_output, but captures STDERR instead of STDOUT
+    in the CalledProcessError exeption's output."""
+    if 'stderr' in kwargs:
+        raise ValueError('stderr argument not allowed, it will be overridden.')
+    process = subprocess.Popen(stderr=subprocess.PIPE, *popenargs, **kwargs)
+    unused_out, output = process.communicate()
+    retcode = process.poll()
+    if retcode:
+        print(output)
+        raise subprocess.CalledProcessError(retcode, popenargs[0],
+                                            output=output)
+    return output
+