Пример #1
0
 def execute(self, args, cmd_pressed, shift_pressed):
     if args[-1] in _pull_request_modes.keys():
         pull_request_mode = args[-1]
         call_alfred('stash:pullrequests {} '.format(pull_request_mode))
     else:
         import webbrowser
         webbrowser.open(args[-1])
Пример #2
0
def route(args):  # e.g., args = ":config sethost http://localhost,--exec"
    command_string = args[0]  # :config sethost http://localhost
    command = command_string.split(' ')

    if not workflow().settings.get(HOST_URL, None) and 'sethost' not in command:
        call_alfred('stash:config sethost ')
        return

    handler = IndexWorkflowAction
    action = next(iter(command), None)
    if action:
        handler = WORKFLOW_ACTIONS.get(action, IndexWorkflowAction)

    if '--exec' in args:
        handler().execute(command, cmd_pressed='--cmd' in args, shift_pressed='--shift' in args)
    else:  # show menu
        handler().menu(command)
        _notify_if_upgrade_available()
        workflow().send_feedback()
        elif 'setpw' in args:
            workflow().save_password(USER_PW, args[-1])
            print('Saved Bamboo password in keychain')
        elif 'verifycert' in args:
            verify_cert = workflow().settings.get(VERIFY_CERT, 'false') == 'true'
            toggle = (str(not verify_cert)).lower()
            workflow().settings[VERIFY_CERT] = toggle
            print('Enabled certificate verification' if toggle == 'true' else 'Disabled certificate verification')
        elif 'sync' in args:
            workflow().clear_cache()
            update_bamboo_cache()
            print('Bamboo data synchronization triggered')
        elif 'update' in args:
            try:
                if workflow().start_update():
                    print('Update of workflow finished')
                else:
                    print('You already have the latest workflow version')
            except Exception, e:
                print('Update of workflow failed: {}'.format(str(e)))
        elif 'switchtheme' in args:
            icon_theme = 'light' if icons.icon_theme() == 'dark' else 'dark'
            workflow().settings[icons.ICON_THEME] = icon_theme
            print('The workflow is now using the %s icon theme' % icon_theme)

        call_alfred('bamboo:config')


def _add_cancel_workflow_action():
    workflow().add_item('Cancel', autocomplete=':config', icon=icons.GO_BACK)
Пример #4
0
                            largetext=plan.name,
                            arg=':plans ' + plan.plan_key,
                            modifier_subtitles={u'shift': u'Trigger build execution for this plan'},
                            # `cmd``, ``ctrl``, ``shift``, ``alt`` and ``fn``
                            copytext='{}/browse/{}'.format(workflow().settings.get(HOST_URL), plan.plan_key),
                            valid=True)

    def _get_result_filter(self):
        return lambda p: u' '.join([p.name, p.description])

    def _transform_from_cache(self, plans, q):
        return sorted(plans, key=lambda p: p.is_favourite, reverse=True) if plans else []


class PlanWorkflowAction(BambooWorkflowAction):
    def menu(self, args):
        plan_workflow = PlansFilterableMenu(args)
        return plan_workflow.run()

    def execute(self, args, ctrl_pressed, shift_pressed):
        plan_key = args[-1]
        if shift_pressed:
            try:
                facade = build_bamboo_facade()
                facade.trigger_build(plan_key)
                print('Successfully triggered build for {}'.format(plan_key))
            except Exception, e:
                print('Failed to trigger build for {}: {}'.format(plan_key, str(e)))
        else:
            call_alfred('bamboo:branches {} '.format(plan_key))
        elif 'setpw' in args:
            workflow().save_password(USER_PW, args[-1])
            print('Saved Stash password in keychain')
        elif 'verifycert' in args:
            verify_cert = workflow().settings.get(VERIFY_CERT, 'false') == 'true'
            toggle = (str(not verify_cert)).lower()
            workflow().settings[VERIFY_CERT] = toggle
            print('Enabled certificate verification' if toggle == 'true' else 'Disabled certificate verification')
        elif 'sync' in args:
            workflow().clear_cache()
            update_stash_cache()
            print('Stash data synchronization triggered')
        elif 'update' in args:
            try:
                if workflow().start_update():
                    print('Update of workflow finished')
                else:
                    print('You already have the latest workflow version')
            except Exception, e:
                print('Update of workflow failed: {}'.format(str(e)))
        elif 'switchtheme' in args:
            icon_theme = 'light' if icons.icon_theme() == 'dark' else 'dark'
            workflow().settings[icons.ICON_THEME] = icon_theme
            print('The workflow is now using the %s icon theme' % icon_theme)

        call_alfred('stash:config')


def _add_cancel_workflow_action():
    workflow().add_item('Cancel', autocomplete=':config', icon=icons.GO_BACK)