launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #19681
[Merge] lp:~cjwatson/launchpad/bmp-webhooks-merge-detection into lp:launchpad
Colin Watson has proposed merging lp:~cjwatson/launchpad/bmp-webhooks-merge-detection into lp:launchpad.
Commit message:
Grant branchscanner SELECT access to previewdiff, so that it can compose webhook payloads on merge detection.
Requested reviews:
Colin Watson (cjwatson)
Related bugs:
Bug #1510993 in Launchpad itself: "Regression in tracking merged git merge requests"
https://bugs.launchpad.net/launchpad/+bug/1510993
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/bmp-webhooks-merge-detection/+merge/276036
Grant branchscanner SELECT access to previewdiff, so that it can compose webhook payloads on merge detection.
--
Your team Launchpad code reviewers is subscribed to branch lp:launchpad.
=== modified file 'database/schema/security.cfg'
--- database/schema/security.cfg 2015-10-27 13:35:44 +0000
+++ database/schema/security.cfg 2015-10-28 17:33:46 +0000
@@ -695,6 +695,7 @@
public.milestonetag = SELECT
public.person = SELECT
public.personsettings = SELECT
+public.previewdiff = SELECT
public.revision = SELECT, INSERT, UPDATE
public.revisionauthor = SELECT, INSERT, UPDATE
public.revisioncache = SELECT, INSERT
=== modified file 'lib/lp/code/model/tests/test_gitjob.py'
--- lib/lp/code/model/tests/test_gitjob.py 2015-10-01 14:45:57 +0000
+++ lib/lp/code/model/tests/test_gitjob.py 2015-10-28 17:33:46 +0000
@@ -13,6 +13,7 @@
import pytz
from testtools.matchers import (
+ ContainsDict,
Equals,
MatchesDict,
MatchesSetwise,
@@ -22,6 +23,9 @@
from zope.security.proxy import removeSecurityProxy
from lp.code.enums import GitObjectType
+from lp.code.interfaces.branchmergeproposal import (
+ BRANCH_MERGE_PROPOSAL_WEBHOOKS_FEATURE_FLAG,
+ )
from lp.code.interfaces.githosting import IGitHostingClient
from lp.code.interfaces.gitjob import (
IGitJob,
@@ -38,6 +42,7 @@
from lp.services.database.constants import UTC_NOW
from lp.services.features.testing import FeatureFixture
from lp.services.job.runner import JobRunner
+from lp.services.webapp import canonical_url
from lp.testing import (
TestCaseWithFactory,
time_counter,
@@ -213,6 +218,47 @@
'new': {'commit_sha1': sha1('refs/tags/2.0')}},
})})))
+ def test_merge_detection_triggers_webhooks(self):
+ self.useFixture(FeatureFixture(
+ {BRANCH_MERGE_PROPOSAL_WEBHOOKS_FEATURE_FLAG: 'on'}))
+ repository = self.factory.makeGitRepository()
+ target, source = self.factory.makeGitRefs(
+ repository, paths=[u'refs/heads/target', u'refs/heads/source'])
+ bmp = self.factory.makeBranchMergeProposalForGit(
+ target_ref=target, source_ref=source)
+ hook = self.factory.makeWebhook(
+ target=repository, event_types=['merge-proposal:0.1'])
+ new_refs = {
+ target.path: {'object': {
+ 'sha1': u'0' * 40,
+ 'type': 'commit',
+ }},
+ source.path: {'object': {
+ 'sha1': source.commit_sha1,
+ 'type': 'commit',
+ }},
+ }
+ hosting_client = FakeGitHostingClient(new_refs, [])
+ hosting_client.detectMerges = FakeMethod(
+ result={source.commit_sha1: u'0' * 40})
+ self.useFixture(ZopeUtilityFixture(hosting_client, IGitHostingClient))
+ job = GitRefScanJob.create(repository)
+ with dbuser('branchscanner'):
+ JobRunner([job]).runAll()
+ delivery = hook.deliveries.one()
+ self.assertThat(
+ delivery,
+ MatchesStructure(
+ event_type=Equals('merge-proposal:0.1'),
+ payload=MatchesDict({
+ 'merge_proposal': Equals(
+ canonical_url(bmp, force_local_path=True)),
+ 'action': Equals('modified'),
+ 'old': ContainsDict(
+ {'queue_status': Equals('Work in progress')}),
+ 'new': ContainsDict({'queue_status': Equals('Merged')}),
+ })))
+
def test_composeWebhookPayload(self):
repository = self.factory.makeGitRepository()
self.factory.makeGitRefs(
References