示例#1
0
 def create_action(self, action, data):
     if IGitRef.providedBy(self.context):
         kwargs = {'git_ref': self.context}
     else:
         kwargs = {'branch': self.context}
     private = not getUtility(
         ISnapSet).isValidPrivacy(False, data['owner'], **kwargs)
     if not data.get('auto_build', False):
         data['auto_build_archive'] = None
         data['auto_build_pocket'] = None
     snap = getUtility(ISnapSet).new(
         self.user, data['owner'],
         data['store_distro_series'].distro_series, data['name'],
         auto_build=data['auto_build'],
         auto_build_archive=data['auto_build_archive'],
         auto_build_pocket=data['auto_build_pocket'],
         auto_build_channels=data['auto_build_channels'],
         processors=data['processors'], private=private,
         build_source_tarball=data['build_source_tarball'],
         store_upload=data['store_upload'],
         store_series=data['store_distro_series'].snappy_series,
         store_name=data['store_name'],
         store_channels=data.get('store_channels'), **kwargs)
     if data['store_upload']:
         self.requestAuthorization(snap)
     else:
         self.next_url = canonical_url(snap)
 def __init__(self, name, type, comment, line_number, branch_or_repository,
              revspec, directory, recipe_data, parent_instruction,
              source_directory):
     super(_SourcePackageRecipeDataInstruction, self).__init__()
     self.name = unicode(name)
     self.type = type
     self.comment = comment
     self.line_number = line_number
     if IGitRepository.providedBy(branch_or_repository):
         self.git_repository = branch_or_repository
     elif IGitRef.providedBy(branch_or_repository):
         self.git_repository = branch_or_repository
         if revspec is None:
             revspec = branch_or_repository.name
     elif IBranch.providedBy(branch_or_repository):
         self.branch = branch_or_repository
     else:
         raise AssertionError("Unsupported source: %r" %
                              (branch_or_repository, ))
     if revspec is not None:
         revspec = unicode(revspec)
     self.revspec = revspec
     if directory is not None:
         directory = unicode(directory)
     self.directory = directory
     self.source_directory = source_directory
     self.recipe_data = recipe_data
     self.parent_instruction = parent_instruction
示例#3
0
 def initial_values(self):
     distroseries = BuildableDistroSeries.findSeries(self.user)
     series = [
         series for series in distroseries
         if series.status in (SeriesStatus.CURRENT,
                              SeriesStatus.DEVELOPMENT)
     ]
     if IBranch.providedBy(self.context):
         recipe_text = MINIMAL_RECIPE_TEXT_BZR % self.context.identity
     elif IGitRepository.providedBy(self.context):
         default_ref = None
         if self.context.default_branch is not None:
             default_ref = self.context.getRefByPath(
                 self.context.default_branch)
         if default_ref is not None:
             branch_name = default_ref.name
         else:
             branch_name = "ENTER-BRANCH-NAME"
         recipe_text = MINIMAL_RECIPE_TEXT_GIT % (self.context.identity,
                                                  branch_name)
     elif IGitRef.providedBy(self.context):
         recipe_text = MINIMAL_RECIPE_TEXT_GIT % (
             self.context.repository.identity, self.context.name)
     else:
         raise AssertionError("Unsupported context: %r" % (self.context, ))
     return {
         'name': self._find_unused_name(self.user),
         'recipe_text': recipe_text,
         'owner': self.user,
         'distroseries': series,
         'build_daily': True,
         'use_ppa': EXISTING_PPA,
     }
示例#4
0
 def __init__(self, context):
     if IGitRef.providedBy(context):
         path = context.path
     elif IGitRule.providedBy(context):
         path = context.ref_pattern
     elif IGitRuleGrant.providedBy(context):
         path = context.rule.ref_pattern
     else:
         raise AssertionError("GitPermissionsVocabulary needs a context.")
     if path.startswith("refs/tags/"):
         terms = list(tag_permissions)
     else:
         # We could restrict this to just refs/heads/*, but it's helpful
         # to be able to offer *some* choices in the UI if somebody tries
         # to create grants for e.g. refs/*, and the choices we offer for
         # branches are probably more useful there than those we offer
         # for tags.
         terms = list(branch_permissions)
     if IGitRuleGrant.providedBy(context):
         grant_permissions = context.permissions
         if grant_permissions not in (term.value for term in terms):
             # Supplement the vocabulary with any atypical permissions
             # used by this grant.
             names = describe_git_permissions(grant_permissions)
             terms.append(
                 SimpleTerm(grant_permissions, "custom",
                            "Custom permissions: %s" % ", ".join(names)))
     super(GitPermissionsVocabulary, self).__init__(terms)
示例#5
0
 def _getTemplateParams(self, email, recipient):
     params = BaseMailer._getTemplateParams(self, email, recipient)
     reason, rationale = self._recipients.getReason(email)
     branch = reason.branch
     params['unique_name'] = branch.unique_name
     params['branch_identity'] = branch.identity
     params['branch_url'] = canonical_url(branch)
     if reason.recipient in branch.subscribers:
         # Give subscribers a link to unsubscribe.
         # XXX cjwatson 2015-04-15: Perhaps GitRef:+edit-subscription
         # should be made to work?
         if IGitRef.providedBy(branch):
             unsubscribe_url = canonical_url(branch.repository)
         else:
             unsubscribe_url = canonical_url(branch)
         params['unsubscribe'] = ("\nTo unsubscribe from this branch go to "
                                  "%s/+edit-subscription" % unsubscribe_url)
     else:
         params['unsubscribe'] = ''
     params['diff'] = self.contents or ''
     if not self._includeDiff(email):
         params['diff'] += self._explainNotPresentDiff(email)
     if self.delta_for_editors_text is not None:
         authz = getAdapter(branch, IAuthorization, 'launchpad.Edit')
         if authz.checkAuthenticated(IPersonRoles(recipient)):
             params['delta'] = self.delta_for_editors_text
         else:
             params['delta'] = self.delta_text or ''
     else:
         params['delta'] = self.delta_text or ''
     params.update(self.extra_template_params)
     return params
    def test_proposal_registrant(self):
        # If the reviewer is the registrant of the proposal, then it is MINE
        # only if the registrant is a member of the team that owns the branch.
        reviewer = self.bmp.registrant
        self.assertReviewGroupForReviewer(reviewer, ActiveReviewsView.OTHER)

        team = self.factory.makeTeam(self.bmp.registrant)
        naked_merge_source = removeSecurityProxy(self.bmp.merge_source)
        if IGitRef.providedBy(naked_merge_source):
            naked_merge_source.repository.owner = team
        else:
            naked_merge_source.owner = team
        self.assertReviewGroupForReviewer(reviewer, ActiveReviewsView.MINE)
示例#7
0
 def _getHeaders(self, email, recipient):
     headers = BaseMailer._getHeaders(self, email, recipient)
     reason, rationale = self._recipients.getReason(email)
     headers['X-Launchpad-Branch'] = reason.branch.unique_name
     if IGitRef.providedBy(reason.branch):
         if IProduct.providedBy(reason.branch.target):
             headers['X-Launchpad-Project'] = reason.branch.target.name
     elif IBranch.providedBy(reason.branch):
         if reason.branch.product is not None:
             headers['X-Launchpad-Project'] = reason.branch.product.name
     if self.revno is not None:
         headers['X-Launchpad-Branch-Revision-Number'] = str(self.revno)
     if self.revision_id is not None:
         headers['X-Launchpad-Branch-Revision-ID'] = self.revision_id
     return headers
示例#8
0
 def _recipe_names(self):
     """A generator of recipe names."""
     # +junk-daily doesn't make a very good recipe name, so use the
     # branch name in that case; similarly for personal Git repositories.
     if ((IBranch.providedBy(self.context)
          and self.context.target.allow_recipe_name_from_target)
             or ((IGitRepository.providedBy(self.context)
                  or IGitRef.providedBy(self.context))
                 and self.context.namespace.allow_recipe_name_from_target)):
         branch_target_name = self.context.target.name.split('/')[-1]
     else:
         branch_target_name = self.context.name
     yield "%s-daily" % branch_target_name
     counter = itertools.count(1)
     while True:
         yield "%s-daily-%s" % (branch_target_name, counter.next())
示例#9
0
    def _generateSuggestionVocab(context, full_vocabulary):
        """Generate the vocabulary for the radio buttons.

        The generated vocabulary contains the default repository for the
        target if there is one, and also any other repositories that the
        user has specified recently as a target for a proposed merge.
        """
        if IGitRef.providedBy(context):
            repository = context.repository
        else:
            repository = context

        if IPerson.providedBy(repository.target):
            # If the source is a personal repository, then the only valid
            # target is that same repository.
            target_repositories = [repository]
        else:
            repository_set = getUtility(IGitRepositorySet)
            default_target = repository_set.getDefaultRepository(
                repository.target)
            logged_in_user = getUtility(ILaunchBag).user
            since = datetime.now(utc) - timedelta(days=90)
            collection = IGitCollection(repository.target).targetedBy(
                logged_in_user, since)
            collection = collection.visibleByUser(logged_in_user)
            # May actually need some eager loading, but the API isn't fine
            # grained yet.
            repositories = collection.getRepositories(eager_load=False).config(
                distinct=True)
            target_repositories = list(repositories.config(limit=5))
            # If there is a default repository, make sure it is always
            # shown, and as the first item.
            if default_target is not None:
                if default_target in target_repositories:
                    target_repositories.remove(default_target)
                target_repositories.insert(0, default_target)

        terms = []
        for repository in target_repositories:
            terms.append(SimpleTerm(repository, repository.unique_name))

        return SimpleVocabulary(terms)