Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add "integration_branch" option to bugzilla hook

Allow users to specificy their integration branch so that only commits
to that branch cause bugs in Bugzilla to get updated. Prevents bugs
being updated while working on a feature branch.
  • Loading branch information...
commit b20691e68a4fd355d6b0e6d4f258a7c7c296a73c 1 parent f8a6cfd
@tofumatt tofumatt authored
Showing with 65 additions and 5 deletions.
  1. +14 −3 docs/bugzilla
  2. +17 −2 services/bugzilla.rb
  3. +34 −0 test/bugzilla_test.rb
View
17 docs/bugzilla
@@ -13,6 +13,14 @@ Multiple bugs can also be specified by separating them with a comma,
apersand, plus or "and":
- Bug 123, 124 and 125
+If the "Integration Branch" option is filled in, only commits to that branch
+will result in bugs being modified. This is useful for disabling premature bug
+closing/comments when working on feature branches.
+
+If "Integration Branch" is not set, commits to *all* branches will be
+processed. If you only want to update Bugzilla when you push to your "main"
+branch: you probably want to set this to "master".
+
If the central repository option is enabled and there is a "fix",
"close", or "address" before the bug then that bug is closed.
@@ -27,8 +35,11 @@ and >= 4.0 to be able to close bugs.
Settings
--------
- - server_url - The URL for the Bugzilla installation, eg http://bugzilla.mozilla.org/
+ - server_url - The URL for the Bugzilla installation,
+ eg `https://bugzilla.mozilla.org/`
- username - Email address for Bugzilla user account
- password - Password for the user account
- - central_repository - Set to true to enable closing bugs and commenting on commits that were
- already pushed to another user's repository
+ - integration_branch - If entered, only commits to this branch will result
+ in bugs being closed
+ - central_repository - Set to true to enable closing bugs and commenting on
+ commits that were already pushed to another user's repository
View
19 services/bugzilla.rb
@@ -1,5 +1,5 @@
class Service::Bugzilla < Service
- string :server_url, :username
+ string :server_url, :username, :integration_branch
password :password
boolean :central_repository
@@ -15,6 +15,10 @@ def receive_push
raise_config_error "password not set"
end
+ # Don't operate on these commits unless this is our "integration" (i.e. main) branch,
+ # as defined by the user. If no integration_branch is set, we operate on all commits.
+ return unless integration_branch?
+
# Post comments on all bugs identified in commits
repository = payload['repository']['url'].to_s
commits = payload['commits'].collect{|c| Commit.new(c)}
@@ -40,6 +44,18 @@ def receive_push
end
end
+ # Name of the branch for this payload; nil if it isn't branch-related.
+ def branch
+ return @branch if defined?(@branch)
+
+ matches = payload['ref'].match(/^refs\/heads\/(.*)$/)
+ @branch = matches ? matches[1] : nil
+ end
+
+ def integration_branch?
+ data['integration_branch'].to_s.empty? or data['integration_branch'].to_s == branch.to_s
+ end
+
attr_writer :xmlrpc_client # Can define own server for testing
def xmlrpc_client
# XMLRPC client to communicate with Bugzilla server
@@ -139,6 +155,5 @@ def comment(first_line_only=false)
end
return output
end
-
end
end
View
34 test/bugzilla_test.rb
@@ -20,6 +20,40 @@ def test_push
assert @server.bug_posts[3].include? '5057e76a11abd02e83b7d3d3171c4b68d9c88480'
end
+ # Verify pushes will be processed on all commits if no integration branch is specified.
+ def test_integration_branch_is_optional
+ modified_payload = modify_payload(payload)
+ svc = service({'server_url' => 'nowhere', 'username' => 'someone', 'password' => '12345', 'central_repository' => true}, modified_payload)
+ svc.xmlrpc_client = @server
+ svc.receive_push
+
+ assert @server.closed_bugs.include?(1)
+ assert @server.bug_posts.include?(4)
+ end
+
+ # Verify commits are only processed if they are in our integration branch.
+ def test_integration_branch
+ # No commits should be processed for this push because we're only listening for
+ # commits landing on the "master" branch.
+ modified_payload = modify_payload(payload).merge({'ref' => 'refs/heads/development'})
+ svc = service({'server_url' => 'nowhere', 'username' => 'someone', 'password' => '12345', 'integration_branch' => 'master', 'central_repository' => true}, modified_payload)
+ svc.xmlrpc_client = @server
+ svc.receive_push
+
+ assert @server.closed_bugs.length == 0
+ assert @server.bug_posts.length == 0
+
+ # This time, we should close a bug and post 4 comments because these commits were
+ # pushed to our integration branch.
+ modified_payload = modify_payload(payload).merge({'ref' => 'refs/heads/master'})
+ svc = service({'server_url' => 'nowhere', 'username' => 'someone', 'password' => '12345', 'integration_branch' => 'master', 'central_repository' => true}, modified_payload)
+ svc.xmlrpc_client = @server
+ svc.receive_push
+
+ assert @server.closed_bugs.include?(1)
+ assert @server.bug_posts.include?(4)
+ end
+
def test_central_push
#test pushing to a central repository
modified_payload = modify_payload(payload)
Please sign in to comment.
Something went wrong with that request. Please try again.