def main()

in releasedocmaker/src/main/python/releasedocmaker/__init__.py [0:0]


def main():  # pylint: disable=too-many-statements, too-many-branches, too-many-locals
    """ hey, it's main """
    global BACKWARD_INCOMPATIBLE_LABEL  #pylint: disable=global-statement
    global SORTTYPE  #pylint: disable=global-statement
    global SORTORDER  #pylint: disable=global-statement
    global NUM_RETRIES  #pylint: disable=global-statement
    global EXTENSION  #pylint: disable=global-statement

    logging.basicConfig(format='%(message)s', level=logging.DEBUG)
    options = parse_args()

    if options.output_directory is not None:
        # Create the output directory if it does not exist.
        try:
            outputpath = pathlib.Path(options.output_directory).resolve()
            outputpath.mkdir(parents=True, exist_ok=True)
        except OSError as exc:
            logging.error("Unable to create output directory %s: %s, %s",
                          options.output_directory, exc.errno, exc.strerror)
            sys.exit(1)
        os.chdir(options.output_directory)

    if options.incompatible_label is not None:
        BACKWARD_INCOMPATIBLE_LABEL = options.incompatible_label

    if options.extension is not None:
        EXTENSION = options.extension

    projects = options.projects

    if options.range is True:
        versions = GetVersions(options.versions, projects,
                               options.base_url).getlist()
    else:
        versions = [ReleaseVersion(v) for v in options.versions]
    versions = sorted(versions)

    SORTTYPE = options.sorttype
    SORTORDER = options.sortorder

    if options.title is None:
        title = projects[0]
    else:
        title = options.title

    if options.retries is not None:
        NUM_RETRIES = options.retries[0]

    haderrors = False

    for version in versions:
        vstr = str(version)
        linter = Linter(vstr, options)
        jlist = sorted(JiraIter(options.base_url, vstr, projects))
        if not jlist and not options.empty:
            logging.warning(
                "There is no issue which has the specified version: %s",
                version)
            continue

        if vstr in RELEASE_VERSION:
            reldate = RELEASE_VERSION[vstr]
        elif options.usetoday:
            reldate = strftime("%Y-%m-%d", gmtime())
        else:
            reldate = f"Unreleased (as of {strftime('%Y-%m-%d', gmtime())})"

        if not os.path.exists(vstr) and options.versiondirs:
            os.mkdir(vstr)

        if options.versionfiles and options.versiondirs:
            reloutputs = Outputs(
                "%(ver)s/RELEASENOTES.%(ver)s%(ext)s",
                "%(ver)s/RELEASENOTES.%(key)s.%(ver)s%(ext)s", [], {
                    "ver": version,
                    "date": reldate,
                    "title": title,
                    "ext": EXTENSION
                })
            choutputs = Outputs("%(ver)s/CHANGELOG.%(ver)s%(ext)s",
                                "%(ver)s/CHANGELOG.%(key)s.%(ver)s%(ext)s", [],
                                {
                                    "ver": version,
                                    "date": reldate,
                                    "title": title,
                                    "ext": EXTENSION
                                })
        elif options.versiondirs:
            reloutputs = Outputs("%(ver)s/RELEASENOTES%(ext)s",
                                 "%(ver)s/RELEASENOTES.%(key)s%(ext)s", [], {
                                     "ver": version,
                                     "date": reldate,
                                     "title": title,
                                     "ext": EXTENSION
                                 })
            choutputs = Outputs("%(ver)s/CHANGELOG%(ext)s",
                                "%(ver)s/CHANGELOG.%(key)s%(ext)s", [], {
                                    "ver": version,
                                    "date": reldate,
                                    "title": title,
                                    "ext": EXTENSION
                                })
        elif options.versionfiles:
            reloutputs = Outputs("RELEASENOTES.%(ver)s%(ext)s",
                                 "RELEASENOTES.%(key)s.%(ver)s%(ext)s", [], {
                                     "ver": version,
                                     "date": reldate,
                                     "title": title,
                                     "ext": EXTENSION
                                 })
            choutputs = Outputs("CHANGELOG.%(ver)s%(ext)s",
                                "CHANGELOG.%(key)s.%(ver)s%(ext)s", [], {
                                    "ver": version,
                                    "date": reldate,
                                    "title": title,
                                    "ext": EXTENSION
                                })
        else:
            reloutputs = Outputs("RELEASENOTES%(ext)s",
                                 "RELEASENOTES.%(key)s%(ext)s", [], {
                                     "ver": version,
                                     "date": reldate,
                                     "title": title,
                                     "ext": EXTENSION
                                 })
            choutputs = Outputs("CHANGELOG%(ext)s", "CHANGELOG.%(key)s%(ext)s",
                                [], {
                                    "ver": version,
                                    "date": reldate,
                                    "title": title,
                                    "ext": EXTENSION
                                })

        if options.license is True:
            reloutputs.write_all(ASF_LICENSE)
            choutputs.write_all(ASF_LICENSE)

        relhead = '# %(title)s %(key)s %(ver)s Release Notes\n\n' \
                  'These release notes cover new developer and user-facing ' \
                  'incompatibilities, important issues, features, and major improvements.\n\n'
        chhead = '# %(title)s Changelog\n\n' \
                 '## Release %(ver)s - %(date)s\n'\
                 '\n'

        reloutputs.write_all(relhead)
        choutputs.write_all(chhead)

        incompatlist = []
        importantlist = []
        buglist = []
        improvementlist = []
        newfeaturelist = []
        subtasklist = []
        tasklist = []
        testlist = []
        otherlist = []

        for jira in jlist:
            if jira.get_incompatible_change():
                incompatlist.append(jira)
            elif jira.get_important():
                importantlist.append(jira)
            elif jira.get_type() == "Bug":
                buglist.append(jira)
            elif jira.get_type() == "Improvement":
                improvementlist.append(jira)
            elif jira.get_type() == "New Feature":
                newfeaturelist.append(jira)
            elif jira.get_type() == "Sub-task":
                subtasklist.append(jira)
            elif jira.get_type() == "Task":
                tasklist.append(jira)
            elif jira.get_type() == "Test":
                testlist.append(jira)
            else:
                otherlist.append(jira)

            line = generate_changelog_line_md(options.base_url, jira)

            if jira.get_release_note() or \
               jira.get_incompatible_change() or jira.get_important():
                reloutputs.write_key_raw(jira.get_project(), "\n---\n\n")
                reloutputs.write_key_raw(jira.get_project(), line)
                if not jira.get_release_note():
                    line = '\n**WARNING: No release note provided for this change.**\n\n'
                else:
                    line = f'\n{processrelnote(jira.get_release_note())}\n\n'
                reloutputs.write_key_raw(jira.get_project(), line)

            linter.lint(jira)

        if linter.enabled:
            if linter.had_errors():
                logging.error(linter.message())
                haderrors = True
                if os.path.exists(vstr):
                    shutil.rmtree(vstr)
                continue

        reloutputs.write_all("\n\n")
        reloutputs.close()

        if options.skip_credits:
            change_header21 = "| JIRA | Summary | Priority | " + \
                     "Component |\n"
            change_header22 = "|:---- |:---- | :--- |:---- |\n"
        else:
            change_header21 = "| JIRA | Summary | Priority | " + \
                         "Component | Reporter | Contributor |\n"
            change_header22 = "|:---- |:---- | :--- |:---- |:---- |:---- |\n"

        if incompatlist:
            choutputs.write_all("### INCOMPATIBLE CHANGES:\n\n")
            choutputs.write_all(change_header21)
            choutputs.write_all(change_header22)
            choutputs.write_list(incompatlist, options.skip_credits,
                                 options.base_url)

        if importantlist:
            choutputs.write_all("\n\n### IMPORTANT ISSUES:\n\n")
            choutputs.write_all(change_header21)
            choutputs.write_all(change_header22)
            choutputs.write_list(importantlist, options.skip_credits,
                                 options.base_url)

        if newfeaturelist:
            choutputs.write_all("\n\n### NEW FEATURES:\n\n")
            choutputs.write_all(change_header21)
            choutputs.write_all(change_header22)
            choutputs.write_list(newfeaturelist, options.skip_credits,
                                 options.base_url)

        if improvementlist:
            choutputs.write_all("\n\n### IMPROVEMENTS:\n\n")
            choutputs.write_all(change_header21)
            choutputs.write_all(change_header22)
            choutputs.write_list(improvementlist, options.skip_credits,
                                 options.base_url)

        if buglist:
            choutputs.write_all("\n\n### BUG FIXES:\n\n")
            choutputs.write_all(change_header21)
            choutputs.write_all(change_header22)
            choutputs.write_list(buglist, options.skip_credits,
                                 options.base_url)

        if testlist:
            choutputs.write_all("\n\n### TESTS:\n\n")
            choutputs.write_all(change_header21)
            choutputs.write_all(change_header22)
            choutputs.write_list(testlist, options.skip_credits,
                                 options.base_url)

        if subtasklist:
            choutputs.write_all("\n\n### SUB-TASKS:\n\n")
            choutputs.write_all(change_header21)
            choutputs.write_all(change_header22)
            choutputs.write_list(subtasklist, options.skip_credits,
                                 options.base_url)

        if tasklist or otherlist:
            choutputs.write_all("\n\n### OTHER:\n\n")
            choutputs.write_all(change_header21)
            choutputs.write_all(change_header22)
            choutputs.write_list(otherlist, options.skip_credits,
                                 options.base_url)
            choutputs.write_list(tasklist, options.skip_credits,
                                 options.base_url)

        choutputs.write_all("\n\n")
        choutputs.close()

    if options.index:
        buildindex(title, options.license)
        buildreadme(title, options.license)

    if options.prettyindex:
        buildprettyindex(title, options.license)

    if haderrors is True:
        sys.exit(1)