apache-airflow-providers-git 0.4.3__tar.gz → 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. {apache_airflow_providers_git-0.4.3 → apache_airflow_providers_git-0.5.0}/PKG-INFO +17 -6
  2. {apache_airflow_providers_git-0.4.3 → apache_airflow_providers_git-0.5.0}/README.rst +12 -3
  3. {apache_airflow_providers_git-0.4.3 → apache_airflow_providers_git-0.5.0}/docs/changelog.rst +13 -0
  4. {apache_airflow_providers_git-0.4.3 → apache_airflow_providers_git-0.5.0}/docs/connections/git.rst +36 -0
  5. {apache_airflow_providers_git-0.4.3 → apache_airflow_providers_git-0.5.0}/docs/index.rst +20 -3
  6. {apache_airflow_providers_git-0.4.3 → apache_airflow_providers_git-0.5.0}/provider.yaml +6 -2
  7. {apache_airflow_providers_git-0.4.3 → apache_airflow_providers_git-0.5.0}/pyproject.toml +11 -3
  8. {apache_airflow_providers_git-0.4.3 → apache_airflow_providers_git-0.5.0}/src/airflow/providers/git/__init__.py +1 -1
  9. {apache_airflow_providers_git-0.4.3 → apache_airflow_providers_git-0.5.0}/src/airflow/providers/git/get_provider_info.py +1 -1
  10. {apache_airflow_providers_git-0.4.3 → apache_airflow_providers_git-0.5.0}/src/airflow/providers/git/hooks/git.py +118 -2
  11. {apache_airflow_providers_git-0.4.3 → apache_airflow_providers_git-0.5.0}/tests/unit/git/hooks/test_git.py +288 -0
  12. {apache_airflow_providers_git-0.4.3 → apache_airflow_providers_git-0.5.0}/.gitignore +0 -0
  13. {apache_airflow_providers_git-0.4.3 → apache_airflow_providers_git-0.5.0}/LICENSE +0 -0
  14. {apache_airflow_providers_git-0.4.3 → apache_airflow_providers_git-0.5.0}/NOTICE +0 -0
  15. {apache_airflow_providers_git-0.4.3 → apache_airflow_providers_git-0.5.0}/docs/.latest-doc-only-change.txt +0 -0
  16. {apache_airflow_providers_git-0.4.3 → apache_airflow_providers_git-0.5.0}/docs/bundles/index.rst +0 -0
  17. {apache_airflow_providers_git-0.4.3 → apache_airflow_providers_git-0.5.0}/docs/commits.rst +0 -0
  18. {apache_airflow_providers_git-0.4.3 → apache_airflow_providers_git-0.5.0}/docs/conf.py +0 -0
  19. {apache_airflow_providers_git-0.4.3 → apache_airflow_providers_git-0.5.0}/docs/installing-providers-from-sources.rst +0 -0
  20. {apache_airflow_providers_git-0.4.3 → apache_airflow_providers_git-0.5.0}/docs/integration-logos/GIT.svg +0 -0
  21. {apache_airflow_providers_git-0.4.3 → apache_airflow_providers_git-0.5.0}/docs/security.rst +0 -0
  22. {apache_airflow_providers_git-0.4.3 → apache_airflow_providers_git-0.5.0}/src/airflow/__init__.py +0 -0
  23. {apache_airflow_providers_git-0.4.3 → apache_airflow_providers_git-0.5.0}/src/airflow/providers/__init__.py +0 -0
  24. {apache_airflow_providers_git-0.4.3 → apache_airflow_providers_git-0.5.0}/src/airflow/providers/git/bundles/__init__.py +0 -0
  25. {apache_airflow_providers_git-0.4.3 → apache_airflow_providers_git-0.5.0}/src/airflow/providers/git/bundles/git.py +0 -0
  26. {apache_airflow_providers_git-0.4.3 → apache_airflow_providers_git-0.5.0}/src/airflow/providers/git/hooks/__init__.py +0 -0
  27. {apache_airflow_providers_git-0.4.3 → apache_airflow_providers_git-0.5.0}/src/airflow/providers/git/version_compat.py +0 -0
  28. {apache_airflow_providers_git-0.4.3 → apache_airflow_providers_git-0.5.0}/tests/conftest.py +0 -0
  29. {apache_airflow_providers_git-0.4.3 → apache_airflow_providers_git-0.5.0}/tests/unit/__init__.py +0 -0
  30. {apache_airflow_providers_git-0.4.3 → apache_airflow_providers_git-0.5.0}/tests/unit/git/__init__.py +0 -0
  31. {apache_airflow_providers_git-0.4.3 → apache_airflow_providers_git-0.5.0}/tests/unit/git/bundles/__init__.py +0 -0
  32. {apache_airflow_providers_git-0.4.3 → apache_airflow_providers_git-0.5.0}/tests/unit/git/bundles/test_git.py +0 -0
  33. {apache_airflow_providers_git-0.4.3 → apache_airflow_providers_git-0.5.0}/tests/unit/git/hooks/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: apache-airflow-providers-git
3
- Version: 0.4.3
3
+ Version: 0.5.0
4
4
  Summary: Provider package apache-airflow-providers-git for Apache Airflow
5
5
  Keywords: airflow-provider,git,airflow,integration
6
6
  Author-email: Apache Software Foundation <dev@airflow.apache.org>
@@ -26,13 +26,15 @@ License-File: NOTICE
26
26
  Requires-Dist: apache-airflow>=3.0.0
27
27
  Requires-Dist: apache-airflow-providers-common-compat>=1.15.0
28
28
  Requires-Dist: GitPython>=3.1.44
29
+ Requires-Dist: PyGithub>=2.1.1 ; extra == "github"
29
30
  Project-URL: Bug Tracker, https://github.com/apache/airflow/issues
30
- Project-URL: Changelog, https://airflow.apache.org/docs/apache-airflow-providers-git/0.4.3/changelog.html
31
- Project-URL: Documentation, https://airflow.apache.org/docs/apache-airflow-providers-git/0.4.3
31
+ Project-URL: Changelog, https://airflow.apache.org/docs/apache-airflow-providers-git/0.5.0/changelog.html
32
+ Project-URL: Documentation, https://airflow.apache.org/docs/apache-airflow-providers-git/0.5.0
32
33
  Project-URL: Mastodon, https://fosstodon.org/@airflow
33
34
  Project-URL: Slack Chat, https://s.apache.org/airflow-slack
34
35
  Project-URL: Source Code, https://github.com/apache/airflow
35
36
  Project-URL: YouTube, https://www.youtube.com/channel/UCSXwxpWZQ7XZ1WL3wqevChA/
37
+ Provides-Extra: github
36
38
  Import-Name: airflow.providers.git
37
39
  Import-Namespace: airflow
38
40
  Import-Namespace: airflow.providers
@@ -62,7 +64,7 @@ Import-Namespace: airflow.providers
62
64
 
63
65
  Package ``apache-airflow-providers-git``
64
66
 
65
- Release: ``0.4.3``
67
+ Release: ``0.5.0``
66
68
 
67
69
 
68
70
  `Distributed version control system (GIT) <https://git-scm.com/>`__
@@ -75,7 +77,7 @@ This is a provider package for ``git`` provider. All classes for this provider p
75
77
  are in ``airflow.providers.git`` python package.
76
78
 
77
79
  You can find package information and changelog for the provider
78
- in the `documentation <https://airflow.apache.org/docs/apache-airflow-providers-git/0.4.3/>`_.
80
+ in the `documentation <https://airflow.apache.org/docs/apache-airflow-providers-git/0.5.0/>`_.
79
81
 
80
82
  Installation
81
83
  ------------
@@ -97,6 +99,15 @@ PIP package Version required
97
99
  ``GitPython`` ``>=3.1.44``
98
100
  ========================================== ==================
99
101
 
102
+ Optional dependencies
103
+ ----------------------
104
+
105
+ ========== ===================
106
+ Extra Dependencies
107
+ ========== ===================
108
+ ``github`` ``PyGithub>=2.1.1``
109
+ ========== ===================
110
+
100
111
  The changelog for the provider package can be found in the
101
- `changelog <https://airflow.apache.org/docs/apache-airflow-providers-git/0.4.3/changelog.html>`_.
112
+ `changelog <https://airflow.apache.org/docs/apache-airflow-providers-git/0.5.0/changelog.html>`_.
102
113
 
@@ -23,7 +23,7 @@
23
23
 
24
24
  Package ``apache-airflow-providers-git``
25
25
 
26
- Release: ``0.4.3``
26
+ Release: ``0.5.0``
27
27
 
28
28
 
29
29
  `Distributed version control system (GIT) <https://git-scm.com/>`__
@@ -36,7 +36,7 @@ This is a provider package for ``git`` provider. All classes for this provider p
36
36
  are in ``airflow.providers.git`` python package.
37
37
 
38
38
  You can find package information and changelog for the provider
39
- in the `documentation <https://airflow.apache.org/docs/apache-airflow-providers-git/0.4.3/>`_.
39
+ in the `documentation <https://airflow.apache.org/docs/apache-airflow-providers-git/0.5.0/>`_.
40
40
 
41
41
  Installation
42
42
  ------------
@@ -58,5 +58,14 @@ PIP package Version required
58
58
  ``GitPython`` ``>=3.1.44``
59
59
  ========================================== ==================
60
60
 
61
+ Optional dependencies
62
+ ----------------------
63
+
64
+ ========== ===================
65
+ Extra Dependencies
66
+ ========== ===================
67
+ ``github`` ``PyGithub>=2.1.1``
68
+ ========== ===================
69
+
61
70
  The changelog for the provider package can be found in the
62
- `changelog <https://airflow.apache.org/docs/apache-airflow-providers-git/0.4.3/changelog.html>`_.
71
+ `changelog <https://airflow.apache.org/docs/apache-airflow-providers-git/0.5.0/changelog.html>`_.
@@ -19,6 +19,19 @@
19
19
  Changelog
20
20
  ---------
21
21
 
22
+ 0.5.0
23
+ .....
24
+
25
+ Features
26
+ ~~~~~~~~
27
+
28
+ * ``Add GitHub App authentication for git Dag bundles (#64422)``
29
+
30
+
31
+ .. Below changes are excluded from the changelog. Move them to
32
+ appropriate section above if needed. Do not delete the lines(!):
33
+ * ``Sync connection UI metadata in provider.yaml with hook definitions (#72087)``
34
+
22
35
  0.4.3
23
36
  .....
24
37
 
@@ -116,3 +116,39 @@ Extra (optional)
116
116
  "strict_host_key_checking": "yes",
117
117
  "known_hosts_file": "/path/to/known_hosts"
118
118
  }
119
+
120
+ **GitHub App authentication:**
121
+
122
+ In order to use GitHub App authentication the ``github`` extra needs to be installed:
123
+
124
+ .. code-block:: bash
125
+
126
+ pip install 'apache-airflow-providers-git[github]'
127
+
128
+ * ``github_app_id``: The App ID of your GitHub App. Note that the GitHub App Client ID can also be used.
129
+ * ``github_installation_id``: The installation ID of your GitHub app.
130
+ * ``key_file``: Path to a PEM-encoded private key file for your GitHub App.
131
+ * ``private_key``: An inline PEM-encoded private key string. When provided, the hook writes it
132
+ to a temporary file and uses it for the GitHub App connection.
133
+ Mutually exclusive with ``key_file``.
134
+
135
+
136
+ Example with key file:
137
+
138
+ .. code-block:: json
139
+
140
+ {
141
+ "github_app_id": "1234567",
142
+ "github_installation_id": "67890",
143
+ "key_file": "/path/to/private-key.pem"
144
+ }
145
+
146
+ Example with inline private key:
147
+
148
+ .. code-block:: json
149
+
150
+ {
151
+ "github_app_id": "1234567",
152
+ "github_installation_id": "67890",
153
+ "private_key": "<content of your PEM-encoded private key>"
154
+ }
@@ -72,7 +72,7 @@ apache-airflow-providers-git package
72
72
  `Distributed version control system (GIT) <https://git-scm.com/>`__
73
73
 
74
74
 
75
- Release: 0.4.3
75
+ Release: 0.5.0
76
76
 
77
77
  Provider package
78
78
  ----------------
@@ -100,11 +100,28 @@ PIP package Version required
100
100
  ``GitPython`` ``>=3.1.44``
101
101
  ========================================== ==================
102
102
 
103
+ Optional dependencies
104
+ ---------------------
105
+
106
+ These extras install optional third-party libraries that enable additional features of the provider.
107
+ Install them when installing from PyPI. For example:
108
+
109
+ .. code-block:: bash
110
+
111
+ pip install apache-airflow-providers-git[github]
112
+
113
+
114
+ ========== ===================
115
+ Extra Dependencies
116
+ ========== ===================
117
+ ``github`` ``PyGithub>=2.1.1``
118
+ ========== ===================
119
+
103
120
  Downloading official packages
104
121
  -----------------------------
105
122
 
106
123
  You can download officially released packages and verify their checksums and signatures from the
107
124
  `Official Apache Download site <https://downloads.apache.org/airflow/providers/>`_
108
125
 
109
- * `The apache-airflow-providers-git 0.4.3 sdist package <https://downloads.apache.org/airflow/providers/apache_airflow_providers_git-0.4.3.tar.gz>`_ (`asc <https://downloads.apache.org/airflow/providers/apache_airflow_providers_git-0.4.3.tar.gz.asc>`__, `sha512 <https://downloads.apache.org/airflow/providers/apache_airflow_providers_git-0.4.3.tar.gz.sha512>`__)
110
- * `The apache-airflow-providers-git 0.4.3 wheel package <https://downloads.apache.org/airflow/providers/apache_airflow_providers_git-0.4.3-py3-none-any.whl>`_ (`asc <https://downloads.apache.org/airflow/providers/apache_airflow_providers_git-0.4.3-py3-none-any.whl.asc>`__, `sha512 <https://downloads.apache.org/airflow/providers/apache_airflow_providers_git-0.4.3-py3-none-any.whl.sha512>`__)
126
+ * `The apache-airflow-providers-git 0.5.0 sdist package <https://downloads.apache.org/airflow/providers/apache_airflow_providers_git-0.5.0.tar.gz>`_ (`asc <https://downloads.apache.org/airflow/providers/apache_airflow_providers_git-0.5.0.tar.gz.asc>`__, `sha512 <https://downloads.apache.org/airflow/providers/apache_airflow_providers_git-0.5.0.tar.gz.sha512>`__)
127
+ * `The apache-airflow-providers-git 0.5.0 wheel package <https://downloads.apache.org/airflow/providers/apache_airflow_providers_git-0.5.0-py3-none-any.whl>`_ (`asc <https://downloads.apache.org/airflow/providers/apache_airflow_providers_git-0.5.0-py3-none-any.whl.asc>`__, `sha512 <https://downloads.apache.org/airflow/providers/apache_airflow_providers_git-0.5.0-py3-none-any.whl.sha512>`__)
@@ -23,12 +23,13 @@ description: |
23
23
 
24
24
  state: ready
25
25
  lifecycle: production
26
- source-date-epoch: 1787011200
26
+ source-date-epoch: 1788976455
27
27
  # Note that those versions are maintained by release manager - do not update them manually
28
28
  # with the exception of case where other provider in sources has >= new provider version.
29
29
  # In such case adding >= NEW_VERSION and bumping to NEW_VERSION in a provider have
30
30
  # to be done in the same PR
31
31
  versions:
32
+ - 0.5.0
32
33
  - 0.4.3
33
34
  - 0.4.2
34
35
  - 0.4.1
@@ -81,4 +82,7 @@ connection-types:
81
82
  host: Repository URL
82
83
  password: Access Token (optional)
83
84
  placeholders:
84
- extra: '{"key_file": "optional/path/to/keyfile", "private_key": "optional inline private key"}'
85
+ extra: '{"key_file": "optional/path/to/keyfile", "private_key": "optional inline private key",
86
+ "private_key_passphrase": "", "strict_host_key_checking": "accept-new", "known_hosts_file": "",
87
+ "ssh_config_file": "", "host_proxy_cmd": "", "ssh_port": "", "github_app_id": "",
88
+ "github_installation_id": ""}'
@@ -25,7 +25,7 @@ build-backend = "flit_core.buildapi"
25
25
 
26
26
  [project]
27
27
  name = "apache-airflow-providers-git"
28
- version = "0.4.3"
28
+ version = "0.5.0"
29
29
  description = "Provider package apache-airflow-providers-git for Apache Airflow"
30
30
  readme = "README.rst"
31
31
  license = "Apache-2.0"
@@ -64,6 +64,13 @@ dependencies = [
64
64
  "GitPython>=3.1.44",
65
65
  ]
66
66
 
67
+ # The optional dependencies should be modified in place in the generated file
68
+ # Any change in the dependencies is preserved when the file is regenerated
69
+ [project.optional-dependencies]
70
+ github = [
71
+ "PyGithub>=2.1.1",
72
+ ]
73
+
67
74
  [dependency-groups]
68
75
  dev = [
69
76
  "apache-airflow",
@@ -71,6 +78,7 @@ dev = [
71
78
  "apache-airflow-devel-common",
72
79
  "apache-airflow-providers-common-compat",
73
80
  # Additional devel dependencies (do not remove this line and add extra development dependencies)
81
+ "PyGithub>=2.1.1"
74
82
  ]
75
83
 
76
84
  # To build docs:
@@ -99,8 +107,8 @@ apache-airflow-providers-common-sql = {workspace = true}
99
107
  apache-airflow-providers-standard = {workspace = true}
100
108
 
101
109
  [project.urls]
102
- "Documentation" = "https://airflow.apache.org/docs/apache-airflow-providers-git/0.4.3"
103
- "Changelog" = "https://airflow.apache.org/docs/apache-airflow-providers-git/0.4.3/changelog.html"
110
+ "Documentation" = "https://airflow.apache.org/docs/apache-airflow-providers-git/0.5.0"
111
+ "Changelog" = "https://airflow.apache.org/docs/apache-airflow-providers-git/0.5.0/changelog.html"
104
112
  "Bug Tracker" = "https://github.com/apache/airflow/issues"
105
113
  "Source Code" = "https://github.com/apache/airflow"
106
114
  "Slack Chat" = "https://s.apache.org/airflow-slack"
@@ -29,7 +29,7 @@ from airflow import __version__ as airflow_version
29
29
 
30
30
  __all__ = ["__version__"]
31
31
 
32
- __version__ = "0.4.3"
32
+ __version__ = "0.5.0"
33
33
 
34
34
  if packaging.version.parse(packaging.version.parse(airflow_version).base_version) < packaging.version.parse(
35
35
  "3.0.0"
@@ -51,7 +51,7 @@ def get_provider_info():
51
51
  "password": "Access Token (optional)",
52
52
  },
53
53
  "placeholders": {
54
- "extra": '{"key_file": "optional/path/to/keyfile", "private_key": "optional inline private key"}'
54
+ "extra": '{"key_file": "optional/path/to/keyfile", "private_key": "optional inline private key", "private_key_passphrase": "", "strict_host_key_checking": "accept-new", "known_hosts_file": "", "ssh_config_file": "", "host_proxy_cmd": "", "ssh_port": "", "github_app_id": "", "github_installation_id": ""}'
55
55
  },
56
56
  },
57
57
  }
@@ -26,11 +26,13 @@ import shlex
26
26
  import stat
27
27
  import tempfile
28
28
  import warnings
29
+ from collections.abc import Generator
30
+ from datetime import datetime, timedelta, timezone
29
31
  from typing import Any
30
32
  from urllib.parse import quote as urlquote
31
33
 
32
34
  from airflow.exceptions import AirflowProviderDeprecationWarning
33
- from airflow.providers.common.compat.sdk import BaseHook
35
+ from airflow.providers.common.compat.sdk import AirflowOptionalProviderFeatureException, BaseHook
34
36
 
35
37
  log = logging.getLogger(__name__)
36
38
 
@@ -53,6 +55,10 @@ class GitHook(BaseHook):
53
55
  * ``ssh_config_file`` — path to a custom SSH config file.
54
56
  * ``host_proxy_cmd`` — SSH ProxyCommand string (e.g. for bastion/jump hosts).
55
57
  * ``ssh_port`` — non-default SSH port.
58
+ * ``github_app_id`` — GitHub App ID used for GitHub App authentication. Requires the GitHub App
59
+ private key to be provided as a PEM-encoded key via either ``private_key`` (inline) or
60
+ ``key_file`` (path to key file).
61
+ * ``github_installation_id`` — GitHub App installation ID used for GitHub App authentication.
56
62
  """
57
63
 
58
64
  conn_name_attr = "git_conn_id"
@@ -80,6 +86,8 @@ class GitHook(BaseHook):
80
86
  "ssh_config_file": "",
81
87
  "host_proxy_cmd": "",
82
88
  "ssh_port": "",
89
+ "github_app_id": "",
90
+ "github_installation_id": "",
83
91
  }
84
92
  )
85
93
  },
@@ -110,6 +118,11 @@ class GitHook(BaseHook):
110
118
  self.host_proxy_cmd = extra.get("host_proxy_cmd")
111
119
  self.ssh_port: int | None = int(extra["ssh_port"]) if extra.get("ssh_port") else None
112
120
 
121
+ # GitHub App Auth Options
122
+ self.github_app_id = extra.get("github_app_id")
123
+ self.github_installation_id = extra.get("github_installation_id")
124
+ self.github_app_token_exp: datetime | None = None
125
+
113
126
  self.env: dict[str, str] = {}
114
127
 
115
128
  if self.key_file and self.private_key:
@@ -127,6 +140,21 @@ class GitHook(BaseHook):
127
140
  AirflowProviderDeprecationWarning,
128
141
  stacklevel=2,
129
142
  )
143
+ github_app_fields = (self.github_app_id, self.github_installation_id)
144
+ if any(github_app_fields) and not all(github_app_fields):
145
+ raise ValueError(
146
+ "Both 'github_app_id' and 'github_installation_id' must be provided to use GitHub App Authentication"
147
+ )
148
+ if all(github_app_fields):
149
+ if self.auth_token:
150
+ raise ValueError("Password field must be empty to use GitHub App Auth")
151
+ if not (self.repo_url or "").startswith(("https://", "http://")):
152
+ raise ValueError(
153
+ f"GitHub App authentication requires an HTTPS repository URL, but got: {self.repo_url!r}"
154
+ )
155
+ if self.key_file and not self.private_key:
156
+ with open(self.key_file, encoding="utf-8") as key_file:
157
+ self.private_key = key_file.read()
130
158
  self._process_git_auth_url()
131
159
 
132
160
  _VALID_STRICT_HOST_KEY_CHECKING = frozenset({"yes", "no", "accept-new", "off", "ask"})
@@ -183,7 +211,89 @@ class GitHook(BaseHook):
183
211
 
184
212
  return " ".join(parts)
185
213
 
186
- def _process_git_auth_url(self):
214
+ def _get_github_app_token(self):
215
+ try:
216
+ from github import Auth, GithubIntegration
217
+ except ImportError as exc:
218
+ raise AirflowOptionalProviderFeatureException(
219
+ "The PyGithub library is required for GitHub App authentication. Please install it with 'pip install apache-airflow-providers-git[github]'"
220
+ ) from exc
221
+
222
+ auth = Auth.AppAuth(self.github_app_id, self.private_key)
223
+ integration = GithubIntegration(auth=auth)
224
+ access_token = integration.get_access_token(installation_id=self.github_installation_id)
225
+ github_app_token_exp = access_token.expires_at
226
+ log.info(
227
+ "Successfully obtained GitHub App installation access token (expires at: %s)",
228
+ github_app_token_exp,
229
+ )
230
+
231
+ return "x-access-token", access_token.token, github_app_token_exp
232
+
233
+ def _ensure_github_app_token(self) -> None:
234
+ TOKEN_REFRESH_BUFFER = timedelta(minutes=5)
235
+ if (
236
+ self.github_app_token_exp is None
237
+ or self.github_app_token_exp < datetime.now(timezone.utc) + TOKEN_REFRESH_BUFFER
238
+ ):
239
+ log.info(
240
+ "GitHub App token is missing or near expiry (expires at: %s). Refreshing token.",
241
+ self.github_app_token_exp,
242
+ )
243
+ self.user_name, self.auth_token, self.github_app_token_exp = self._get_github_app_token()
244
+
245
+ @contextlib.contextmanager
246
+ def _github_app_askpass_env(self) -> Generator[None]:
247
+ if not self.auth_token:
248
+ yield
249
+ return
250
+
251
+ token = shlex.quote(self.auth_token)
252
+ with tempfile.NamedTemporaryFile(mode="w", suffix=".sh", delete=True) as askpass_script:
253
+ askpass_script.write(
254
+ "#!/bin/sh\n"
255
+ 'case "$1" in\n'
256
+ " *Username*) echo x-access-token;;\n"
257
+ f" *Password*) echo {token};;\n"
258
+ f" *) echo {token};;\n"
259
+ "esac\n"
260
+ )
261
+ askpass_script.flush()
262
+ os.chmod(askpass_script.name, stat.S_IRWXU)
263
+
264
+ old_askpass = os.environ.get("GIT_ASKPASS")
265
+ old_lc_all = os.environ.get("LC_ALL")
266
+ old_terminal_prompt = os.environ.get("GIT_TERMINAL_PROMPT")
267
+ try:
268
+ os.environ["GIT_ASKPASS"] = askpass_script.name
269
+ os.environ["GIT_TERMINAL_PROMPT"] = "0"
270
+ self.env["GIT_ASKPASS"] = askpass_script.name
271
+ self.env["LC_ALL"] = "C"
272
+ self.env["GIT_TERMINAL_PROMPT"] = "0"
273
+ yield
274
+ finally:
275
+ if old_askpass is None:
276
+ self.env.pop("GIT_ASKPASS", None)
277
+ os.environ.pop("GIT_ASKPASS", None)
278
+ else:
279
+ self.env["GIT_ASKPASS"] = old_askpass
280
+ os.environ["GIT_ASKPASS"] = old_askpass
281
+
282
+ if old_lc_all is None:
283
+ self.env.pop("LC_ALL", None)
284
+ os.environ.pop("LC_ALL", None)
285
+ else:
286
+ self.env["LC_ALL"] = old_lc_all
287
+ os.environ["LC_ALL"] = old_lc_all
288
+
289
+ if old_terminal_prompt is None:
290
+ self.env.pop("GIT_TERMINAL_PROMPT", None)
291
+ os.environ.pop("GIT_TERMINAL_PROMPT", None)
292
+ else:
293
+ self.env["GIT_TERMINAL_PROMPT"] = old_terminal_prompt
294
+ os.environ["GIT_TERMINAL_PROMPT"] = old_terminal_prompt
295
+
296
+ def _process_git_auth_url(self) -> None:
187
297
  if not isinstance(self.repo_url, str):
188
298
  return
189
299
  if self.auth_token and self.repo_url.startswith("https://"):
@@ -240,6 +350,12 @@ class GitHook(BaseHook):
240
350
 
241
351
  @contextlib.contextmanager
242
352
  def configure_hook_env(self):
353
+ if self.github_app_id is not None and self.github_installation_id is not None:
354
+ self._ensure_github_app_token()
355
+ with self._github_app_askpass_env():
356
+ yield
357
+ return
358
+
243
359
  if self.private_key:
244
360
  with tempfile.NamedTemporaryFile(mode="w", delete=True) as tmp_keyfile:
245
361
  tmp_keyfile.write(self.private_key)
@@ -51,6 +51,12 @@ CONN_ONLY_PATH = "my_git_conn_only_path"
51
51
  CONN_ONLY_INLINE_KEY = "my_git_conn_only_inline_key"
52
52
  CONN_BOTH_PATH_INLINE = "my_git_conn_both_path_inline"
53
53
  CONN_NO_REPO_URL = "my_git_conn_no_repo_url"
54
+ CONN_APP_INLINE_KEY = "git_app_inline_key"
55
+ CONN_APP_ONLY_APP_ID = "git_app_only_app_id"
56
+ CONN_APP_ONLY_INSTALLATION_ID = "git_app_only_installation_id"
57
+ CONN_APP_NO_KEY = "git_app_no_key"
58
+ CONN_APP_INVALID_APP_ID = "git_app_invalid_app_id"
59
+ CONN_APP_INVALID_INSTALLATION_ID = "git_app_invalid_installation_id"
54
60
 
55
61
 
56
62
  @pytest.fixture
@@ -122,6 +128,85 @@ class TestGitHook:
122
128
  },
123
129
  )
124
130
  )
131
+ create_connection_without_db(
132
+ Connection(
133
+ conn_id=CONN_BOTH_PATH_INLINE,
134
+ host="path/to/repo",
135
+ conn_type="git",
136
+ extra={
137
+ "key_file": "path/to/key",
138
+ "private_key": "inline_key",
139
+ },
140
+ )
141
+ )
142
+ create_connection_without_db(
143
+ Connection(
144
+ conn_id="my_git_conn_strict",
145
+ host=AIRFLOW_GIT,
146
+ conn_type="git",
147
+ extra='{"key_file": "/files/pkey.pem", "strict_host_key_checking": "yes"}',
148
+ )
149
+ )
150
+ create_connection_without_db(
151
+ Connection(
152
+ conn_id=CONN_APP_INLINE_KEY,
153
+ host=AIRFLOW_HTTPS_URL,
154
+ conn_type="git",
155
+ extra={
156
+ "github_app_id": "12345",
157
+ "github_installation_id": "67890",
158
+ "private_key": "inline_pem_key",
159
+ },
160
+ )
161
+ )
162
+ create_connection_without_db(
163
+ Connection(
164
+ conn_id=CONN_APP_ONLY_APP_ID,
165
+ host=AIRFLOW_HTTPS_URL,
166
+ conn_type="git",
167
+ extra={"github_app_id": "12345"},
168
+ )
169
+ )
170
+ create_connection_without_db(
171
+ Connection(
172
+ conn_id=CONN_APP_ONLY_INSTALLATION_ID,
173
+ host=AIRFLOW_HTTPS_URL,
174
+ conn_type="git",
175
+ extra={"github_installation_id": "67890"},
176
+ )
177
+ )
178
+ create_connection_without_db(
179
+ Connection(
180
+ conn_id=CONN_APP_NO_KEY,
181
+ host=AIRFLOW_HTTPS_URL,
182
+ conn_type="git",
183
+ extra={"github_app_id": "12345", "github_installation_id": "67890"},
184
+ )
185
+ )
186
+ create_connection_without_db(
187
+ Connection(
188
+ conn_id=CONN_APP_INVALID_APP_ID,
189
+ host=AIRFLOW_HTTPS_URL,
190
+ conn_type="git",
191
+ extra={
192
+ "github_app_id": "not_an_int",
193
+ "github_installation_id": "67890",
194
+ "private_key": "inline_pem_key",
195
+ },
196
+ )
197
+ )
198
+ create_connection_without_db(
199
+ Connection(
200
+ conn_id=CONN_APP_INVALID_INSTALLATION_ID,
201
+ host=AIRFLOW_HTTPS_URL,
202
+ conn_type="git",
203
+ extra={
204
+ "github_app_id": "12345",
205
+ "github_installation_id": "not_an_int",
206
+ "private_key": "inline_pem_key",
207
+ },
208
+ )
209
+ )
125
210
 
126
211
  @pytest.mark.parametrize(
127
212
  ("conn_id", "hook_kwargs", "expected_repo_url", "warns_on_default"),
@@ -413,3 +498,206 @@ class TestGitHook:
413
498
  assert os.path.exists(askpass_path)
414
499
  # Both the askpass script and the temp key file should be cleaned up
415
500
  assert not os.path.exists(askpass_path)
501
+
502
+ # --- GitHub App auth tests ---
503
+
504
+ def test_only_app_id_without_installation_id_raises(self):
505
+ with pytest.raises(
506
+ ValueError, match="Both 'github_app_id' and 'github_installation_id' must be provided"
507
+ ):
508
+ GitHook(git_conn_id=CONN_APP_ONLY_APP_ID)
509
+
510
+ def test_only_installation_id_without_app_id_raises(self):
511
+ with pytest.raises(
512
+ ValueError,
513
+ match="Both 'github_app_id' and 'github_installation_id' must be provided",
514
+ ):
515
+ GitHook(git_conn_id=CONN_APP_ONLY_INSTALLATION_ID)
516
+
517
+ def test_app_id_and_installation_id_without_key_does_not_raise_on_init(self):
518
+ hook = GitHook(git_conn_id=CONN_APP_NO_KEY)
519
+
520
+ assert hook.github_app_id == "12345"
521
+ assert hook.github_installation_id == "67890"
522
+ assert hook.private_key is None
523
+
524
+ def test_app_auth_with_key_file_reads_file(self, create_connection_without_db, tmp_path, monkeypatch):
525
+ key_file = tmp_path / "app_key.pem"
526
+ key_file.write_text("file_pem_key_content")
527
+ create_connection_without_db(
528
+ Connection(
529
+ conn_id="git_app_key_file",
530
+ host=AIRFLOW_HTTPS_URL,
531
+ conn_type="git",
532
+ extra={
533
+ "github_app_id": "12345",
534
+ "github_installation_id": "67890",
535
+ "key_file": str(key_file),
536
+ },
537
+ )
538
+ )
539
+ from datetime import datetime, timedelta, timezone
540
+
541
+ mock_expiry = datetime.now(timezone.utc) + timedelta(hours=1)
542
+ monkeypatch.setattr(
543
+ "airflow.providers.git.hooks.git.GitHook._get_github_app_token",
544
+ lambda self: ("x-access-token", "ghs_test_token", mock_expiry),
545
+ )
546
+ with pytest.warns(AirflowProviderDeprecationWarning, match="accept-new"):
547
+ hook = GitHook(git_conn_id="git_app_key_file")
548
+
549
+ assert hook.private_key == "file_pem_key_content"
550
+
551
+ def test_app_auth_with_missing_key_file_raises(self, create_connection_without_db):
552
+ create_connection_without_db(
553
+ Connection(
554
+ conn_id="git_app_missing_key_file",
555
+ host=AIRFLOW_HTTPS_URL,
556
+ conn_type="git",
557
+ extra={
558
+ "github_app_id": "12345",
559
+ "github_installation_id": "67890",
560
+ "key_file": "/nonexistent/path/key.pem",
561
+ },
562
+ )
563
+ )
564
+ with pytest.warns(AirflowProviderDeprecationWarning, match="accept-new"):
565
+ with pytest.raises(FileNotFoundError):
566
+ GitHook(git_conn_id="git_app_missing_key_file")
567
+
568
+ def test_app_auth_defers_token_fetch(self, monkeypatch):
569
+ """GitHub App token is not fetched in __init__, only on configure_hook_env."""
570
+ from datetime import datetime, timedelta, timezone
571
+
572
+ mock_called = []
573
+
574
+ def mock_get_token(self):
575
+ mock_called.append(True)
576
+ return ("x-access-token", "ghs_test_token", datetime.now(timezone.utc) + timedelta(hours=1))
577
+
578
+ monkeypatch.setattr(
579
+ "airflow.providers.git.hooks.git.GitHook._get_github_app_token",
580
+ mock_get_token,
581
+ )
582
+ # __init__ should NOT call _get_github_app_token
583
+ with pytest.warns(AirflowProviderDeprecationWarning, match="accept-new"):
584
+ hook = GitHook(git_conn_id=CONN_APP_INLINE_KEY)
585
+ assert len(mock_called) == 0
586
+ assert hook.auth_token is None
587
+ assert hook.github_app_id == "12345"
588
+ assert hook.github_installation_id == "67890"
589
+
590
+ # First call to configure_hook_env should trigger the token fetch
591
+ with hook.configure_hook_env():
592
+ assert len(mock_called) == 1
593
+ assert hook.auth_token == "ghs_test_token"
594
+ assert hook.user_name == "x-access-token"
595
+
596
+ def test_app_auth_success_stores_app_id_and_installation_id(self):
597
+ """App ID and installation ID are stored at __init__ time."""
598
+ with pytest.warns(AirflowProviderDeprecationWarning, match="accept-new"):
599
+ hook = GitHook(git_conn_id=CONN_APP_INLINE_KEY)
600
+ assert hook.github_app_id == "12345"
601
+ assert hook.github_installation_id == "67890"
602
+
603
+ @pytest.mark.parametrize(
604
+ ("app_id", "installation_id"),
605
+ [
606
+ ("12345", "67890"),
607
+ (12345, 67890),
608
+ ],
609
+ )
610
+ def test_app_id_and_installation_id_are_stored_as_provided(
611
+ self, app_id, installation_id, create_connection_without_db, monkeypatch
612
+ ):
613
+ from datetime import datetime, timedelta, timezone
614
+
615
+ create_connection_without_db(
616
+ Connection(
617
+ conn_id="git_app_int_check",
618
+ host=AIRFLOW_HTTPS_URL,
619
+ conn_type="git",
620
+ extra={
621
+ "github_app_id": app_id,
622
+ "github_installation_id": installation_id,
623
+ "private_key": "inline_pem_key",
624
+ },
625
+ )
626
+ )
627
+ monkeypatch.setattr(
628
+ "airflow.providers.git.hooks.git.GitHook._get_github_app_token",
629
+ lambda self: ("x-access-token", "token", datetime.now(timezone.utc) + timedelta(hours=1)),
630
+ )
631
+ with pytest.warns(AirflowProviderDeprecationWarning, match="accept-new"):
632
+ hook = GitHook(git_conn_id="git_app_int_check")
633
+ assert hook.github_app_id == app_id
634
+ assert hook.github_installation_id == installation_id
635
+
636
+ def test_github_app_token_refresh_near_expiry(self, monkeypatch):
637
+ """Token is refreshed when near expiry during configure_hook_env."""
638
+ from datetime import datetime, timedelta, timezone
639
+
640
+ mock_get_token_call_count = [0]
641
+
642
+ def mock_get_token(self):
643
+ mock_get_token_call_count[0] += 1
644
+ # First call returns token expiring in 3 minutes
645
+ if mock_get_token_call_count[0] == 1:
646
+ return (
647
+ "x-access-token",
648
+ f"token_{mock_get_token_call_count[0]}",
649
+ datetime.now(timezone.utc) + timedelta(minutes=3),
650
+ )
651
+ # Second call (refresh) returns token expiring in 1 hour
652
+ return (
653
+ "x-access-token",
654
+ f"token_{mock_get_token_call_count[0]}",
655
+ datetime.now(timezone.utc) + timedelta(hours=1),
656
+ )
657
+
658
+ monkeypatch.setattr(
659
+ "airflow.providers.git.hooks.git.GitHook._get_github_app_token",
660
+ mock_get_token,
661
+ )
662
+ with pytest.warns(AirflowProviderDeprecationWarning, match="accept-new"):
663
+ hook = GitHook(git_conn_id=CONN_APP_INLINE_KEY)
664
+ assert mock_get_token_call_count[0] == 0 # No call in __init__
665
+
666
+ # First configure_hook_env triggers first token fetch
667
+ with hook.configure_hook_env():
668
+ assert mock_get_token_call_count[0] == 1
669
+ assert hook.auth_token == "token_1"
670
+
671
+ # Second configure_hook_env triggers refresh (token near expiry)
672
+ with hook.configure_hook_env():
673
+ assert mock_get_token_call_count[0] == 2
674
+ assert hook.auth_token == "token_2"
675
+
676
+ def test_github_app_integration_call_shape(self, monkeypatch):
677
+ """Verify GithubIntegration is called with correct arguments."""
678
+ from datetime import datetime, timedelta, timezone
679
+ from unittest import mock
680
+
681
+ mock_integration = mock.MagicMock()
682
+ mock_access_token = mock.MagicMock()
683
+ mock_access_token.token = "ghs_test_token"
684
+ mock_access_token.expires_at = datetime.now(timezone.utc) + timedelta(hours=1)
685
+ mock_integration.get_access_token.return_value = mock_access_token
686
+
687
+ import sys
688
+ from types import SimpleNamespace
689
+
690
+ fake_github = SimpleNamespace(
691
+ Auth=SimpleNamespace(AppAuth=lambda app_id, key: "auth"),
692
+ GithubIntegration=lambda auth: mock_integration,
693
+ )
694
+ monkeypatch.setitem(sys.modules, "github", fake_github)
695
+
696
+ with pytest.warns(AirflowProviderDeprecationWarning, match="accept-new"):
697
+ hook = GitHook(git_conn_id=CONN_APP_INLINE_KEY)
698
+ with hook.configure_hook_env():
699
+ # Verify get_access_token was called with installation_id kwarg
700
+ assert mock_integration.get_access_token.call_count == 1
701
+ _, kwargs = mock_integration.get_access_token.call_args
702
+ assert "installation_id" in kwargs
703
+ assert str(kwargs["installation_id"]) == "67890"