-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add entry point #2616
Merged
Merged
feat: add entry point #2616
Changes from 32 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
95b66a8
feat: add entry_point.py
JoeWang1127 964d81a
remove cli in generate_repo.py
JoeWang1127 5b303cb
remove cli in generate_pr_description.py
JoeWang1127 4f6cedd
add comment
JoeWang1127 531244d
fix integration test
JoeWang1127 a6811d5
rename config
JoeWang1127 14cdfb9
change pr description file path
JoeWang1127 24f2070
add comments
JoeWang1127 853b70c
restore CLI
JoeWang1127 923f149
format code
JoeWang1127 1cd3859
change input to current_generation_config
JoeWang1127 ffc16ee
change to optional inputs
JoeWang1127 87c7d1c
raise exception if current commit is older than baseline commit
JoeWang1127 9d723b0
add unit test
JoeWang1127 fd7897a
add error log
JoeWang1127 ca902ec
convert time to int
JoeWang1127 4895971
add comment
JoeWang1127 87c0bdd
extract helper method
JoeWang1127 69fd09b
refactor tests
JoeWang1127 d2b3963
add integration test
JoeWang1127 b4b907b
change if
JoeWang1127 ce25efa
refactor
JoeWang1127 8d1d3f6
restore integration test
JoeWang1127 e155ea0
add unit tests
JoeWang1127 8de0c3d
add unit tests
JoeWang1127 e518d3f
test setup
JoeWang1127 22eb127
restore unit tests
JoeWang1127 c25e2bd
refactor
JoeWang1127 cc137b0
change error message
JoeWang1127 5dbcd2c
fail if current config is null but baseline is not
JoeWang1127 3d3522b
two commits should be different
JoeWang1127 280cee5
change doc
JoeWang1127 881b557
change comment
JoeWang1127 4de89de
change readme
JoeWang1127 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import os | ||
|
||
import click as click | ||
from library_generation.generate_pr_description import generate_pr_descriptions | ||
from library_generation.generate_repo import generate_from_yaml | ||
from library_generation.model.generation_config import from_yaml | ||
from library_generation.utils.generation_config_comparator import compare_config | ||
|
||
|
||
@click.group(invoke_without_command=False) | ||
@click.pass_context | ||
@click.version_option(message="%(version)s") | ||
def main(ctx): | ||
pass | ||
|
||
|
||
@main.command() | ||
@click.option( | ||
"--baseline-generation-config", | ||
required=False, | ||
default=None, | ||
type=str, | ||
help=""" | ||
Absolute or relative path to generation_config.yaml that contains the | ||
metadata about library generation. | ||
The googleapis commit in the configuration is the oldest commit, | ||
exclusively, from which the commit message is considered. | ||
""", | ||
) | ||
@click.option( | ||
"--current-generation-config", | ||
required=False, | ||
default=None, | ||
type=str, | ||
help=""" | ||
Absolute or relative path to generation_config.yaml that contains the | ||
metadata about library generation. | ||
The googleapis commit in the configuration is the newest commit, | ||
inclusively, to which the commit message is considered. | ||
""", | ||
) | ||
@click.option( | ||
"--repository-path", | ||
type=str, | ||
default=".", | ||
show_default=True, | ||
help=""" | ||
The repository path to which the generated files | ||
will be sent. | ||
If not specified, the repository will be generated to the current working | ||
directory. | ||
""", | ||
) | ||
def generate( | ||
baseline_generation_config: str, | ||
current_generation_config: str, | ||
repository_path: str, | ||
): | ||
""" | ||
Compare baseline generation config and current generation config and | ||
generate changed libraries based on current generation config with pull | ||
request description. | ||
|
||
If baseline generation config is not specified but current generation | ||
config is specified, generate all libraries based on current generation | ||
config without pull request description. | ||
|
||
If current generation config is not specified but baseline generation | ||
config is specified, raise FileNotFoundError because current generation | ||
config should be the source of truth of library generation. | ||
|
||
If both baseline generation config and current generation config are not | ||
specified, generate all libraries based on the default generation config, | ||
which is generation_config.yaml in the current working directory. Raise | ||
FileNotFoundError if the default config does not exist. | ||
|
||
The pull request description, if generated, will be available in | ||
repository_path/pr_description.txt. | ||
""" | ||
default_generation_config = f"{os.getcwd()}/generation_config.yaml" | ||
|
||
if baseline_generation_config is None and current_generation_config is None: | ||
if not os.path.isfile(default_generation_config): | ||
raise FileNotFoundError( | ||
f"{default_generation_config} does not exist. " | ||
"A valid generation config has to be passed in as " | ||
"current_generation_config or exist in the current working " | ||
"directory." | ||
) | ||
current_generation_config = default_generation_config | ||
elif current_generation_config is None: | ||
blakeli0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
raise FileNotFoundError( | ||
"current_generation_config is not specified when " | ||
"baseline_generation_config is specified. " | ||
"current_generation_config should be the source of truth of " | ||
"library generation." | ||
) | ||
|
||
current_generation_config = os.path.abspath(current_generation_config) | ||
repository_path = os.path.abspath(repository_path) | ||
if not baseline_generation_config: | ||
blakeli0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Execute full generation based on current_generation_config if | ||
# baseline_generation_config is not specified. | ||
# Do not generate pull request description. | ||
generate_from_yaml( | ||
config=from_yaml(current_generation_config), | ||
repository_path=repository_path, | ||
) | ||
return | ||
|
||
# Compare two generation configs and only generate changed libraries. | ||
# Generate pull request description. | ||
baseline_generation_config = os.path.abspath(baseline_generation_config) | ||
config_change = compare_config( | ||
baseline_config=from_yaml(baseline_generation_config), | ||
current_config=from_yaml(current_generation_config), | ||
) | ||
generate_from_yaml( | ||
config=config_change.current_config, | ||
repository_path=repository_path, | ||
target_library_names=config_change.get_changed_libraries(), | ||
) | ||
generate_pr_descriptions( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We probably want to rename |
||
config=config_change.current_config, | ||
baseline_commit=config_change.baseline_config.googleapis_commitish, | ||
description_path=repository_path, | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we include some high level description for
baseline-generation-config
? For example, something like "We compare baseline-generation-config with the current generation config, and generate commit messages based on the diff of the googleapis-commitish between the two generation configs."Same comment for
current-generation-config
below.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added high level description of
generate
method in doc string.User can read the docs through
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looks good! I think we still need more info to distinguish between
baseline-generation-config
fromcurrent-generation-config
. For example, both descriptions includeAbsolute or relative path to generation_config.yaml that contains the metadata about library generation.
, in fact, only the info incurrent-generation-config
is used for generation,baseline-generation-config
is only used for generating commit history. Also the additional info regarding inclusive/exclusive of googleapis commitish might be a little too detailed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed the comment.