blob: 10733b4750a96cfe936f88bd62d81b64feb85cdb [file] [log] [blame]
Anthonios Partheniouaff037a2021-04-21 11:00:09 -04001# Copyright 2021 Google LLC
2
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6
7# https://www.apache.org/licenses/LICENSE-2.0
8
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15from enum import IntEnum
16import numpy as np
17import pandas as pd
18import pathlib
19
20class ChangeType(IntEnum):
21 UNKNOWN = 0
22 DELETED = 1
23 ADDED = 2
24 CHANGED = 3
25
26
27def get_commit_link(name):
28 """Return a string with a link to the last commit for the given
29 API Name.
30 args:
31 name (str): The name of the api.
32 """
33
34 url = "https://github.com/googleapis/google-api-python-client/commit/"
35 sha = None
36 api_link = ""
37
38 file_path = pathlib.Path(directory).joinpath("{0}.sha".format(name))
39 if file_path.is_file():
40 with open(file_path, "r") as f:
41 sha = f.readline().rstrip()
42 if sha:
43 api_link = "[{0}]({1}{2})".format(" [More details]", url, sha)
44
45 return api_link
46
47
48if __name__ == "__main__":
49 directory = pathlib.Path("temp")
50 dataframe = pd.read_csv("temp/allapis.dataframe")
51 dataframe["Version"] = dataframe["Version"].astype(str)
52
53 dataframe["Commit"] = np.vectorize(get_commit_link)(dataframe["Name"])
54
55 stable_and_breaking = (
56 dataframe[
57 dataframe["IsStable"]
58 & (dataframe["ChangeType"] == ChangeType.DELETED)
59 ][["Name", "Version", "Commit"]]
60 .drop_duplicates()
61 .agg("".join, axis=1)
62 .values
63 )
64
65 prestable_and_breaking = (
66 dataframe[
67 (dataframe["IsStable"] == False)
68 & (dataframe["ChangeType"] == ChangeType.DELETED)
69 ][["Name", "Version", "Commit"]]
70 .drop_duplicates()
71 .agg("".join, axis=1)
72 .values
73 )
74
75 all_apis = (
76 dataframe[["Name", "Version", "Commit"]]
77 .drop_duplicates()
78 .agg("".join, axis=1)
79 .values
80 )
81
82 with open(directory / "allapis.summary", "w") as f:
83 if len(stable_and_breaking) > 0:
84 f.writelines(
85 [
86 "## Deleted keys were detected in the following stable discovery artifacts:\n",
87 "\n".join(stable_and_breaking),
88 "\n\n",
89 ]
90 )
91
92 if len(prestable_and_breaking) > 0:
93 f.writelines(
94 [
95 "## Deleted keys were detected in the following pre-stable discovery artifacts:\n",
96 "\n".join(prestable_and_breaking),
97 "\n\n",
98 ]
99 )
100
101 if len(all_apis) > 0:
102 f.writelines(
103 ["## Discovery Artifact Change Summary:\n", "\n".join(all_apis), "\n"]
104 )