def perform_migrate_roadmap(args):
    redmine = RedmineClient(args.redmine_key, args.no_verify)
    gitlab = GitlabClient(args.gitlab_key, args.no_verify)

    redmine_project = RedmineProject(args.redmine_project_url, redmine)
    gitlab_project = GitlabProject(args.gitlab_project_url, gitlab)

    checks = [
        #(check_no_milestone, 'Gitlab project has no pre-existing milestone'),
        (check_origin_milestone, 'Redmine project contains versions'),
    ]
    for i in checks:
        check(
            *i, redmine_project=redmine_project,
            gitlab_project=gitlab_project)

    versions = redmine_project.get_versions()
    if args.filter:
        name_filter = re.compile(args.filter)
        versions = [version for version in versions if name_filter.match(version['name'])]
    versions_data = (convert_version(i) for i in versions)

    for data, meta in versions_data:
        if args.check:
            log.info("Would create version {}".format(data))
        else:
            created = gitlab_project.create_milestone(data, meta)
            log.info("Version {}".format(created['title']))
def perform_migrate_roadmap(args):
    redmine = RedmineClient(args.redmine_key)
    gitlab = GitlabClient(args.gitlab_key)

    redmine_project = RedmineProject(args.redmine_project_url, redmine)
    gitlab_project = GitlabProject(args.gitlab_project_url, gitlab)

    checks = [
        (check_no_milestone, 'Gitlab project has no pre-existing milestone'),
        (check_origin_milestone, 'Redmine project contains versions'),
    ]
    for i in checks:
        check(
            *i, redmine_project=redmine_project,
            gitlab_project=gitlab_project)

    versions = redmine_project.get_versions()
    versions_data = (convert_version(i) for i in versions)

    for data, meta in versions_data:
        if args.check:
            log.info("Would create version {}".format(data))
        else:
            created = gitlab_project.create_milestone(data, meta)
            log.info("Version {}".format(created['title']))
示例#3
0
 def test_get_versions(self):
     project = RedmineProject(
         'http://localhost:9000/projects/diaspora-site', self.client)
     self.assertEqual(len(project.get_versions()), 2)
 def test_get_versions(self):
     project = RedmineProject(
         'http://localhost:9000/projects/diaspora-site',
         self.client)
     self.assertEqual(len(project.get_versions()), 2)
示例#5
0
def perform_migrate_roadmap(args):
    redmine = RedmineClient(args.redmine_key, args.no_verify)
    gitlab = GitlabClient(args.gitlab_key, args.no_verify)

    redmine_project = RedmineProject(args.redmine_project_url, redmine)
    gitlab_project = GitlabProject(args.gitlab_project_url, gitlab)

    # auto create milestones
    milestones_data = []
    if args.auto_milestones:
        match = re.match("^(monthly|yearly):(\d{4}(-[01]\d)?)$",
                         args.auto_milestones)
        if not match:
            log.error(
                "--auto-milestone must be formed as (monthly|yearly):<start_date>"
            )
            exit(1)

        milestones_type = match.group(1)
        milestones_date = list(map(lambda x: int(x),
                                   match.group(2).split("-")))

        if milestones_type == "monthly" and len(milestones_date) == 1:
            milestones_date.append(1)

        log.info("Creating %s milestones, from %s" %
                 (milestones_type, "-".join(
                     map(lambda x: str(x).zfill(2), milestones_date))))

        day = date(milestones_date[0], milestones_date[1], 1)
        today = date.today()

        while day <= today:
            month_days = monthrange(day.year, day.month)[1]

            milestone = {
                "title": day.strftime("%Y-%m"),
                "description": "\n\n*(auto-generated milestone)*",
                "start_date": day.strftime("%Y-%m-%d"),
                "due_date": day.replace(day=month_days).strftime("%Y-%m-%d"),
            }

            must_close = True

            if day > today - timedelta(days=4 * 31):  # keep last 4 months open
                must_close = False

            meta = {
                "must_close": must_close,
            }
            milestones_data.append((milestone, meta))

            # next month
            day = day + timedelta(days=month_days)

    checks = [
        #(check_no_milestone, 'Gitlab project has no pre-existing milestone'),
        (check_origin_milestone, 'Redmine project contains versions'),
    ]
    for i in checks:
        check(*i,
              redmine_project=redmine_project,
              gitlab_project=gitlab_project)

    versions = redmine_project.get_versions()
    versions_data = [convert_version(i) for i in versions]

    if milestones_data:
        versions_titles = []
        for data, meta in versions_data:
            versions_titles.append(data['title'])

        for data, meta in milestones_data:
            if data['title'] in versions_titles:
                continue

            versions_data.append((data, meta))

    for data, meta in versions_data:
        if args.check:
            log.info("Would create version {}".format(data))
        else:
            created = gitlab_project.create_milestone(data, meta)
            log.info("Version {}".format(created['title']))