Exemplo n.º 1
0
def generate_main_md_table(repositories_holder, which_repo, days_to_generate):
    """
    Looks into repositories folders (hg_files & git files),
    filters the files to load the json's using a passfilter and calls after
    extraction functions.
    :param which_repo: tells the function for which repo to update the md
    :param days_to_generate: just a pass by parameter, used in extract json
    from git/hg and generates for the specified days.
    :param repositories_holder: repositories
    """
    from fic_modules.git import extract_json_from_git
    successfully_generated = "part from main markdown table was " \
                             "successfully generated."
    list = []
    for i in repositories_holder.get("Github"):
        position = repositories_holder.get("Github").get(i).get("order")
        list.append((position, i, "git"))
    for i in repositories_holder.get("Mercurial"):
        position = repositories_holder.get("Mercurial").get(i).get("order")
        list.append((position, i, "hg"))
    list.sort()
    for element in list:
        if (which_repo == "complete" or which_repo == "Git") and element[2] == "git":
            extract_json_from_git(element[1], days_to_generate)
            LOGGER.info("GIT %s Repository: %s", successfully_generated, element[1])

        if (which_repo == "complete" or which_repo == "Hg") and element[2] == "hg":
            extract_json_from_hg(element[1], days_to_generate)
            LOGGER.info("HG %s Repository: %s", successfully_generated, element[1])

        if which_repo != "complete" and which_repo != "Git" and which_repo != "Hg":
            LOGGER.error("No {} table was generated!".format(element[2]))
Exemplo n.º 2
0
now = datetime.now()

branch_name = 'auto-push'
try:
    # Setup environment
    subprocess.call(['git', 'checkout', 'master'])
    subprocess.call(['git', 'pull'])
    subprocess.call(['git', 'branch', '-D', branch_name])
    subprocess.call(['git', 'checkout', '-b', branch_name])
    # Run FIC
    subprocess.call(['python', 'client.py', '-c', '-l'])
    # Prepare commit
    subprocess.call(['git', 'add', 'git_files/', 'hg_files/',
                     'changelog.md', 'changelog.json'])
    commit_message = "Changelog:  " + str(datetime.utcnow()) + \
                     "\n- updated git files \n- updated hg files" \
                     "\n- updated changelog.md \n- updated changelog.json"
    subprocess.call(['git', 'commit', '-m', commit_message])
    # Push commit to origin
    subprocess.call(['git', 'push', '--set-upstream', 'origin', branch_name])
    subprocess.call(['git', 'push'])
    subprocess.call(['git', 'checkout', 'master'])
    subprocess.call(['git', 'pull'])
    print("\n\nAuto Update Process finished.")
    toaster.show_toast("FireFox Infra Changelog",
                       "Generated files have been updated")
except Exception as e:
    toaster.show_toast("FireFox Infra Changelog",
                       "Failed to update the generated files")
    LOGGER.error(e)
Exemplo n.º 3
0
def create_hg_md_table(repository_name):
    """
    Uses 'repository_name' parameter to generate markdown tables for every
    json file inside path_to_files parameter.
    :param repository_name: Used to display the repo name in the title row of
    the MD table
    :return: MD tables for every json file inside the git_files dir.
    """

    try:
        json_data = open(WORKING_DIR + "/hg_files/" + "{}.json"
                         .format(repository_name)).read()
        data = json.loads(json_data)
        base_table = "| Changeset | Date | Commiter | " \
                     "Commit Message | Commit URL | \n" + \
                     "|:---:|:---:|:----:|:---------------" \
                     "-------------------:|:-----:| \n"
        tables = {}
        try:
            last_push_id = data.get('0').get("last_push_id")
            md_title = [
                "Repository name: {}\n Current push id: {}"
                .format(repository_name, last_push_id)]
        except AttributeError:
            md_title = ["Error while accessing the " +
                        str(repository_name) + "file."]

        for repo in md_title:
            tables[repo] = base_table

        for key in data:
            if key > "0":
                key = str(len(data) - int(key))
                changeset_id = data.get(key).get("changeset_number")
                date_of_push = data.get(key).get("date_of_push")
                try:
                    for entry in data.get(key).get("changeset_commits"):
                        try:
                            commit_author = data \
                                .get(key) \
                                .get("changeset_commits") \
                                .get(entry) \
                                .get("commiter_name")
                            commit_author = re.sub("\u0131", "i",
                                                   commit_author)
                            commit_author = filter_strings(commit_author)

                            message = data \
                                .get(key) \
                                .get("changeset_commits") \
                                .get(entry).get("commit_message")
                            message = re.sub("\n|", "", message)

                            message = filter_strings(message)
                            message = replace_bug_with_url(message, LOGGER)
                            url = data\
                                .get(key)\
                                .get("changeset_commits")\
                                .get(entry)\
                                .get("url")

                            row = "|" + changeset_id + \
                                  "|" + date_of_push + \
                                  "|" + commit_author + \
                                  "|" + message + \
                                  "|" + url + "\n"

                            for repo in tables.keys():
                                tables[repo] = tables[repo] + row
                        except TypeError:
                            pass
                except TypeError:
                    pass

        md_file_name = "{}.md".format(repository_name)
        md_file = open(WORKING_DIR + "/hg_files/" + md_file_name, "w")

        try:
            for key, value in tables.items():
                if value != base_table:
                    md_file.write("## " + key.upper() + "\n\n")
                    md_file.write(value + "\n\n")
        except KeyError:
            pass

        md_file.close()
    except FileNotFoundError:
        LOGGER.error("Json for %s is empty! Skipping!", repository_name)