Bitbucket post-receive hook

Review Request #5653 — Created March 22, 2014 and submitted

b.ramnani
Review Board
master
5596
891b835...
reviewboard
anselina, chipx86, david, mike_conley, smacleod

This is a Bitbucket post-receive hook that will automatically close review requests as "submitted" after a push. To determine which review requests should be closed, it scans through each commit's commit message for the following strings (case-insensitive): "Reviewed at <reviewboard_url>/r/<id>" or "Review request #<id>". The regex used for this can be overriden in settings_local.py.

Basic testing on a git repo performed. Test passed successfully (see screenshot).

All tests carried out on both mercurial and git repos.

Tests:
1) Close an open review request. [PASSED]
2) Try to close a review request that already has been closed as submitted. (Logged a warning saying that the review request has already been submitted). [PASSED]
3) Try to close a discarded review request. (Marked the review request as submitted) [PASSED]
4) Push without a review request id in commit message. (Error logged that the request id does not exist). [PASSED]
5) Push with a non existent request id in the commit message. (Error logged as Review request id does not exist.) [PASSED]


Description From Last Updated

This can be combined to a single import (http://docs.python.org/2/reference/simple_stmts.html#the-import-statement)

TO tomiaijo

Change this to: repository_url_patterns = patterns( '', url(r'^hooks/post-receive/$', 'reviewboard.hostingsvcs.tests.hosting_service_url_test_view') )

anselinaanselina

Trailing whitespace

TO tomiaijo

You should delete these lines because the URLs are already dynamically generated.

anselinaanselina

Mixed tabs and whitespaces

TO tomiaijo

Only for temporary testing

B. b.ramnani

You didn't add any logging, so this import can go away.

daviddavid

This isn't used.

daviddavid

This line isn't necessary.

daviddavid

If review_id_to_commits is an empty map, close_all_review_requests will be a no-op. Therefore I think you can remove the test and ...

daviddavid
TO
  1. 
      
  2. reviewboard/hostingsvcs/bitbucket.py (Diff revision 1)
     
     
     

    This can be combined to a single import (http://docs.python.org/2/reference/simple_stmts.html#the-import-statement)

  3. reviewboard/hostingsvcs/urls.py (Diff revision 1)
     
     

    Trailing whitespace

  4. reviewboard/hostingsvcs/urls.py (Diff revision 1)
     
     

    Mixed tabs and whitespaces

  5. 
      
B.
  1. 
      
  2. reviewboard/hostingsvcs/urls.py (Diff revision 1)
     
     

    Only for temporary testing

  3. 
      
anselina
  1. Making these changes should fix the problem you mentioned in your status report about the URLs not being added for Bitbucket! (Using your code in /r/5510, I've checked that the URLs are properly generated for GitHub, so everything's fine there.)

  2. reviewboard/hostingsvcs/bitbucket.py (Diff revision 1)
     
     
     
     
     
     

    Change this to:

    repository_url_patterns = patterns(
        '',
        url(r'^hooks/post-receive/$',
            'reviewboard.hostingsvcs.tests.hosting_service_url_test_view')
    )
    
    1. Sorry, some style issues with what I said above - instead, change it to:

      repository_url_patterns = patterns(
          '',
      
          url(r'^hooks/post-receive/$',
              'reviewboard.hostingsvcs.tests.hosting_service_url_test_view'),
      )
      

      And also make sure you import patterns and url: from django.conf.urls import patterns, url
      It should work after this!

  3. reviewboard/hostingsvcs/urls.py (Diff revision 1)
     
     
     

    You should delete these lines because the URLs are already dynamically generated.

  4. 
      
B.
B.
B.
B.
B.
B.
B.
B.
B.
B.
david
  1. 
      
  2. reviewboard/hostingsvcs/bitbucket.py (Diff revision 4)
     
     

    You didn't add any logging, so this import can go away.

  3. reviewboard/hostingsvcs/bitbucket.py (Diff revision 4)
     
     

    This isn't used.

  4. reviewboard/hostingsvcs/bitbucket.py (Diff revision 4)
     
     

    This line isn't necessary.

  5. reviewboard/hostingsvcs/bitbucket.py (Diff revision 4)
     
     
     
     
     
     
     

    If review_id_to_commits is an empty map, close_all_review_requests will be a no-op. Therefore I think you can remove the test and early return.

  6. 
      
B.
david
  1. Ship It!

  2. 
      
B.
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to release-2.0.x (9e4245e).
Loading...