-
Notifications
You must be signed in to change notification settings - Fork 86
refactor(get_env_vars): use get_env_vars() for consistent env variable retrieval #171
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
Merged
Merged
Changes from all commits
Commits
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 hidden or 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,93 @@ | ||
| """A module for managing environment variables used in GitHub metrics calculation. | ||
|
|
||
| This module defines a class for encapsulating environment variables and a function to retrieve these variables. | ||
|
|
||
| Classes: | ||
| EnvVars: Represents the collection of environment variables used in the script. | ||
|
|
||
| Functions: | ||
| get_env_vars: Retrieves and returns an instance of EnvVars populated with environment variables. | ||
| """ | ||
| import os | ||
| from typing import List | ||
|
|
||
|
|
||
| class EnvVars: | ||
| # pylint: disable=too-many-instance-attributes | ||
| """ | ||
| Environment variables | ||
|
|
||
| Attributes: | ||
| search_query (str): Search query used to filter issues/prs/discussions on GitHub | ||
| gh_token (str): GitHub personal access token (PAT) for API authentication | ||
| labels_to_measure (List[str]): List of labels to measure how much time the lable is applied | ||
| ignore_users (List[str]): List of usernames to ignore when calculating metrics | ||
| github_server_url (str): URL of GitHub server (Github.com or Github Enterprise) | ||
| hide_author (str): If set, the author's information is hidden in the output | ||
| hide_time_to_first_response (str): If set, the time to first response metric is hidden in the output | ||
| hide_time_to_close (str): If set, the time to close metric is hidden in the output | ||
| hide_time_to_answer (str): If set, the time to answer discussions is hidden in the output | ||
| hide_label_metrics (str): If set, the label metrics are hidden in the output | ||
| """ | ||
| def __init__(self, search_query: str, gh_token: str, labels_to_measure: List[str], ignore_user: List[str], | ||
| github_server_url: str, hide_author: str, hide_time_to_first_response: str, | ||
| hide_time_to_close: str, hide_time_to_answer: str, hide_label_metrics: str): | ||
| self.search_query = search_query | ||
| self.gh_token = gh_token | ||
| self.labels_to_measure = labels_to_measure | ||
| self.ignore_users = ignore_user | ||
| self.github_server_url = github_server_url | ||
| self.hide_author = hide_author | ||
| self.hide_time_to_first_response = hide_time_to_first_response | ||
| self.hide_time_to_close = hide_time_to_close | ||
| self.hide_time_to_answer = hide_time_to_answer | ||
| self.hide_label_metrics = hide_label_metrics | ||
|
|
||
|
|
||
| def get_env_vars() -> EnvVars: | ||
| """ | ||
| Get the environment variables for use in the script. | ||
|
|
||
| Returns EnvVars object with all environment variables | ||
| """ | ||
| search_query = os.getenv("SEARCH_QUERY") | ||
| if not search_query: | ||
| raise ValueError("SEARCH_QUERY environment variable not set") | ||
|
|
||
| gh_token = os.getenv("GH_TOKEN") | ||
| if not gh_token: | ||
| raise ValueError("GITHUB_TOKEN environment variable not set") | ||
|
|
||
| labels_to_measure = os.getenv("LABELS_TO_MEASURE") | ||
| if labels_to_measure: | ||
| labels_to_measure = labels_to_measure.split(",") | ||
| else: | ||
| labels_to_measure = [] | ||
|
|
||
| ignore_users = os.getenv("IGNORE_USERS") | ||
| if ignore_users: | ||
| ignore_users = ignore_users.split(",") | ||
| else: | ||
| ignore_users = [] | ||
|
|
||
| github_server_url = os.getenv("GITHUB_SERVER_URL") | ||
|
|
||
| # Hidden columns | ||
| hide_author = os.getenv("HIDE_AUTHOR") | ||
| hide_time_to_first_response = os.getenv("HIDE_TIME_TO_FIRST_RESPONSE") | ||
| hide_time_to_close = os.getenv("HIDE_TIME_TO_CLOSE") | ||
| hide_time_to_answer = os.getenv("HIDE_TIME_TO_ANSWER") | ||
| hide_label_metrics = os.getenv("HIDE_LABEL_METRICS") | ||
|
|
||
| return EnvVars( | ||
| search_query, | ||
| gh_token, | ||
| labels_to_measure, | ||
| ignore_users, | ||
| github_server_url, | ||
| hide_author, | ||
| hide_time_to_first_response, | ||
| hide_time_to_close, | ||
| hide_time_to_answer, | ||
| hide_label_metrics | ||
| ) | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.