def _populate_changelog_md(self, element, changelog_data): """ Populates a list with all the data to be writen to changelog.md """ json_link, md_link = self._get_js_md_links(element[0]) if element[2] is "git": self.changelog_md_data.append(self._changelog_md_links(element[0], json_link, md_link)) self.changelog_md_data.append(self._changelog_md_first_row()) if len(changelog_data["Github"][element[0]]) > 0: for value in changelog_data["Github"][element[0]].values(): self.commit_url = value["url"] self.commit_message = value["message"] self.commit_author = value["author"] self.commit_reviewer = "N/A" self.commit_date = return_time(input_time=value["date"], input_time_format="%Y-%m-%dT%H:%M:%SZ", output_time_format="%Y-%m-%d %H:%M:%S") self.commit_author, self.commit_message = self.filter_strings() self.changelog_md_data.append(self._changelog_md_row_builder()) else: self.changelog_md_data.append(self.no_data_for_md(md_link, main_markdown=True)) if element[2] is "hg": self.changelog_md_data.append(self._changelog_md_links(element[0], json_link, md_link)) self.changelog_md_data.append(self._changelog_md_first_row()) if len(changelog_data["Mercurial"][element[0]]) > 0: for value in changelog_data["Mercurial"][element[0]].values(): self.commit_date = return_time(input_time=value["date_of_push"], input_time_format="%Y-%m-%dT%H:%M:%S.%f", output_time_format="%Y-%m-%d %H:%M:%S") for commit in value["changeset_commits"].values(): self.commit_url = commit["url"] self.commit_message = commit["commit_message"] self.commit_author = commit["commit_author"].split("<")[0] self.commit_reviewer = self.extract_reviewer() self.commit_author, self.commit_message = self.filter_strings() self.changelog_md_data.append(self._changelog_md_row_builder()) else: self.changelog_md_data.append(self.no_data_for_md(md_link, main_markdown=True))
def _get_local_data(self): """ Picks up data if a .json file is already in place """ if len(self.local_repo_data): self.local_repo_data.pop("0") for key, value in self.local_repo_data.items(): if return_time(input_time=value["date_of_push"], input_time_format="%Y-%m-%dT%H:%M:%S.%f") > \ return_time(output_time_format="%Y-%m-%dT%H:%M:%S.%f", operation="sub", operation_days=INDIVIDUAL_REPO_DAYS): self.push_number += 1 self.final_dict.update({self.push_number: value})
def _check_commit_age(self, filter_list=None): """ Removes data that is older tham a set amount of days. Default = 30 :param filter_list: awaits a list of commit data """ for commit in range(1, len(filter_list)): if return_time(input_time=filter_list[str(commit)]["date"], input_time_format="%Y-%m-%dT%H:%M:%SZ") > \ return_time(operation="sub", operation_days=INDIVIDUAL_REPO_DAYS): self.commit_number += 1 self.list_of_commits.update( {str(self.commit_number): filter_list[str(commit)]})
def commit(self): """ Commits the added changes """ self.LOGGER.info( f"Committing changes with message: Changelog: {return_time()}") return self.repo.index.commit("Changelog: " + return_time( output_time_format="%Y-%m-%dT%H:%M:%S"))
def _generate_first_element(self): """ Creates the first element which will be at the top of the json file :return: """ if self.repo_type == "tag" and self.repo_name != "build-puppet": return { "0": { "last_checked": return_time(output_time_format="%Y-%m-%dT%H:%M:%S.%f"), "version": self._get_release(1) } } else: return { "0": { "last_checked": return_time(output_time_format="%Y-%m-%dT%H:%M:%S.%f") } }
def _extract_hg_commits(self, key, changelog, number_of_days): """ The method to extract the commits from Mercurial repositories for <int> amount of days. :param key: repository name :param changelog: the dictionary of commits for changelog.json :param number_of_days: the amount of days to extract the commits """ repo_data = json.load( self.load(CHANGELOG_REPO_PATH, key.lower() + ".json")) if len(repo_data) > 0: repo_data.pop("0") changelog["Mercurial"].update({key: {}}) commit_number = 0 for value in repo_data.values(): time_span = return_time( output_time_format="%Y-%m-%dT%H:%M:%S.%f", operation="sub", operation_days=number_of_days) if return_time( input_time=value["date_of_push"], input_time_format="%Y-%m-%dT%H:%M:%S.%f") > time_span: changelog["Mercurial"][key].update({commit_number: value}) commit_number += 1
def _last_checked(self): """ :return: the last checked value in the json files. If there isn't one use DEFAULT_DAYS """ if json.load( self.load(CHANGELOG_REPO_PATH, self.repo_name.lower() + ".json")).get("0"): self.last_check = json.load( self.load(CHANGELOG_REPO_PATH, self.repo_name.lower() + ".json")).get("0").get("last_checked") else: self.last_check = return_time( output_time_format="%Y-%m-%dT%H:%M:%S.%f", operation="sub", operation_days=DEFAULT_DAYS)
def _populate_md_for_git(self): """ Populates a list with all the data to be writen to an MD file. Works for git repos """ local_json_data = self._load_local_json_data() if len(local_json_data) > 1: del local_json_data["0"] self.commit_number = 1 for key in local_json_data: self.commit_date = return_time(input_time=local_json_data.get(key).get("date"), input_time_format="%Y-%m-%dT%H:%M:%SZ", output_time_format="%Y-%m-%d %H:%M:%S") self.commit_author = local_json_data.get(key).get("author") self.commit_url = local_json_data.get(key).get("url") self.commit_message = local_json_data.get(key).get("message") self.commit_author, self.commit_message = self.filter_strings() self.trim_commit_description(self.commit_url, COMMIT_DESCRIPTION_LENGTH) self.generate_link_for_bugs() self.md_ready_data.append(self.md_table_row_builder()) self.commit_number += 1 else: self.md_ready_data.append(self.no_data_for_md("Github", repo_markdown=True))
def _populate_md_for_hg(self): """ Populates a list with all the data to be writen to an MD file. Works for hg repos """ local_json_data = self._load_local_json_data() if len(local_json_data) > 1: del local_json_data["0"] self.commit_number = 1 for changeset in local_json_data: for commit in local_json_data.get(changeset).get("changeset_commits"): self.commit_date = return_time(input_time=local_json_data.get(changeset).get("date_of_push"), input_time_format="%Y-%m-%dT%H:%M:%S.%f", output_time_format="%Y-%m-%d %H:%M:%S") self.commit_author = local_json_data.get(changeset).get("changeset_commits").get(commit).get("commit_author").split("<")[0] self.commit_url = local_json_data.get(changeset).get("changeset_commits").get(commit).get("url") self.commit_message = local_json_data.get(changeset).get("changeset_commits").get(commit).get("commit_message") self.commit_author, self.commit_message = self.filter_strings() self.trim_commit_description(self.commit_url, COMMIT_DESCRIPTION_LENGTH) self.generate_link_for_bugs() self.md_ready_data.append(self.md_table_row_builder()) self.commit_number += 1 else: self.md_ready_data.append(self.no_data_for_md("Mercurial", repo_markdown=True))
def _generate_changeset_date(self, date): self.changeset_date = return_time( input_time=date, input_time_unix=True, output_time_format="%Y-%m-%dT%H:%M:%S.%f") return self.changeset_date
def _get_current_time(): return return_time(output_time_format="%Y-%m-%d %H:%M:%S UTC")
def _get_reset_time(self): reset_time = return_time( input_time=self._gh.rate_limit()['rate']['reset'], input_time_unix=True) self.LOGGER.info(f"Rate limit reset in: {reset_time - return_time()}") return reset_time