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 you to connect to GitHub."""from__future__importannotationsfromtypingimportTYPE_CHECKINGfromgithubimportGithubasGithubClientfromairflow.exceptionsimportAirflowExceptionfromairflow.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.host# Currently the only method of authenticating to GitHub in Airflow is via a token. This is not the# only means available, but raising an exception to enforce this method for now.# TODO: When/If other auth methods are implemented this exception should be removed/modified.ifnotaccess_token:raiseAirflowException("An access token is required to authenticate to GitHub.")ifnothost:self.client=GithubClient(login_or_token=access_token)else:self.client=GithubClient(login_or_token=access_token,base_url=host)returnself.client