11"""
2- This module defines the `GithubEvent ` class for handling GitHub event details.
2+ This module defines the `GitHubEvent ` class for handling GitHub event details.
33
44Note:
55 This module relies on the presence of specific environment variables
1212
1313
1414# pylint: disable=R0902; Too many instance attributes
15- class GithubEvent :
15+ class GitHubEvent :
1616 """Class representing GitHub events.
1717
1818 This class provides methods for loading and accessing various details of
@@ -24,6 +24,7 @@ class GithubEvent:
2424 ref (str): The Git reference (branch or tag) for the event.
2525 workflow (str): The name of the GitHub workflow.
2626 action (str): The action that triggered the event.
27+ repository (str): The GitHub repository name.
2728 actor (str): The GitHub username of the user or app that triggered the event.
2829 job (str): The name of the job associated with the event.
2930 run_attempt (str): The current attempt number for the job run.
@@ -34,20 +35,19 @@ class GithubEvent:
3435 payload (dict): The GitHub event payload.
3536
3637 Raises:
37- EnvironmentError: If the required environment variable 'GITHUB_EVENT_PATH'
38- is not found.
38+ EnvironmentError: If GitHub env are not set properly.
3939
4040 Example:
4141 ```python
42- github_event = GithubEvent ()
42+ github_event = GitHubEvent ()
4343 print(github_event.event_name)
4444 print(github_event.sha)
4545 print(github_event.payload)
4646 ```
4747 """
4848
4949 def __init__ (self ) -> None :
50- """Initialize a new instance of the GithubEvent class."""
50+ """Initialize a new instance of the GitHubEvent class."""
5151 self .__load_details ()
5252
5353 def __load_details (self ) -> None :
@@ -58,30 +58,31 @@ def __load_details(self) -> None:
5858 environment variables set by GitHub Actions and loading the event payload
5959 from a file.
6060 """
61- self .event_name = os .environ .get ("GITHUB_EVENT_NAME" )
62- self .sha = os .environ .get ("GITHUB_SHA" )
63- self .ref = os .environ .get ("GITHUB_REF" )
64- self .workflow = os .environ .get ("GITHUB_WORKFLOW" )
65- self .action = os .environ .get ("GITHUB_ACTION" )
66- self .actor = os .environ .get ("GITHUB_ACTOR" )
67- self .job = os .environ .get ("GITHUB_JOB" )
68- self .run_attempt = os .environ .get ("GITHUB_RUN_ATTEMPT" )
69- self .run_number = os .environ .get ("GITHUB_RUN_NUMBER" )
70- self .run_id = os .environ .get ("GITHUB_RUN_ID" )
71-
72- if "GITHUB_EVENT_PATH" not in os .environ :
73- raise EnvironmentError ("GITHUB_EVENT_PATH not found on the environment." )
74-
75- self .event_path = os .environ ["GITHUB_EVENT_PATH" ]
76- with open (self .event_path , encoding = "utf-8" ) as file :
77- self .payload = json .load (file )
61+ try :
62+ self .event_name = os .environ ["GITHUB_EVENT_NAME" ]
63+ self .sha = os .environ ["GITHUB_SHA" ]
64+ self .ref = os .environ ["GITHUB_REF" ]
65+ self .workflow = os .environ ["GITHUB_WORKFLOW" ]
66+ self .action = os .environ ["GITHUB_ACTION" ]
67+ self .actor = os .environ ["GITHUB_ACTOR" ]
68+ self .repository = os .environ ["GITHUB_REPOSITORY" ]
69+ self .job = os .environ ["GITHUB_JOB" ]
70+ self .run_attempt = os .environ ["GITHUB_RUN_ATTEMPT" ]
71+ self .run_number = os .environ ["GITHUB_RUN_NUMBER" ]
72+ self .run_id = os .environ ["GITHUB_RUN_ID" ]
73+
74+ self .event_path = os .environ ["GITHUB_EVENT_PATH" ]
75+ with open (self .event_path , encoding = "utf-8" ) as file :
76+ self .payload : Dict [str , Any ] = json .load (file )
77+ except KeyError as ex :
78+ raise EnvironmentError ("GitHub env not found." ) from ex
7879
7980 def to_dict (self ) -> Dict [str , Any ]:
8081 """
81- Convert the GithubEvent instance to a dictionary.
82+ Convert the GitHubEvent instance to a dictionary.
8283
8384 Returns:
84- dict: A dictionary containing the attributes of the GithubEvent instance.
85+ dict: A dictionary containing the attributes of the GitHubEvent instance.
8586 """
8687 return {
8788 attr : getattr (self , attr )
0 commit comments