salla-gitpuller 0.1.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.
File without changes
@@ -0,0 +1,12 @@
1
+ Metadata-Version: 2.4
2
+ Name: salla_gitpuller
3
+ Version: 0.1.0
4
+ Summary: A lightweight utility to git pull a repository using SSH deploy keys stored in environment variables
5
+ Author-email: Muhammad Zahid <zahidmuhammad127@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/Zahid07/gitpuller
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Dynamic: license-file
11
+
12
+ # gitpuller
@@ -0,0 +1 @@
1
+ # gitpuller
@@ -0,0 +1,4 @@
1
+ from .gitpull import git_pull
2
+ from .utils import transform_custom, get_repo_path, get_env_base_path
3
+
4
+ __all__ = ["git_pull", "transform_custom", "get_repo_path", "get_env_base_path"]
@@ -0,0 +1,68 @@
1
+ import os
2
+ import subprocess
3
+ from typing import Any, Dict
4
+
5
+
6
+ def git_pull(repo_path: str, workspace_name: str, git_url: str, key_material: str) -> Dict[str, Any]:
7
+ """
8
+ Executes 'git pull' in the specified repository path using a deploy key
9
+ provided via the env var WP_AUTOPULL_SSHKEY.
10
+
11
+ Args:
12
+ repo_path: Path to the local git repository
13
+ workspace_name: Logical workspace identifier
14
+ git_url: Git remote URL (SSH-based)
15
+ Returns:
16
+ Dict with status and command output.
17
+ """
18
+ print(f"Running git pull for workspace: {workspace_name}")
19
+ print(f"Repo path: {repo_path}")
20
+
21
+ if not os.path.exists(repo_path):
22
+ raise FileNotFoundError(f"Repo path does not exist: {repo_path}")
23
+
24
+
25
+ if not key_material:
26
+ raise EnvironmentError(f"Missing SSH key material for workspace: {workspace_name}")
27
+
28
+ if "\\n" in key_material and "\n" not in key_material:
29
+ key_material = key_material.replace("\\n", "\n")
30
+
31
+ ssh_dir = os.path.expanduser("~/.ssh")
32
+ key_path = os.path.join(ssh_dir, "gitpuller_deploy_key")
33
+ os.makedirs(ssh_dir, exist_ok=True)
34
+ os.chmod(ssh_dir, 0o700)
35
+
36
+ with open(key_path, "w") as f:
37
+ f.write(key_material)
38
+ os.chmod(key_path, 0o600)
39
+
40
+ cmd = [
41
+ "git",
42
+ "-c",
43
+ f"core.sshCommand=ssh -i {key_path} -o IdentitiesOnly=yes -o StrictHostKeyChecking=accept-new",
44
+ "pull",
45
+ git_url,
46
+ "master",
47
+ ]
48
+
49
+ try:
50
+ os.chdir(repo_path)
51
+ result = subprocess.run(cmd, capture_output=True, text=True, check=True)
52
+ git_output = result.stdout
53
+ git_status = "success"
54
+ except subprocess.CalledProcessError as e:
55
+ git_output = (e.stdout or "") + (e.stderr or "")
56
+ git_status = "error"
57
+ finally:
58
+ try:
59
+ os.remove(key_path)
60
+ except Exception:
61
+ pass
62
+
63
+ return {
64
+ "workspace": workspace_name,
65
+ "repo_path": repo_path,
66
+ "git_pull_status": git_status,
67
+ "git_pull_output": git_output.strip(),
68
+ }
@@ -0,0 +1,35 @@
1
+ import os
2
+
3
+
4
+ def get_repo_path() -> str:
5
+ """
6
+ Returns the current working repository path (directory of this script).
7
+ """
8
+ return os.getcwd()
9
+
10
+
11
+ def get_env_base_path() -> str:
12
+ """
13
+ Returns the value of the ENV environment variable.
14
+ """
15
+ return os.environ.get("ENV", "")
16
+
17
+
18
+ def transform_custom() -> tuple[str, str]:
19
+ """
20
+ Returns a tuple of (repo_path, base_path)
21
+ """
22
+ repo_path = get_repo_path()
23
+ base_path = get_env_base_path()
24
+
25
+ if not repo_path:
26
+ raise Exception("Unable to determine repository path.")
27
+
28
+ return repo_path, base_path
29
+
30
+
31
+ def test_output(output) -> None:
32
+ """
33
+ Simple test function to validate non-empty output.
34
+ """
35
+ assert output is not None, "Output is undefined"
@@ -0,0 +1,19 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "salla_gitpuller"
7
+ version = "0.1.0"
8
+ description = "A lightweight utility to git pull a repository using SSH deploy keys stored in environment variables"
9
+ readme = "README.md"
10
+ authors = [
11
+ { name="Muhammad Zahid", email="zahidmuhammad127@gmail.com" }
12
+ ]
13
+ license = { text = "MIT" }
14
+ dependencies = []
15
+
16
+ [project.urls]
17
+ Homepage = "https://github.com/Zahid07/gitpuller"
18
+
19
+
@@ -0,0 +1,12 @@
1
+ Metadata-Version: 2.4
2
+ Name: salla_gitpuller
3
+ Version: 0.1.0
4
+ Summary: A lightweight utility to git pull a repository using SSH deploy keys stored in environment variables
5
+ Author-email: Muhammad Zahid <zahidmuhammad127@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/Zahid07/gitpuller
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Dynamic: license-file
11
+
12
+ # gitpuller
@@ -0,0 +1,10 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ gitpuller/__init__.py
5
+ gitpuller/gitpull.py
6
+ gitpuller/utils.py
7
+ salla_gitpuller.egg-info/PKG-INFO
8
+ salla_gitpuller.egg-info/SOURCES.txt
9
+ salla_gitpuller.egg-info/dependency_links.txt
10
+ salla_gitpuller.egg-info/top_level.txt
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+