hgext/phabricator.py
changeset 43506 9f70512ae2cf
parent 43504 a78a65c33b5a
child 43549 4cb3f5bb29ec
equal deleted inserted replaced
43505:47fac1692ede 43506:9f70512ae2cf
   165             br'cli-[a-z0-9]+', br'cli-hahayouwish', request.body
   165             br'cli-[a-z0-9]+', br'cli-hahayouwish', request.body
   166         )
   166         )
   167         return request
   167         return request
   168 
   168 
   169     def sanitiseresponse(response):
   169     def sanitiseresponse(response):
   170         if r'set-cookie' in response[r'headers']:
   170         if 'set-cookie' in response['headers']:
   171             del response[r'headers'][r'set-cookie']
   171             del response['headers']['set-cookie']
   172         return response
   172         return response
   173 
   173 
   174     def decorate(fn):
   174     def decorate(fn):
   175         def inner(*args, **kwargs):
   175         def inner(*args, **kwargs):
   176             cassette = pycompat.fsdecode(kwargs.pop(r'test_vcr', None))
   176             cassette = pycompat.fsdecode(kwargs.pop('test_vcr', None))
   177             if cassette:
   177             if cassette:
   178                 import hgdemandimport
   178                 import hgdemandimport
   179 
   179 
   180                 with hgdemandimport.deactivated():
   180                 with hgdemandimport.deactivated():
   181                     import vcr as vcrmod
   181                     import vcr as vcrmod
   182                     import vcr.stubs as stubs
   182                     import vcr.stubs as stubs
   183 
   183 
   184                     vcr = vcrmod.VCR(
   184                     vcr = vcrmod.VCR(
   185                         serializer=r'json',
   185                         serializer='json',
   186                         before_record_request=sanitiserequest,
   186                         before_record_request=sanitiserequest,
   187                         before_record_response=sanitiseresponse,
   187                         before_record_response=sanitiseresponse,
   188                         custom_patches=[
   188                         custom_patches=[
   189                             (
   189                             (
   190                                 urlmod,
   190                                 urlmod,
   191                                 r'httpconnection',
   191                                 'httpconnection',
   192                                 stubs.VCRHTTPConnection,
   192                                 stubs.VCRHTTPConnection,
   193                             ),
   193                             ),
   194                             (
   194                             (
   195                                 urlmod,
   195                                 urlmod,
   196                                 r'httpsconnection',
   196                                 'httpsconnection',
   197                                 stubs.VCRHTTPSConnection,
   197                                 stubs.VCRHTTPSConnection,
   198                             ),
   198                             ),
   199                         ],
   199                         ],
   200                     )
   200                     )
   201                     vcr.register_matcher(r'hgmatcher', hgmatcher)
   201                     vcr.register_matcher('hgmatcher', hgmatcher)
   202                     with vcr.use_cassette(cassette, match_on=[r'hgmatcher']):
   202                     with vcr.use_cassette(cassette, match_on=['hgmatcher']):
   203                         return fn(*args, **kwargs)
   203                         return fn(*args, **kwargs)
   204             return fn(*args, **kwargs)
   204             return fn(*args, **kwargs)
   205 
   205 
   206         inner.__name__ = fn.__name__
   206         inner.__name__ = fn.__name__
   207         inner.__doc__ = fn.__doc__
   207         inner.__doc__ = fn.__doc__
   406                         continue
   406                         continue
   407 
   407 
   408         # Check commit message
   408         # Check commit message
   409         m = _differentialrevisiondescre.search(ctx.description())
   409         m = _differentialrevisiondescre.search(ctx.description())
   410         if m:
   410         if m:
   411             toconfirm[node] = (1, set(precnodes), int(m.group(r'id')))
   411             toconfirm[node] = (1, set(precnodes), int(m.group('id')))
   412 
   412 
   413     # Double check if tags are genuine by collecting all old nodes from
   413     # Double check if tags are genuine by collecting all old nodes from
   414     # Phabricator, and expect precursors overlap with it.
   414     # Phabricator, and expect precursors overlap with it.
   415     if toconfirm:
   415     if toconfirm:
   416         drevs = [drev for force, precs, drev in toconfirm.values()]
   416         drevs = [drev for force, precs, drev in toconfirm.values()]
  1086                 action = b'created'
  1086                 action = b'created'
  1087 
  1087 
  1088             # Create a local tag to note the association, if commit message
  1088             # Create a local tag to note the association, if commit message
  1089             # does not have it already
  1089             # does not have it already
  1090             m = _differentialrevisiondescre.search(ctx.description())
  1090             m = _differentialrevisiondescre.search(ctx.description())
  1091             if not m or int(m.group(r'id')) != newrevid:
  1091             if not m or int(m.group('id')) != newrevid:
  1092                 tagname = b'D%d' % newrevid
  1092                 tagname = b'D%d' % newrevid
  1093                 tags.tag(
  1093                 tags.tag(
  1094                     repo,
  1094                     repo,
  1095                     tagname,
  1095                     tagname,
  1096                     ctx.node(),
  1096                     ctx.node(),
  1633     """
  1633     """
  1634     ctx = context.resource(mapping, b'ctx')
  1634     ctx = context.resource(mapping, b'ctx')
  1635     m = _differentialrevisiondescre.search(ctx.description())
  1635     m = _differentialrevisiondescre.search(ctx.description())
  1636     if m:
  1636     if m:
  1637         return templateutil.hybriddict(
  1637         return templateutil.hybriddict(
  1638             {b'url': m.group(r'url'), b'id': b"D%s" % m.group(r'id'),}
  1638             {b'url': m.group('url'), b'id': b"D%s" % m.group('id'),}
  1639         )
  1639         )
  1640     else:
  1640     else:
  1641         tags = ctx.repo().nodetags(ctx.node())
  1641         tags = ctx.repo().nodetags(ctx.node())
  1642         for t in tags:
  1642         for t in tags:
  1643             if _differentialrevisiontagre.match(t):
  1643             if _differentialrevisiontagre.match(t):