Example #1
0
def main(args):
    parser = argparse.ArgumentParser()
    parser.add_argument('--repo',
                        required=True,
                        help='repo name accessible in your account.')
    parser.add_argument('--orgn',
                        required=True,
                        help='Organisation name of the repo.')
    parser.add_argument('--token',
                        type=str,
                        default=None,
                        help='GitHub access token.')
    parser.add_argument('--pr',
                        required=True,
                        type=int,
                        help='The original PR number to be backported.')
    parser.add_argument('--branch',
                        type=str,
                        default='v8',
                        help='Target branch to make a backport')
    parser.add_argument('--debug', action='store_true')
    parser.add_argument(
        '--continue',
        action='store_true',
        dest='is_continue',
        help='Continues the process suspended by conflict situation. Run from'
        ' the working tree directory.')
    parser.add_argument(
        '--abort-before-push',
        action='store_true',
        help='Abort the procedure before making an push. Useful if you want to'
        ' make some modification to the backport branch. Use --continue to'
        ' make an actual push after making modification.')
    args = parser.parse_args(args)

    target_branch = args.branch
    repo_name = args.repo
    organ_name = args.orgn

    github_token = args.token
    if github_token is None:
        if 'BACKPORT_GITHUB_TOKEN' not in os.environ:
            parser.error('GitHub Access token must be specified with '
                         '--token or BACKPORT_GITHUB_TOKEN '
                         'environment variable.')
        github_token = os.environ['BACKPORT_GITHUB_TOKEN']

    if args.debug:
        github.enable_console_debug_logging()

    app = App(github_token, organ_name=organ_name, repo_name=repo_name)

    app.run(pr_num=args.pr,
            target_branch=target_branch,
            is_continue=args.is_continue,
            abort_before_push=args.abort_before_push)
Example #2
0
def main(args):
    parser = argparse.ArgumentParser()
    parser.add_argument('--repo',
                        required=True,
                        choices=('chainer', 'cupy'),
                        help='chainer or cupy')
    parser.add_argument('--token', required=True, help='GitHub access token.')
    parser.add_argument('--pr',
                        required=True,
                        type=int,
                        help='The original PR number to be backported.')
    parser.add_argument('--branch',
                        type=str,
                        default='v6',
                        help='Target branch to make a backport')
    parser.add_argument('--debug', action='store_true')
    parser.add_argument(
        '--continue',
        action='store_true',
        dest='is_continue',
        help=
        'Continues the process suspended by conflict situation. Run from the working tree directory.'
    )
    parser.add_argument(
        '--abort-before-push',
        action='store_true',
        help=
        'Abort the procedure before making an push. Useful if you want to make some modification to the backport branch. Use --continue to make an actual push after making modification.'
    )
    args = parser.parse_args(args)

    target_branch = args.branch
    if args.repo == 'chainer':
        organ_name, repo_name = 'chainer', 'chainer'
    elif args.repo == 'cupy':
        organ_name, repo_name = 'cupy', 'cupy'
    else:
        assert False

    github_token = args.token

    if args.debug:
        github.enable_console_debug_logging()

    app = App(github_token, organ_name=organ_name, repo_name=repo_name)

    app.run(pr_num=args.pr,
            target_branch=target_branch,
            is_continue=args.is_continue,
            abort_before_push=args.abort_before_push)
Example #3
0
def main():
    debug_mode = len(sys.argv) >= 2 and 'debug' in sys.argv[1].casefold()
    t = Terminal()
    if debug_mode:
        enable_console_debug_logging()
    gh = Github(os.getenv('CONTENTBOT_GH_ADMIN_TOKEN'), verify=False)
    organization = 'demisto'
    repo = 'content'
    content_repo = gh.get_repo(f'{organization}/{repo}')

    stale_non_contrib_branches = get_non_contributor_stale_branch_names(
        content_repo)
    for branch_name in stale_non_contrib_branches:
        try:
            base_branch = 'master'
            if not is_suitable_for_pr(content_repo, branch_name):
                print(f'Branch {branch_name} is not ahead of {base_branch} '
                      'and therefore not suited for a posterity PR')
                print(
                    f'Deleting stale branch {branch_name} without creating a postery PR'
                )
                content_repo.get_git_ref(f'heads/{branch_name}').delete()
            else:
                print(f'Creating PR for {branch_name}')
                title = branch_name
                body = (
                    f'## Description\r\nPosterity PR Created for the branch "{branch_name}"'
                    ' so that it may be restored if necessary')
                pr = content_repo.create_pull(title=title,
                                              body=body,
                                              base=base_branch,
                                              head=branch_name,
                                              draft=False)
                print(
                    f'{t.cyan}Posterity PR Created - {pr.html_url}{t.normal}')
                pr.add_to_labels('stale-branch')
                pr.edit(state='closed')
                print(f'{t.cyan}Posterity PR Closed{t.normal}')
                print(f'Deleting {branch_name}')
                branch_ref = content_repo.get_git_ref(f'heads/{branch_name}')
                branch_ref.delete()
        except Exception as e:
            print(
                f"{t.red}Deletion of {branch_name} encountered an issue: {str(e)}{t.normal}"
            )

    if debug_mode:
        print(f'{stale_non_contrib_branches=}')
 def __init__(self, access_token, repository, debug=False):
     if debug:
         enable_console_debug_logging()
     self.access_token = access_token
     retry = Retry(
         total=30,
         connect=5,
         read=5,
         backoff_factor=0.5,
         status_forcelist=(500, 502, 503, 504)
     )
     self.github = Github(access_token, timeout=30, retry=retry, per_page=300)
     try:
         self.repo = self.github.get_repo(repository)
     except UnknownObjectException:
         raise Exception("Failed to get the repository '{}'".format(repository))
Example #5
0
def _process_report(args):
    """
    A ``cli_tools`` processor that adapts between the command line
    interface and the ``report()`` function.  The processor obtains a
    ``github.Github`` object, using the authentication data collected
    by the argument processor; it then selects the correct output
    stream and ``repo_callback`` function for the verbosity level.
    After ``report()`` returns, it ensures that the output stream is
    closed, if required.

    :param args: The ``argparse.Namespace`` object constructed by
                 ``cli_tools``.

    :returns: A ``cli_tools`` processor generator.
    """

    # Enable debugging output
    if args.debug:
        github.enable_console_debug_logging()

    # Get the user's password
    password = args.password
    if not password:
        password = getpass.getpass(u'Password for %s> ' % args.username)

    # Create a github handle
    args.gh = github.Github(args.username, password, args.github_url)

    # Select the correct output stream
    if args.output == '-':
        args.stream = sys.stdout
        close = False
    else:
        args.stream = io.open(args.output, 'w', encoding='utf-8')
        close = True

    # Select the correct verbosity
    args.repo_callback = verbosity[args.verbose]

    # Generate the report as requested
    try:
        yield
    finally:
        # Make sure the stream gets closed
        if close:
            args.stream.close()
def main():
    debug_mode = len(sys.argv) >= 2 and 'debug' in sys.argv[1].casefold
    if debug_mode:
        enable_console_debug_logging()
    gh = Github(os.getenv('CONTENTBOT_GH_ADMIN_TOKEN'), verify=False)
    organization = 'demisto'
    repo = 'content'
    content_repo = gh.get_repo(f'{organization}/{repo}')

    master_sha = get_master_commit_sha(content_repo)
    contrib_base_branches = get_branch_names_with_contrib(content_repo)
    for branch_name in contrib_base_branches:
        git_ref = content_repo.get_git_ref(f'heads/{branch_name}')
        print(f'Updating branch "{branch_name}" to sha "{master_sha}"')
        git_ref.edit(master_sha, force=True)

    if debug_mode:
        print(f'{contrib_base_branches=}')
Example #7
0
 def __init__(self, args_sequence: Sequence[str],
              cache_options: Sequence[str],
              input_caches_options: Sequence[str], simulate: bool,
              main_args_parser: CustomArgumentParser):
     Engine.__init__(self, args_sequence, cache_options,
                     input_caches_options, simulate, main_args_parser)
     # noinspection PyUnresolvedReferences
     self._decomposer = ExclusionInclusionDecomposer(self.deep_simplify)
     self._translator = SpacesTranslator()
     # noinspection PyUnresolvedReferences
     self._query_issuer = GithubV3QueryIssuer(
         self.user, self.passw, self.url, self.search_type,
         self.query_max_length, self.admit_long_query, self.total_retry,
         self.connect_retry, self.read_retry, self.status_retry,
         self.backoff_factor, self.backoff_max, self.waiting_factor,
         not simulate)
     # noinspection PyUnresolvedReferences
     if self.logging:
         github.enable_console_debug_logging()
Example #8
0
def main():
    args = arguments_handler()
    ref_branch = args.branch_name
    debug_mode = len(sys.argv) >= 2 and 'debug' in sys.argv[1].casefold()
    if debug_mode:
        enable_console_debug_logging()
    gh = Github(os.getenv('CONTENTBOT_GH_ADMIN_TOKEN'), verify=False)
    organization = 'demisto'
    repo = 'content'
    content_repo = gh.get_repo(f'{organization}/{repo}')

    master_sha = get_master_commit_sha(content_repo)
    if ref_branch:
        # Case this flow was triggered on a specific branch
        contrib_base_branches = [ref_branch]
    else:
        # Case we are running scheduled job - detect all contrib/ base branches.
        contrib_base_branches = get_branch_names_with_contrib(content_repo)

    print(f'Updating {contrib_base_branches=}')
    for branch_name in contrib_base_branches:
        update_branch(content_repo, branch_name, master_sha)
def main():
    debug_mode = len(sys.argv) >= 2 and 'debug' in sys.argv[1].casefold()
    t = Terminal()
    if debug_mode:
        enable_console_debug_logging()
    gh = Github(os.getenv('CONTENTBOT_GH_ADMIN_TOKEN'), verify=False)
    organization = 'demisto'
    repo = 'content'
    content_repo = gh.get_repo(f'{organization}/{repo}')

    stale_contrib_branches = get_stale_branch_names_with_contrib(content_repo)
    for branch_name in stale_contrib_branches:
        try:
            print(f'Deleting {branch_name}')
            branch_ref = content_repo.get_git_ref(f'heads/{branch_name}')
            branch_ref.delete()
        except Exception as e:
            print(
                f"{t.red}Deletion of {branch_name} encountered an issue: {str(e)}{t.normal}"
            )

    if debug_mode:
        print(f'{stale_contrib_branches=}')
Example #10
0
    def __init__(self, bot):
        self.bot = bot
        self.log = bot.log

        if "github_plugin" not in bot.config:
            raise RuntimeError(
                "No [github_plugin] section set in the configuration")
        else:
            if "token" not in bot.config["github_plugin"]:
                raise RuntimeError("No Github API token declared")
            elif "repository" not in bot.config["github_plugin"]:
                raise RuntimeError("No target repository declared")

        self.token = bot.config["github_plugin"]["token"]
        self.repository = bot.config["github_plugin"]["repository"]

        self.max_search_results = 3
        if "max_search_results" in bot.config["github_plugin"]:
            self.max_search_results = bot.config["github_plugin"][
                "max_search_results"]

        if bot.config["debug"]:
            github.enable_console_debug_logging()

        try:
            self.github = github.Github(self.token)
        except github.GithubException as e:
            raise RuntimeError(
                "Unable to initialize the Github API wrapper: %s (%s)" %
                (e.data["message"], e.status))

        try:
            self.repo = self.github.get_repo(self.repository)
        except github.GithubException as e:
            raise RuntimeError(
                "Unable to fetch the target repository: %s (%s)" %
                (e.data["message"], e.status))
Example #11
0
def _process_perform_audit(args):
    """
    A ``cli_tools`` processor that adapts between the command line
    interface and the ``audit()`` function.  The processor builds a
    ``Context`` object, which will be used to carry various defaults.
    It also selects the correct output stream.  After ``audit()``
    returns, it ensures that the output stream is closed, if required.

    :param args: The ``argparse.Namespace`` object constructed by
                 ``cli_tools``.

    :returns: A ``cli_tools`` processor generator.
    """

    # Enable debugging output
    if args.debug:
        github.enable_console_debug_logging()

    # Construct the context
    args.ctxt = Context(args)

    # Select the correct output stream
    if args.output == '-':
        args.stream = sys.stdout
        close = False
    else:
        args.stream = io.open(args.output, 'w', encoding='utf-8')
        close = True

    # Generate the audit report as requested
    try:
        yield
    finally:
        # Make sure the stream gets closed
        if close:
            args.stream.close()
Example #12
0
def main(args_: list[str]) -> ExitCode:
    parser = argparse.ArgumentParser()
    parser.add_argument('--repo',
                        required=True,
                        choices=('chainer', 'cupy', 'cupy-release-tools',
                                 'sandbox'),
                        help='target repository')
    parser.add_argument('--token',
                        type=str,
                        default=None,
                        help='GitHub access token.')
    parser.add_argument(
        '--pr',
        default=None,
        type=int,
        help='The original PR number to be backported. Exclusive with --sha')
    parser.add_argument(
        '--sha',
        default=None,
        type=str,
        help='The SHA hash of the merge commit. Exclusive with --pr')
    parser.add_argument('--branch',
                        type=str,
                        default='v11',
                        help='Target branch to make a backport')
    parser.add_argument('--https',
                        action='store_true',
                        default=False,
                        help='Use HTTPS instead of SSH for git access')
    parser.add_argument('--debug', action='store_true')
    parser.add_argument(
        '--continue',
        action='store_true',
        dest='is_continue',
        help='Continues the process suspended by conflict situation. Run from'
        ' the working tree directory.')
    parser.add_argument(
        '--abort-before-push',
        action='store_true',
        help='Abort the procedure before making an push. Useful if you want to'
        ' make some modification to the backport branch. Use --continue to'
        ' make an actual push after making modification.')
    parser.add_argument(
        '--bot',
        action='store_true',
        default=False,
        help='Leave a comment when backport failed. This is intended for use'
        ' with GitHub workflow.')
    args = parser.parse_args(args_)

    target_branch = args.branch
    if args.repo == 'chainer':
        organ_name, repo_name = 'chainer', 'chainer'
    elif args.repo == 'cupy':
        organ_name, repo_name = 'cupy', 'cupy'
    elif args.repo == 'cupy-release-tools':
        organ_name, repo_name = 'cupy', 'cupy-release-tools'
    elif args.repo == 'sandbox':
        organ_name, repo_name = 'chainer-ci', 'backport-sandbox'
    else:
        assert False

    if args.pr is None and args.sha is None:
        parser.error('Specify only --pr or --sha')

    if args.pr is not None and args.sha is not None:
        parser.error('Can\'t specify both --pr and --sha')

    github_token = args.token
    if github_token is None:
        if 'BACKPORT_GITHUB_TOKEN' not in os.environ:
            parser.error('GitHub Access token must be specified with '
                         '--token or BACKPORT_GITHUB_TOKEN '
                         'environment variable.')
        github_token = os.environ['BACKPORT_GITHUB_TOKEN']

    if args.debug:
        github.enable_console_debug_logging()

    app = App(github_token, organ_name=organ_name, repo_name=repo_name)

    run_func: Callable[..., ExitCode] = app.run_cli
    if args.bot:
        print('Running as bot mode (will leave a comment when failed).')
        run_func = app.run_bot

    return run_func(pr_num=args.pr,
                    sha=args.sha,
                    target_branch=target_branch,
                    is_continue=args.is_continue,
                    abort_before_push=args.abort_before_push,
                    https=args.https)
Example #13
0
import json

from github import Github, enable_console_debug_logging

enable_console_debug_logging()

with open("./token.json", "r") as f:
    auth_token = json.load(f)["token"]

g = Github(auth_token)

repo = next(iter(g.get_user().get_repos()))
# this fails with a 403
print(repo.get_views_traffic())
Example #14
0
from nudgebot.tasks import celery_app


argparser = argparse.ArgumentParser()
subparsers = argparser.add_subparsers(help='Operations', dest='operation')
run_server_parser = subparsers.add_parser('run_server', help='Running the Bot')
run_celery_parser = subparsers.add_parser('run_celery', help='Running the celery app')
dump_db_parser = subparsers.add_parser('dump_db', help='Dumping all the DB content')
dump_db_parser.add_argument('--filename', '-f', help='The file path to dump the DB content', default=None)
clear_db_parser = subparsers.add_parser('clear_db', help='Clearing all the DB content (DANGER)')
clear_db_parser.add_argument('--force', '-f', dest='force', help='Force operation (without prompt)',
                             action='store_true', default=False)


if config().config.debug_mode:
    github.enable_console_debug_logging()


def parse_command(namespace):
    if namespace.operation == 'run_server':
        import nudgebot.server as server
        server.run()
    elif namespace.operation == 'run_celery':
        celery_app.worker_main(['--loglevel=info', '--beat'])
    elif namespace.operation == 'dump_db':
        print(db().dump(namespace.filename))
    elif namespace.operation == 'clear_db':
        if namespace.force:
            db().clear_db()
        else:
            ans = raw_input('Are you sure? this operation cannot be undone (n/y): ')
Example #15
0
def main():
    global IS_AUTHORIZED
    logging.basicConfig(level=logging.INFO)

    parser = init_parser()
    args = parser.parse_args()

    if args.quiet:
        LOGGER.setLevel(logging.WARN)
    elif args.debug:
        LOGGER.setLevel(logging.DEBUG)
        github.enable_console_debug_logging()

    # Process args
    if args.quiet:
        args.git.append("--quiet")
    if args.include_everything:
        args.account = True
        args.include_starred = True
        args.include_watched = True
        args.include_followers = True
        args.include_following = True
        args.include_issues = True
        args.include_issue_comments = True
        args.include_issue_events = True
        args.include_pulls = True
        args.include_pull_comments = True
        args.include_pull_commits = True
        args.include_keys = True
        args.include_releases = True
        args.include_assets = True
        args.include_wiki = True
    if args.include_starred or args.include_watched or args.include_followers \
       or args.include_following or args.include_keys:
        args.account = True

    args.backupdir = args.backupdir.rstrip("/")

    # Make the connection to Github here.
    config = {}
    if args.password == False:
        # no password option given, continue unauthenticated
        # unauthenticated users can only use http git method
        args.type = 'http'
    elif args.password == None:
        # password option given, but no password value given
        config = {'login_or_token': args.login_or_token}
        if os.path.isfile(CONFFILE):
            cfg = ConfigParser()
            cfg.read(CONFFILE)
            try:
                config['password'] = cfg.get('github-backup', 'APITOKEN')
            except:
                config['password'] = cfg.get('github-backup', 'PASSWORD')
        else:
            password = getpass.getpass('Enter password for {}: '.format(
                config['login_or_token']))
            if password:
                config['password'] = password
    else:
        config = {'login_or_token': args.login_or_token}
        config['password'] = args.password

    LOGGER.debug("Github config: %r", config)
    global gh
    gh = github.Github(**config)

    # Check that backup dir exists
    if not os.path.exists(args.backupdir):
        mkdir_p(args.backupdir)

    if args.organization:
        if args.password:
            account = gh.get_organization(args.org)
        else:
            account = gh.get_organization(args.login_or_token)
    else:
        if args.username:
            account = gh.get_user(args.username)
        elif config.get('password', None):
            account = gh.get_user()
        else:
            account = gh.get_user(args.login_or_token)

    IS_AUTHORIZED = isinstance(account,
                               github.AuthenticatedUser.AuthenticatedUser)
    assert not (bool(config.get('password', None)) ^ IS_AUTHORIZED), account

    if args.include_keys and not IS_AUTHORIZED:
        LOGGER.info(
            "Cannot backup keys with unauthenticated account, ignoring...")
        args.include_keys = False

    filters = {}
    if IS_AUTHORIZED:
        # Get all repos
        filters = {
            'affiliation': ','.join(args.affiliation),
            'visibility': args.visibility
        }

    if args.account:
        process_account(gh, account, args)

    if args.include_gists:
        for gist in get_account_gists(account):
            RepositoryBackup(gist, args).backup()

    if args.include_starred_gists and hasattr(account, 'get_starred_gists'):
        for gist in get_account_starred_gists(account):
            RepositoryBackup(gist, args).backup()

    if not args.skip_repos:
        repos = get_account_repos(account, **filters)
        for repo in repos:
            if args.skip_forks and repo.fork:
                continue

            RepositoryBackup(repo, args).backup()
Example #16
0
def setup_logging(verbosity=0):
    """Enable pygithub HTTP request tracing if verbosity is 2+."""
    if verbosity and verbosity > 1:
        github.enable_console_debug_logging()
Example #17
0
    def __init__(self, gh_auth_token, debug=False):
        if debug:
            enable_console_debug_logging()

        self._connection = Github(gh_auth_token)
Example #18
0
def main(options):
    b2g_config = read_config_file(options.b2g_config[0])
    _user = b2g_config.get("github", "user")
    _token = b2g_config.get("github", "token")

    if options.debug:
        github.enable_console_debug_logging()
    gh = github.Github(_user, _token)

    if options.report_rate_limit:
        rl = gh.get_rate_limit()
        print(rl)
        return 0

    resume = options.resume[0]

    friendly_pause = 5

    convert_config = read_config_file(options.convert_config[0])
    _organization = convert_config.get("github", "organization")
    _repository = convert_config.get("github", "repository")

    # get the authorized user
    gh_auth_user = gh.get_user()

    try:
        gh_repo = gh_auth_user.get_repo(_repository)
    except github.UnknownObjectException:
        try:
            gh_org = gh.get_organization(_organization)
            gh_repo = gh_org.get_repo(_repository)
        except github.UnknownObjectException:
            gh_repo = None

    if not resume:
        # delete existing test repository
        print('Deleting existing repository: {0}'.format(_repository))
        try:
            if gh_repo:
                gh_repo.delete()
        except github.UnknownObjectException:
            # repository doesn't exist
            pass

        time.sleep(friendly_pause)

        # recreate test repo
        print('Creating repository: {0}'.format(_repository))
        gh_repo = gh_auth_user.create_repo(_repository,
                                           description=convert_config.get(
                                               'github', 'description'),
                                           has_issues=True,
                                           auto_init=False)

        time.sleep(friendly_pause)

    if not gh_repo:
        msg = ("Could not find or create github repository object "
               "for the authenticated user: {0}/{1}".format(
                   _organization, _repository))
        raise RuntimeError(msg)

    if False:
        # create a lookup table of xml users?
        # fetch user list
        gh_users_all = gh.search_users('bandre-ucar')
        gh_users = {}
        for user in gh_users_all:
            gh_users[user.login] = user
        print(gh_users)

    # add new milestones to the repo
    print("Processing milestones.")
    new_milestones = convert_config.get('github', 'milestones').split(',')
    gh_milestones = gh_repo.get_milestones()
    for name in new_milestones:
        name = name.strip().lower()
        found_milestone = False
        for milestone in gh_milestones:
            if name == milestone.title.lower():
                found_milestone = True
        if not found_milestone:
            gh_repo.create_milestone(name)
    # save the updated list
    gh_milestones = gh_repo.get_milestones()
    milestones = {}
    for ghm in gh_milestones:
        milestones[ghm.title.lower()] = ghm
    # create map for converting bugzilla milestones to github
    milestone_map = {}
    mm = convert_config.options('milestone_map')
    for m in mm:
        milestone_map[m] = convert_config.get('milestone_map', m)

    # add new labels to the repo
    print("Processing labels")
    label_names = convert_config.get('github', 'labels').split(',')
    labels = {}
    gh_labels = gh_repo.get_labels()
    for ghl in gh_labels:
        labels[ghl.name] = ghl
    for name in label_names:
        name = name.strip().lower()
        if name not in labels:
            label = gh_repo.create_label(name, 'ef13e8')
            labels[name] = label
    # create map for tranlating bugzilla labels to github
    label_map = {}
    lm = convert_config.options('label_map')
    for l in lm:
        label_map[l.lower()] = convert_config.get('label_map', l).strip()

    # create the xml bug list
    xml_bug_list = convert_config.get('bugzilla', 'xml_bug_list')
    bugz_list_xml = read_bugzilla_xml(xml_bug_list)

    # add bugs to the repo
    max_attempts = 100
    found_start_bug = True
    if resume:
        found_start_bug = False
    for bug in bugz_list_xml.findall('./bug'):
        bug_id = bug.find('./bug_id').text
        if bug_id == resume:
            found_start_bug = True
        if not found_start_bug:
            print("Skipping bug {0}".format(bug_id))
            continue
        else:
            print('Processing bug {0}'.format(bug_id))

        issue_title = bug.find('./short_desc')
        # check for labels
        new_labels = []
        update_issue_label_list(bug, 'priority', labels, label_map, new_labels)
        update_issue_label_list(bug, 'bug_severity', labels, label_map,
                                new_labels)
        # check for milestone
        new_milestone = None
        target_milestone = bug.find('./target_milestone')
        if target_milestone is not None:
            tmilestone = target_milestone.text
            tmilestone = tmilestone.strip().lower()
            new_milestone = milestones[milestone_map[tmilestone]]

        # search for optional fields that don't directly translate to gh
        cc_list = optional_list(bug, 'cc')
        blocks_list = optional_list(bug, 'blocks')
        depends_list = optional_list(bug, 'dependson')
        attachment_list = create_attachment_list(bug)
        # all text is contained in comments. comment 0 is the main
        # issue text.
        gh_issue = None
        for comment in bug.findall('./long_desc'):
            time.sleep(friendly_pause)
            comment_count = comment.find('./comment_count').text
            object_created = False
            attempts = 0
            if comment_count == '0':
                # create the issue, comment 0 is main issue text
                body_text = b2g_comment(bug_id,
                                        comment,
                                        main_issue=True,
                                        cc_list=cc_list,
                                        blocks_list=blocks_list,
                                        depends_list=depends_list,
                                        attachment_list=attachment_list)

                while (not object_created) and (attempts < max_attempts):
                    try:
                        gh_issue = gh_repo.create_issue(
                            issue_title.text,
                            body=body_text,
                            milestone=new_milestone,
                            labels=new_labels)
                        object_created = True
                    except github.GithubException as error:
                        check_for_abuse_error(error.status, error.data)
                        attempts += 1
            else:
                # additional comments to the issue
                body_text = b2g_comment(bug_id, comment)
                while (not object_created) and (attempts < max_attempts):
                    try:
                        gh_issue.create_comment(body_text)
                        object_created = True
                    except github.GithubException as error:
                        check_for_abuse_error(error.status, error.data)
                        attempts += 1

    return 0
Example #19
0
from wtforms.ext.sqlalchemy.orm import model_form
from functools import wraps
from flask import Flask, render_template, flash, request, url_for, redirect, session

app = Flask(__name__, instance_relative_config=True)
app.config.from_object('config')
app.config.from_pyfile( os.path.join( os.path.dirname(__file__) , '../instance/config.py') )

from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy(app)

from flask_mail import Mail, Message
mail = Mail(app)

from flask_bootstrap import Bootstrap
Bootstrap(app)

import tweepy
tweepy_auth = tweepy.OAuthHandler( app.config['TWEEPY_CONSUMER_KEY'], app.config['TWEEPY_CONSUMER_SECRET'])
tweepy_auth.set_access_token( app.config['TWEEPY_ACCESS_TOKEN_KEY'], app.config['TWEEPY_ACCESS_TOKEN_SECRET'] )
tweepy_API = tweepy.API(tweepy_auth)


import github as pyGithub
if app.config['PYGITHUB_DEBUG']:
    pyGithub.enable_console_debug_logging()
GithubAPI = pyGithub.Github(per_page=100, client_id=app.config['GITHUB_CLIENT_ID'], client_secret=app.config['GITHUB_CLIENT_SECRET'] )

from sktimeline.models import *
from sktimeline.views import *