Beispiel #1
0
    def run(self) -> TaskResults:
        """
        Discover information about organization/user which wants to install packit on his repository
        Try to allowlist automatically if mapping from github username to FAS account can prove that
        user is a packager.
        :return: TaskResults
        """
        InstallationModel.create(event=self.installation_event)
        # try to add user to allowlist
        allowlist = Allowlist(
            fas_user=self.service_config.fas_user,
            fas_password=self.service_config.fas_password,
        )
        if not allowlist.add_account(self.account_login, self.sender_login):
            # Create an issue in our repository, so we are notified when someone install the app
            self.project.create_issue(
                title=
                f"{self.account_type} {self.account_login} needs to be approved.",
                body=
                (f"Hi @{self.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"{self.account_type} {self.account_login} needs to be approved manually!"
        else:
            msg = f"{self.account_type} {self.account_login} allowlisted!"

        logger.info(msg)
        return TaskResults(success=True, details={"msg": msg})
Beispiel #2
0
def multiple_installation_entries(installation_events):
    with get_sa_session() as session:
        session.query(InstallationModel).delete()
        yield [
            InstallationModel.create(event=installation_events[0],),
            InstallationModel.create(event=installation_events[1],),
        ]
    clean_db()
Beispiel #3
0
    def run(self) -> TaskResults:
        """
        Discover information about organization/user which wants to install packit on his repository
        Try to allowlist automatically if mapping from github username to FAS account can prove that
        user is a packager.
        :return: TaskResults
        """
        InstallationModel.create(event=self.installation_event)
        # try to add user to allowlist
        allowlist = Allowlist(
            fas_user=self.service_config.fas_user,
            fas_password=self.service_config.fas_password,
        )
        if not allowlist.add_namespace(f"github.com/{self.account_login}",
                                       self.sender_login):
            # Create an issue in our repository, so we are notified when someone install the app
            self.project.create_issue(
                title=
                f"{self.account_type} {self.account_login} needs to be approved.",
                body=
                (f"Hi @{self.sender_login}, we need to approve you in "
                 "order to start using Packit-as-a-Service. "
                 "We are now onboarding Fedora contributors who have a valid "
                 "[Fedora Account System](https://fedoraproject.org/wiki/Account_System) "
                 "account and have signed "
                 "[FPCA](https://fedoraproject.org/wiki/Legal"
                 ":Fedora_Project_Contributor_Agreement). "
                 "If you have such an account, please, provide it in a comment and "
                 "we'd be glad to approve you for using the service.\n\n"
                 "For more info, please check out the documentation: "
                 "https://packit.dev/docs/packit-service"),
            )
            msg = f"{self.account_type} {self.account_login} needs to be approved manually!"
        else:
            msg = f"{self.account_type} {self.account_login} allowlisted!"

        logger.info(msg)
        return TaskResults(success=True, details={"msg": msg})
Beispiel #4
0
def test_get_installation_by_account(clean_before_and_after,
                                     multiple_installation_entries):
    assert InstallationModel.get_by_account_login("teg").sender_login == "teg"
    assert InstallationModel.get_by_account_login(
        "Pac23").sender_login == "Pac23"
Beispiel #5
0
def test_get_installations(clean_before_and_after,
                           multiple_installation_entries):
    results = list(InstallationModel.get_all())
    assert len(results) == 2
 def get(self, id):
     """A specific installation details"""
     installation = InstallationModel.get_by_id(id)
     return (installation.to_dict() if installation else
             ("", HTTPStatus.NO_CONTENT.value))
 def get(self):
     """List all Github App installations"""
     return [
         installation.to_dict()
         for installation in InstallationModel.get_all()
     ]