chore: Add conventional commits to PR body of discovery document update (#1314)
diff --git a/scripts/changesummary.py b/scripts/changesummary.py
index badb7b8..b95ea6f 100644
--- a/scripts/changesummary.py
+++ b/scripts/changesummary.py
@@ -20,10 +20,18 @@
import numpy as np
BRANCH_ARTIFACTS_DIR = (
- pathlib.Path(__file__).parent.resolve() / "googleapiclient" / "discovery_cache" / "documents"
+ pathlib.Path(__file__).parent.resolve()
+ / "googleapiclient"
+ / "discovery_cache"
+ / "documents"
)
MAIN_ARTIFACTS_DIR = (
- pathlib.Path(__file__).parent.resolve() / ".." / "main" / "googleapiclient" / "discovery_cache" / "documents"
+ pathlib.Path(__file__).parent.resolve()
+ / ".."
+ / "main"
+ / "googleapiclient"
+ / "discovery_cache"
+ / "documents"
)
MULTIPROCESSING_NUM_PER_BATCH = 5
@@ -124,11 +132,10 @@
combined_docs = (
pd.concat([current_doc, new_doc], keys=["CurrentValue", "NewValue"])
# Drop the index column
- .reset_index(drop=True,level=1)
+ .reset_index(drop=True, level=1)
# Transpose the DataFrame, Resulting Columns should be
# ["Key", "CurrentValue", "New Value"]
- .rename_axis(['Key'], axis=1)
- .transpose()
+ .rename_axis(["Key"], axis=1).transpose()
# Drop the index column
.reset_index()
)
@@ -199,7 +206,8 @@
# children keys have been added.
all_added = (
parent_added_agg[
- (parent_added_agg["Proportion"] == 1) & (parent_added_agg["Added"] == True)
+ (parent_added_agg["Proportion"] == 1)
+ & (parent_added_agg["Added"] == True)
][["Parent", "NumLevels"]]
.sort_values("NumLevels", ascending=True)
.Parent.to_list()
@@ -277,20 +285,24 @@
# called 'Count' which indicates the number of keys that have been
# grouped together. The reason for the count column is that when keys
# have the same parent, we group them together to improve readability.
- docs_diff = (
+ docs_diff_with_count = (
docs_diff.groupby(
["Parent", "Added", "Deleted", "Name", "Version", "ChangeType"]
)
.size()
- .reset_index(name="Count")[
- ["Parent", "Added", "Deleted", "Name", "Version", "ChangeType", "Count"]
- ]
+ .reset_index(name="Count")
)
- # Rename the Parent column to the Key Column since we are reporting
- # summary information of keys with the same parent.
- docs_diff.rename(columns={"Parent": "Key"}, inplace=True)
- return docs_diff
+ # Add counts column
+ docs_diff = docs_diff.merge(docs_diff_with_count)
+
+ # When the count is greater than 1, update the key with the name of the
+ # parent since we are consolidating keys with the same parent.
+ docs_diff.loc[docs_diff["Count"] > 1, "Key"] = docs_diff["Parent"]
+
+ return docs_diff[
+ ["Key", "Added", "Deleted", "Name", "Version", "ChangeType", "Count"]
+ ].drop_duplicates()
def _build_summary_message(self, api_name, is_feature):
"""Returns a string containing the summary for a given api. The string
@@ -327,7 +339,7 @@
return keys_to_ignore
def _get_stable_versions(self, versions):
- """ Returns a pandas series `pd.Series()` of boolean values,
+ """Returns a pandas series `pd.Series()` of boolean values,
corresponding to the given series, indicating whether the version is
considered stable or not.
args:
@@ -343,7 +355,7 @@
def _get_summary_and_write_to_disk(self, dataframe, directory):
"""Writes summary information to file about changes made to discovery
artifacts based on the provided dataframe and returns a dataframe
- with the same. The file `'allapis.summary'` is saved to the current
+ with the same. The file `'allapis.dataframe'` is saved to the current
working directory.
args:
dataframe (object): a pandas dataframe containing summary change
@@ -374,8 +386,7 @@
# Create a new column `Summary`, which will contain a string with the
# conventional commit message.
dataframe["Summary"] = np.vectorize(self._build_summary_message)(
- dataframe["Name"],
- dataframe["IsFeatureAggregate"]
+ dataframe["Name"], dataframe["IsFeatureAggregate"]
)
# Write the final dataframe to disk as it will be used in the
@@ -384,7 +395,7 @@
return dataframe
def _write_verbose_changes_to_disk(self, dataframe, directory, summary_df):
- """ Writes verbose information to file about changes made to discovery
+ """Writes verbose information to file about changes made to discovery
artifacts based on the provided dataframe. A separate file is saved
for each api in the current working directory. The extension of the
files will be `'.verbose'`.
@@ -400,8 +411,9 @@
verbose_changes = []
# Sort the dataframe to minimize file operations below.
- dataframe.sort_values(by=["Name","Version","ChangeType"],
- ascending=True, inplace=True)
+ dataframe.sort_values(
+ by=["Name", "Version", "ChangeType"], ascending=True, inplace=True
+ )
# Select only the relevant columns. We need to create verbose output
# by Api Name, Version and ChangeType so we need to group by these
@@ -433,7 +445,7 @@
# Clear the array of strings with information from the previous
# api and reset the last version
verbose_changes = []
- lastVersion = ''
+ lastVersion = ""
# Create a file which contains verbose changes for the current
# API being processed
filename = "{0}.verbose".format(currentApi)
@@ -450,12 +462,13 @@
# summary column are the same for a given API.
verbose_changes.append(summary_df[current_api_filter].Summary.iloc[0])
-
# If the version has changed, we need to create append a new heading
# in the verbose summary which contains the api and version.
if lastVersion != currentVersion:
# Append a header string with the API and version
- verbose_changes.append("\n\n#### {0}:{1}\n\n".format(currentApi, currentVersion))
+ verbose_changes.append(
+ "\n\n#### {0}:{1}\n\n".format(currentApi, currentVersion)
+ )
lastVersion = currentVersion
lastType = ChangeType.UNKNOWN
@@ -476,7 +489,7 @@
# type group.
verbose_changes.extend(
[
- "- {0} (Total Keys: {1})\n".format(row['Key'], row['Count'])
+ "- {0} (Total Keys: {1})\n".format(row["Key"], row["Count"])
for index, row in group[["Key", "Count"]].iterrows()
]
)
@@ -521,4 +534,3 @@
# Create verbose change information for each API which contains
# a list of changes by key and write it to disk.
self._write_verbose_changes_to_disk(result, self._temp_dir, summary_df)
-