Source code for airflow.providers.github.hooks.github
## Licensed to the Apache Software Foundation (ASF) under one# or more contributor license agreements. See the NOTICE file# distributed with this work for additional information# regarding copyright ownership. The ASF licenses this file# to you 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## http://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."""This module allows to connect to a Github."""fromtypingimportDict,OptionalfromgithubimportGithubasGithubClientfromairflow.hooks.baseimportBaseHook
[docs]classGithubHook(BaseHook):""" Interact with Github. Performs a connection to GitHub and retrieves client. :param github_conn_id: Reference to :ref:`GitHub connection id <howto/connection:github>`. """
[docs]defget_conn(self)->GithubClient:""" Function that initiates a new GitHub connection with token and hostname ( for GitHub Enterprise ) """ifself.clientisnotNone:returnself.clientconn=self.get_connection(self.github_conn_id)access_token=conn.passwordhost=conn.hostifnothost:self.client=GithubClient(login_or_token=access_token)else:self.client=GithubClient(login_or_token=access_token,base_url=host)returnself.client