Review Board 1.7.22


Patch for DRILL-241

Review Request #14331 - Created Sept. 25, 2013 and submitted

Timothy Chen
DRILL-241
Reviewers
drill-git
drill-git
Testing review board tool

 

Diff revision 2 (Latest)

1 2
1 2

  1. drill-patch-review.py: Loading...
drill-patch-review.py
New File

    
   
1
#!/usr/bin/env python

    
   
2

   

    
   
3
# Modified based on Kafka's patch review tool

    
   
4

   

    
   
5
import argparse

    
   
6
import sys

    
   
7
import os 

    
   
8
import time

    
   
9
import datetime

    
   
10
import tempfile

    
   
11
from jira.client import JIRA

    
   
12

   

    
   
13
def get_jira():

    
   
14
  options = {

    
   
15
    'server': 'https://issues.apache.org/jira'

    
   
16
  }

    
   
17
  # read the config file

    
   
18
  home=jira_home=os.getenv('HOME')

    
   
19
  home=home.rstrip('/')

    
   
20
  jira_config = dict(line.strip().split('=') for line in open(home + '/jira.ini'))

    
   
21
  jira = JIRA(options,basic_auth=(jira_config['user'], jira_config['password']))

    
   
22
  return jira 

    
   
23

   

    
   
24
def main():

    
   
25
  ''' main(), shut up, pylint '''

    
   
26
  popt = argparse.ArgumentParser(description='Drill patch review tool')

    
   
27
  popt.add_argument('-b', '--branch', action='store', dest='branch', required=True, help='Tracking branch to create diff against')

    
   
28
  popt.add_argument('-j', '--jira', action='store', dest='jira', required=True, help='JIRA corresponding to the reviewboard')

    
   
29
  popt.add_argument('-s', '--summary', action='store', dest='summary', required=False, help='Summary for the reviewboard')

    
   
30
  popt.add_argument('-d', '--description', action='store', dest='description', required=False, help='Description for reviewboard')

    
   
31
  popt.add_argument('-r', '--rb', action='store', dest='reviewboard', required=False, help='Review board that needs to be updated')

    
   
32
  popt.add_argument('-t', '--testing-done', action='store', dest='testing', required=False, help='Text for the Testing Done section of the reviewboard')

    
   
33
  popt.add_argument('-db', '--debug', action='store_true', required=False, help='Enable debug mode')

    
   
34
  popt.add_argument('-rbu', '--reviewboard-user', action='store', dest='reviewboard_user', required=True, help='Review board user name')

    
   
35
  popt.add_argument('-rbp', '--reviewboard-password', action='store', dest='reviewboard_password', required=True, help='Review board user password')

    
   
36
  opt = popt.parse_args()

    
   
37

   

    
   
38
  patch_file=tempfile.gettempdir() + "/" + opt.jira + ".patch"

    
   
39
  if opt.reviewboard:

    
   
40
    ts = time.time()

    
   
41
    st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d_%H:%M:%S')

    
   
42
    patch_file=tempfile.gettempdir() + "/" + opt.jira + '_' + st + '.patch'

    
   
43
  

    
   
44
  git_remote_update="git remote update"

    
   
45
  print "Updating your remote branches to pull the latest changes"

    
   
46
  p=os.popen(git_remote_update)

    
   
47
  p.close()

    
   
48

   

    
   
49
  rb_command="post-review --publish --tracking-branch " + opt.branch + " --target-groups=drill-git --bugs-closed=" + opt.jira

    
   
50
  rb_command=rb_command + " --username " + opt.reviewboard_user + " --password " + opt.reviewboard_password

    
   
51

   

    
   
52
  if opt.debug:

    
   
53
    rb_command=rb_command + " --debug" 

    
   
54
  summary="Patch for " + opt.jira

    
   
55
  if opt.summary:

    
   
56
    summary=opt.summary

    
   
57
  rb_command=rb_command + " --summary \"" + summary + "\""

    
   
58
  if opt.description:

    
   
59
    rb_command=rb_command + " --description \"" + opt.description + "\""

    
   
60
  if opt.reviewboard:

    
   
61
    rb_command=rb_command + " -r " + opt.reviewboard

    
   
62
  if opt.testing:

    
   
63
    rb_command=rb_command + " --testing-done=" + opt.testing

    
   
64
  if opt.debug:

    
   
65
    print rb_command

    
   
66
  p=os.popen(rb_command)

    
   
67
  rb_url=""

    
   
68
  for line in p:

    
   
69
    print line

    
   
70
    if line.startswith('http'):

    
   
71
      rb_url = line

    
   
72
    elif line.startswith("There don't seem to be any diffs"):

    
   
73
      print 'ERROR: Your reviewboard was not created/updated since there was no diff to upload. The reasons that can cause this issue are 1) Your diff is not checked into your local branch. Please check in the diff to the local branch and retry 2) You are not specifying the local branch name as part of the --branch option. Please specify the remote branch name obtained from git branch -r'

    
   
74
      p.close()

    
   
75
      sys.exit(1)

    
   
76
    elif line.startswith("Your review request still exists, but the diff is not attached") and not opt.debug:

    
   
77
      print 'ERROR: Your reviewboard was not created/updated. Please run the script with the --debug option to troubleshoot the problem'

    
   
78
      p.close()

    
   
79
      sys.exit(1)

    
   
80
  p.close()

    
   
81
  if opt.debug: 

    
   
82
    print 'rb url=',rb_url

    
   
83
 

    
   
84
  git_command="git diff " + opt.branch + " > " + patch_file

    
   
85
  if opt.debug:

    
   
86
    print git_command

    
   
87
  p=os.popen(git_command)

    
   
88
  p.close()

    
   
89

   

    
   
90
  print 'Creating diff against', opt.branch, 'and uploading patch to JIRA',opt.jira

    
   
91
  jira=get_jira()

    
   
92
  issue = jira.issue(opt.jira)

    
   
93
  attachment=open(patch_file)

    
   
94
  jira.add_attachment(issue,attachment)

    
   
95
  attachment.close()

    
   
96

   

    
   
97
  comment="Created reviewboard " 

    
   
98
  if not opt.reviewboard:

    
   
99
    print 'Created a new reviewboard ',rb_url

    
   
100
  else:

    
   
101
    print 'Updated reviewboard',opt.reviewboard

    
   
102
    comment="Updated reviewboard "

    
   
103

   

    
   
104
  comment = comment + rb_url 

    
   
105
  jira.add_comment(opt.jira, comment)

    
   
106

   

    
   
107
if __name__ == '__main__':

    
   
108
  sys.exit(main())

    
   
109

   
  1. drill-patch-review.py: Loading...