def run(self) -> HandlerResults:
        """
        Discover information about organization/user which wants to install packit on his repository
        Try to whitelist automatically if mapping from github username to FAS account can prove that
        user is a packager.
        :return: HandlerResults
        """

        # try to add user to whitelist
        whitelist = Whitelist()
        Installation.create(
            installation_id=self.installation_event.installation_id,
            event=self.installation_event,
        )
        if not whitelist.add_account(self.installation_event):
            # Create an issue in our repository, so we are notified when someone install the app
            self.project.create_issue(
                title=
                f"Account: {self.installation_event.account_login} needs to be approved.",
                body=
                (f"Hi @{self.installation_event.account_login}, we need to approve you in "
                 "order to start using Packit-as-a-Service. Someone from our team will "
                 "get back to you shortly."),
            )

            msg = f"Account: {self.installation_event.account_login} needs to be approved manually!"
            logger.info(msg)
            return HandlerResults(success=True, details={"msg": msg})
        return HandlerResults(
            success=True,
            details={
                "msg":
                f"Account {self.installation_event.account_login} whitelisted!"
            },
        )
    def run(self) -> HandlerResults:
        """
        Discover information about organization/user which wants to install packit on his repository
        Try to whitelist automatically if mapping from github username to FAS account can prove that
        user is a packager.
        :return: HandlerResults
        """
        InstallationModel.create(event=self.event)
        # try to add user to whitelist
        whitelist = Whitelist(
            fas_user=self.config.fas_user,
            fas_password=self.config.fas_password,
        )
        account_login = self.event.account_login
        account_type = self.event.account_type
        if not whitelist.add_account(self.event):
            # Create an issue in our repository, so we are notified when someone install the app
            self.project.create_issue(
                title=f"{account_type} {account_login} needs to be approved.",
                body=
                (f"Hi @{self.event.sender_login}, we need to approve you in "
                 "order to start using Packit-as-a-Service. Someone from our team will "
                 "get back to you shortly.\n\n"
                 "For more info, please check out the documentation: "
                 "http://packit.dev/packit-as-a-service/"),
            )
            msg = f"{account_type} {account_login} needs to be approved manually!"
        else:
            msg = f"{account_type} {account_login} whitelisted!"

        logger.info(msg)
        return HandlerResults(success=True, details={"msg": msg})
Esempio n. 3
0
    def run(self) -> HandlerResults:
        """
        Discover information about organization/user which wants to install packit on his repository
        Try to whitelist automatically if mapping from github username to FAS account can prove that
        user is a packager.
        :return:
        """

        # try to add user to whitelist
        whitelist = Whitelist()
        if not whitelist.add_account(self.github_app):

            # Create an issue in our repository, so we are notified when someone install the app
            gh_proj = get_github_project(
                self.config, repo="notifications", namespace="packit-service"
            )
            gh_proj.create_issue(
                title=f"Account: {self.github_app.account_login} needs to be approved.",
                body=(
                    f"Hi @{self.github_app.account_login}, we need to approve you in "
                    "order to start using Packit-as-a-Service. Someone from our team will "
                    "get back to you shortly."
                ),
            )

            msg = f"Account: {self.github_app.account_login} needs to be approved manually!"
            logger.info(msg)
            return HandlerResults(success=True, details={"msg": msg})

        msg = (
            f"Account: {self.github_app.account_login} approved automatically,"
            f" because user: {self.github_app.sender_login}, who installed Packit-as-a-service,"
            f" is a packager in Fedora."
        )
        return HandlerResults(success=True, details={"msg": msg})