Beispiel #1
0
def github_callback():
    if request.headers["X-GitHub-Event"] == "ping":
        return jsonify(status="OK"), 200

    if current_app.config["DEBUG_PAYLOADS"]:
        current_app.logger.info(f"Incoming github payload: {request.json}")

    # if "unique_slug" not in request.args or "pull_request" not in request.json:  # TODO: should be abstracted somehow
    #     current_app.logger.info("Missing ‘unique_slug’ in query params or ‘pull_request’ in payload")
    #     return jsonify(status="OK"), 200

    payload = request.json["pull_request"]
    repo_id = payload["head"]["repo"]["id"]

    github_repo = GithubRepo.query.get(repo_id)
    if not github_repo:
        current_app.logger.info("No github_repo found in database")
        return jsonify(status="GONE"), 410

    # if github_repo.hook_unique_slug != request.args["unique_slug"]:
    #     current_app.logger.info("Mis-match on hook’s unique slug")
    #     return jsonify(status="BAD SLUG"), 400

    # verify_signature = (
    #     "sha1=" + hmac.new(github_repo.hook_secret.encode("utf8"), request.data, hashlib.sha1).hexdigest()
    # )
    # if not hmac.compare_digest(request.headers["X-Hub-Signature"], verify_signature):
    #     current_app.logger.info("X-Hub-Signature verification failed")
    #     return jsonify(status="OK"), 200

    updater = Updater(current_app, db, github_repo.integration.user)
    updater.sync_pull_request(data=payload)

    return jsonify(status="OK"), 200
Beispiel #2
0
def trello_callback():
    data = json.loads(request.get_data(as_text=True))

    if current_app.config["DEBUG_PAYLOADS"]:
        current_app.logger.debug(f"Incoming trello payload: {data}")

    if data.get("action", {}).get("type") == "updateCard":
        trello_card = TrelloCard.from_json(data["action"]["data"]["card"])
        current_app.logger.debug(f"updateCard on {trello_card}")
        if trello_card and trello_card.pull_requests:
            updater = Updater(current_app, db, trello_card.pull_requests[0].repo.integration.user)
            updater.sync_trello_card(trello_card)

    else:
        current_app.logger.debug("Ignoring payload: not an `updateCard`")

    return jsonify(status="OK"), 200
class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.api = Api()

        self.updater = Updater()
        self.updater.chainstatus_changed.connect(self.on_chainstatus_changed)

        # Sidebar
        self.btn_group_nav.buttonClicked.connect(self.on_nav_change)
        self.widget_skills = WidgetSkills(self)
        self.layout_frame_sidebar.insertWidget(4, self.widget_skills)

        # Content
        self.stack_content.setCurrentIndex(0)
        self.layout_page_wallet.insertWidget(0, WalletHeader(self))
        self.layout_wallet_addresses.addWidget(WalletAddresses(self))
        self.layout_wallet_send.addWidget(WalletSend(self))
        self.layout_wallet_history.addWidget(WalletHistory(self))
        self.layout_community.addWidget(Community(self))
        self.layout_privilege_request.addWidget(
            CreatePrivilegeRequest(self, self.change_stack_index))

        self.updater.start()

    def on_nav_change(self, btn):
        name = btn.objectName()
        if name == 'btn_nav_wallet':
            self.change_stack_index(0)
        if name == 'btn_nav_community':
            self.change_stack_index(1)

    def change_stack_index(self, new_index):
        self.stack_content.setCurrentIndex(new_index)

    def on_chainstatus_changed(self, data):
        percentage = (data.get('blocks') / data.get('headers')) * 100
        self.progbar_blockchain_sync.setValue(int(percentage))
        msg = 'Synced {} blocks of {}'.format(data.get('blocks'),
                                              data.get('headers'))
        self.statusbar.showMessage(msg, 10000)
Beispiel #4
0
def github_choose_repos():
    github_client = get_github_client(current_app, current_user)
    available_repos = github_client.get_repos()
    print("available_repos", available_repos)
    editable_repos = [
        repo
        for repo in available_repos
        if (not repo.integration) or repo.integration == current_user.github_integration
    ]
    editable_repo_ids = {repo.id for repo in editable_repos}
    print("editable_repos", editable_repos)
    owned_by_another_repos = [
        repo for repo in available_repos if repo.integration and repo.integration != current_user.github_integration
    ]
    owned_by_another_repo_ids = {repo.id for repo in owned_by_another_repos}
    print("owned_by_another_repos", owned_by_another_repos)

    repo_form = ChooseGithubRepoForm(editable_repos)

    if repo_form.validate_on_submit():
        github_client = get_github_client(current_app, current_user)
        chosen_repo_ids = editable_repo_ids.intersection(set(repo_form.repo_choice.data)) - owned_by_another_repo_ids

        updater = Updater(current_app, db, current_user)
        updater.sync_repositories(chosen_repo_ids)

        return redirect(url_for(".dashboard"))

    elif repo_form.errors:
        for error in repo_form.errors.items():
            flash(error, "warning")

    existing_repos = GithubRepo.query.filter(GithubRepo.id.in_([repo.id for repo in editable_repos])).all()
    repo_form.repo_choice.data = [repo.id for repo in existing_repos]

    return render_template(
        "integration/choose-repos.html", repo_form=repo_form, owned_by_another_repos=owned_by_another_repos
    )
Beispiel #5
0
def github_transfer_existing_repos():
    github_client = get_github_client(current_app, current_user)
    available_repos = github_client.get_repos()
    repos_owned_by_another = [
        repo for repo in available_repos if repo.integration and repo.integration != current_user.github_integration
    ]

    repo_form = TransferGithubRepoForm(repos_owned_by_another)

    if repo_form.validate_on_submit():
        github_client = get_github_client(current_app, current_user)
        chosen_repo_id = repo_form.repo_choice.data

        updater = Updater(current_app, db, current_user)
        updater.transfer_repository(chosen_repo_id)

        return redirect(url_for(".dashboard"))

    elif repo_form.errors:
        for error in repo_form.errors.items():
            flash(error, "warning")

    return render_template("integration/transfer-existing-repos.html", repo_form=repo_form)
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.api = Api()

        self.updater = Updater()
        self.updater.chainstatus_changed.connect(self.on_chainstatus_changed)

        # Sidebar
        self.btn_group_nav.buttonClicked.connect(self.on_nav_change)
        self.widget_skills = WidgetSkills(self)
        self.layout_frame_sidebar.insertWidget(4, self.widget_skills)

        # Content
        self.stack_content.setCurrentIndex(0)
        self.layout_page_wallet.insertWidget(0, WalletHeader(self))
        self.layout_wallet_addresses.addWidget(WalletAddresses(self))
        self.layout_wallet_send.addWidget(WalletSend(self))
        self.layout_wallet_history.addWidget(WalletHistory(self))
        self.layout_community.addWidget(Community(self))
        self.layout_privilege_request.addWidget(
            CreatePrivilegeRequest(self, self.change_stack_index))

        self.updater.start()
Beispiel #7
0
    def on_application_start(self):
        init_profile_db()
        self.updater = Updater(self)
        self.node = Node(self)
        self.aboutToQuit.connect(self.cleanup)

        from app.models.db import profile_session_scope
        with profile_session_scope() as session:
            is_first_start = app.is_first_start(session)

        if is_first_start:
            wizard = SetupWizard()
            if wizard.exec() == SetupWizard.Rejected:
                QtWidgets.qApp.quit()
                return
        else:
            init_data_db()

        # Initialize main window
        self.ui = self.main_widget()

        # Init TrayIcon
        self.tray_icon = QtWidgets.QSystemTrayIcon(self)
        self.tray_icon.setIcon(QIcon(':images/resources/app_icon.png'))
        self.tray_icon.activated.connect(self.on_tray_activated)

        show_action = QtWidgets.QAction("Show", self)
        quit_action = QtWidgets.QAction("Exit", self)
        hide_action = QtWidgets.QAction("Hide", self)
        show_action.triggered.connect(self.ui.show)
        hide_action.triggered.connect(self.ui.hide)
        quit_action.triggered.connect(QtWidgets.qApp.quit)

        tray_menu = QtWidgets.QMenu()
        tray_menu.addAction(show_action)
        tray_menu.addAction(hide_action)
        tray_menu.addAction(quit_action)
        self.tray_icon.setContextMenu(tray_menu)
        self.tray_icon.show()

        # Shortcuts
        if hasattr(self.ui, 'node'):
            self.ui.debug_shortcut = QtWidgets.QShortcut(
                'Ctrl+K', self.ui, self.node.kill)
            self.ui.debug_shortcut = QtWidgets.QShortcut(
                'Ctrl+S', self.ui, self.node.stop)
            self.ui.debug_shortcut = QtWidgets.QShortcut(
                'Ctrl+R', self.ui, self.node.start)
Beispiel #8
0
        if self.currentId() == self.P3_CONNECT:
            return self.P7_SYNC
        if self.currentId() == self.P4_CHOOSE_ACCOUNT:
            if self.button_account_create.isChecked():
                return self.P6_CREATE_ACCOUNT
            if self.button_account_import.isChecked():
                return self.P5_IMPORT_ACCOUNT
        if self.currentId() == self.P5_IMPORT_ACCOUNT:
            return self.P7_SYNC
        return super().nextId()


if __name__ == '__main__':
    import sys
    import traceback
    from PyQt5 import QtWidgets, Qt
    from app.updater import Updater
    from app.node import Node
    from app.helpers import init_logging
    sys.excepthook = traceback.print_exception
    init_logging()

    wrapper = QtWidgets.QApplication(sys.argv)
    wrapper.setStyle('fusion')
    wrapper.node = Node()
    wrapper.updater = Updater()
    wizard = SetupWizard()
    wizard.show()
    sys.exit(wrapper.exec())