dump-github 0.1.8__py3-none-any.whl → 0.2.0__py3-none-any.whl

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.
dump_github/__init__.py CHANGED
@@ -1,2 +1,4 @@
1
- # from .lib import *
2
- from .main import main
1
+ from ._version import __version__
2
+ from .main import main
3
+
4
+ __all__ = ["__version__", "main"]
@@ -0,0 +1 @@
1
+ __version__ = "0.2.0"
dump_github/lib.py CHANGED
@@ -1,63 +1,158 @@
1
- import requests
2
-
3
-
4
- def _github_auth_headers(token):
5
- """GitHub REST API expects Authorization: Bearer <token> (PAT classic / fine-grained)."""
6
- if not token:
7
- return {}
8
- token = token.strip()
9
- if not token:
10
- return {}
11
- if token.lower().startswith(("bearer ", "token ", "basic ")):
12
- return {"Authorization": token}
13
- return {"Authorization": "Bearer {}".format(token)}
14
-
15
-
16
- def get_page_of_repos(username, page, token=""):
17
- token_header = _github_auth_headers(token)
18
-
19
- if token_header:
20
- url = "https://api.github.com/user/repos?per_page=100&page={}".format(page)
21
- headers = {
22
- "Accept": "application/vnd.github+json",
23
- "X-GitHub-Api-Version": "2022-11-28",
24
- }
25
- headers.update(token_header)
26
- response = requests.get(url, headers=headers)
27
- if response.status_code == 200:
28
- repos = response.json()
29
- return repos
30
- else:
31
- return []
32
- else:
33
- url = "https://api.github.com/users/{}/repos?per_page=100&page={}".format(
34
- username, page
35
- )
36
- headers = {
37
- "Accept": "application/vnd.github+json",
38
- "X-GitHub-Api-Version": "2022-11-28",
39
- }
40
- response = requests.get(url, headers=headers)
41
- if response.status_code == 200:
42
- repos = response.json()
43
- return repos
44
- else:
45
- return []
46
-
47
-
48
- def search_user_repos(username, token=""):
49
- page = 0
50
- res_repos = []
51
-
52
- while True:
53
- page += 1
54
- repos = get_page_of_repos(username, page, token)
55
- if len(repos) == 0:
56
- break
57
- res_repos += repos
58
-
59
- return res_repos
60
-
61
-
62
- # Backward-compatible alias for the historical typo
63
- serach_user_repos = search_user_repos
1
+ from urllib.parse import quote
2
+
3
+ import requests
4
+
5
+ GITHUB_API = "https://api.github.com"
6
+ PER_PAGE = 100
7
+
8
+
9
+ def _github_auth_headers(token):
10
+ """GitHub REST API expects Authorization: Bearer <token> (PAT classic / fine-grained)."""
11
+ if not token:
12
+ return {}
13
+ token = token.strip()
14
+ if not token:
15
+ return {}
16
+ if token.lower().startswith(("bearer ", "token ", "basic ")):
17
+ return {"Authorization": token}
18
+ return {"Authorization": "Bearer {}".format(token)}
19
+
20
+
21
+ def _api_headers(token=""):
22
+ headers = {
23
+ "Accept": "application/vnd.github+json",
24
+ "X-GitHub-Api-Version": "2022-11-28",
25
+ }
26
+ headers.update(_github_auth_headers(token))
27
+ return headers
28
+
29
+
30
+ def _api_get(path, token=""):
31
+ """GET one GitHub REST API path and return the decoded JSON, or None on failure."""
32
+ try:
33
+ response = requests.get(
34
+ GITHUB_API + path, headers=_api_headers(token), timeout=30
35
+ )
36
+ except requests.RequestException:
37
+ return None
38
+ if response.status_code != 200:
39
+ return None
40
+ try:
41
+ return response.json()
42
+ except ValueError:
43
+ return None
44
+
45
+
46
+ def get_authenticated_login(token=""):
47
+ """Return the login of the token owner, or None if there is no usable token."""
48
+ if not _github_auth_headers(token):
49
+ return None
50
+ account = _api_get("/user", token)
51
+ if not isinstance(account, dict):
52
+ return None
53
+ return account.get("login") or None
54
+
55
+
56
+ def get_account_type(username, token=""):
57
+ """Return ``"Organization"``/``"User"`` for ``username``, or None if unknown."""
58
+ quoted = quote(username, safe="")
59
+ account = _api_get("/users/{}".format(quoted), token)
60
+ if isinstance(account, dict) and account.get("type"):
61
+ return account["type"]
62
+ # ``/users/{org}`` is not guaranteed to resolve for organisations, so fall
63
+ # back to the org endpoint, which unambiguously identifies one.
64
+ org = _api_get("/orgs/{}".format(quoted), token)
65
+ if isinstance(org, dict) and org.get("login"):
66
+ return "Organization"
67
+ return None
68
+
69
+
70
+ def _repos_path(username, page, authenticated_login, account_type):
71
+ """Build a listing API path that only contains repositories owned by ``username``.
72
+
73
+ ``GET /user/repos`` (used by an earlier version whenever a token was
74
+ supplied) lists every repository the token owner can see, which includes
75
+ repositories of the organisations the token owner is a member of, and it
76
+ ignores ``username`` entirely. Listing must therefore be scoped to the
77
+ requested account:
78
+
79
+ * organisation -> ``/orgs/{org}/repos?type=all``; only repositories owned
80
+ by that organisation, including private ones the token may access
81
+ * own user account -> ``/user/repos?affiliation=owner``; keeps private
82
+ repos, drops organisation/collaborator repos
83
+ * any other user account -> ``/users/{username}/repos?type=owner``
84
+ """
85
+ quoted = quote(username, safe="")
86
+ if (account_type or "").lower() == "organization":
87
+ return "/orgs/{}/repos?type=all&per_page={}&page={}".format(
88
+ quoted, PER_PAGE, page
89
+ )
90
+ own_account = bool(authenticated_login) and (
91
+ authenticated_login.lower() == username.lower()
92
+ )
93
+ if own_account:
94
+ return "/user/repos?affiliation=owner&per_page={}&page={}".format(
95
+ PER_PAGE, page
96
+ )
97
+ return "/users/{}/repos?type=owner&per_page={}&page={}".format(
98
+ quoted, PER_PAGE, page
99
+ )
100
+
101
+
102
+ def _is_owned_by(repo, username):
103
+ owner = repo.get("owner") or {}
104
+ login = owner.get("login") or ""
105
+ if login:
106
+ return login.lower() == username.lower()
107
+ full_name = repo.get("full_name") or ""
108
+ return full_name.split("/", 1)[0].lower() == username.lower()
109
+
110
+
111
+ def _fetch_repos_page(username, page, token="", authenticated_login=None,
112
+ account_type=None):
113
+ """Fetch one raw page of repositories owned by ``username``."""
114
+ path = _repos_path(username, page, authenticated_login, account_type)
115
+ repos = _api_get(path, token)
116
+ if not isinstance(repos, list):
117
+ return []
118
+ return [repo for repo in repos if isinstance(repo, dict)]
119
+
120
+
121
+ def get_page_of_repos(username, page, token="", authenticated_login=None,
122
+ account_type=None):
123
+ username = username.strip()
124
+ if account_type is None:
125
+ account_type = get_account_type(username, token)
126
+ if authenticated_login is None:
127
+ authenticated_login = get_authenticated_login(token)
128
+ repos = _fetch_repos_page(
129
+ username, page, token, authenticated_login, account_type
130
+ )
131
+ return [repo for repo in repos if _is_owned_by(repo, username)]
132
+
133
+
134
+ def search_user_repos(username, token=""):
135
+ username = username.strip()
136
+ authenticated_login = get_authenticated_login(token)
137
+ account_type = get_account_type(username, token)
138
+ page = 0
139
+ res_repos = []
140
+
141
+ while True:
142
+ page += 1
143
+ repos = _fetch_repos_page(
144
+ username, page, token, authenticated_login, account_type
145
+ )
146
+ if len(repos) == 0:
147
+ break
148
+ res_repos += repos
149
+ if len(repos) < PER_PAGE:
150
+ break
151
+
152
+ # Never return repositories that belong to somebody else (e.g. a user repo
153
+ # returned for an organisation, or an organisation the token owner is in).
154
+ return [repo for repo in res_repos if _is_owned_by(repo, username)]
155
+
156
+
157
+ # Backward-compatible alias for the historical typo
158
+ serach_user_repos = search_user_repos
dump_github/main.py CHANGED
@@ -1,109 +1,131 @@
1
- import argparse
2
- import os
3
- import subprocess
4
- from urllib.parse import quote
5
-
6
- from .lib import search_user_repos
7
-
8
- parser = argparse.ArgumentParser(
9
- prog="dump-github",
10
- description="Backup users github repo.",
11
- epilog="https://github.com/Core2002/dump_github",
12
- )
13
-
14
- parser.add_argument("username")
15
- parser.add_argument(
16
- "-d", "--download_zip", action="store_true", help="only download zip file"
17
- )
18
- parser.add_argument("-p", "--print", action="store_true", help="only print urls")
19
- parser.add_argument(
20
- "--token",
21
- action="store",
22
- default="",
23
- help="GitHub personal access token (or set GITHUB_TOKEN). Required for private repos and higher API rate limits.",
24
- )
25
- parser.add_argument(
26
- "--limit_size",
27
- type=int,
28
- default=100,
29
- help="limit size(MB) of download zip file, if 0 then no limit(default:100).",
30
- )
31
-
32
- args = parser.parse_args()
33
-
34
-
35
- def clone_repo(repo, token=""):
36
- name = repo["name"]
37
- url = repo["clone_url"]
38
- if token:
39
- url = url.replace(
40
- "https://",
41
- "https://x-access-token:{}@".format(quote(token, safe="")),
42
- 1,
43
- )
44
- print("Clone repo: {}".format(name))
45
- subprocess.run(["git", "clone", url], check=False)
46
-
47
-
48
- def download_zip(user_name, reop, token=""):
49
- ref = reop.get("default_branch") or "main"
50
- max_size = args.limit_size * 1000 * 1000
51
- file_name = "./{}_{}.zip".format(user_name, reop["name"])
52
- curl_cmd = [
53
- "curl",
54
- "-sS",
55
- "-L",
56
- "--connect-timeout",
57
- "5",
58
- "--retry",
59
- "3",
60
- "--retry-delay",
61
- "3",
62
- ]
63
- if max_size > 0:
64
- curl_cmd.extend(["--max-filesize", str(max_size)])
65
- if token:
66
- url = "https://api.github.com/repos/{}/{}/zipball/{}".format(
67
- user_name, reop["name"], ref
68
- )
69
- curl_cmd.extend(
70
- [
71
- "-H",
72
- "Authorization: Bearer {}".format(token),
73
- "-H",
74
- "Accept: application/vnd.github+json",
75
- "-o",
76
- file_name,
77
- url,
78
- ]
79
- )
80
- else:
81
- url = "https://github.com/{}/{}/archive/refs/heads/{}.zip".format(
82
- user_name, reop["name"], ref
83
- )
84
- curl_cmd.extend(["-o", file_name, url])
85
- print("Download {} : {}".format(reop["name"], url))
86
- subprocess.run(curl_cmd, check=False)
87
- if (
88
- max_size > 0
89
- and os.path.exists(file_name)
90
- and os.stat(file_name).st_size > max_size
91
- ):
92
- os.remove(file_name)
93
- print("Removed {} because it exceeds the limit size.".format(file_name))
94
-
95
-
96
- def main():
97
- token = (args.token or "").strip() or (os.environ.get("GITHUB_TOKEN") or "").strip()
98
- repos = search_user_repos(args.username, token)
99
- for repo in repos:
100
- if args.print == True:
101
- print(repo["clone_url"])
102
- elif args.download_zip == True:
103
- download_zip(args.username, repo, token)
104
- else:
105
- clone_repo(repo, token)
106
-
107
-
108
- if __name__ == "__main__":
109
- main()
1
+ import argparse
2
+ import os
3
+ import subprocess
4
+
5
+ from ._version import __version__
6
+ from .lib import search_user_repos
7
+
8
+ # One-shot credential helper: git asks for credentials, the helper answers with
9
+ # the token from the environment. The token is therefore never part of the
10
+ # clone URL and never gets written to the cloned repository's .git/config.
11
+ GIT_CREDENTIAL_HELPER = (
12
+ '!f() { test "$1" = get || return 0; '
13
+ 'echo username=x-access-token; '
14
+ 'echo "password=$DUMP_GITHUB_TOKEN"; }; f'
15
+ )
16
+
17
+ parser = argparse.ArgumentParser(
18
+ prog="dump-github",
19
+ description="Backup users github repo.",
20
+ epilog="https://github.com/Core2002/dump_github",
21
+ )
22
+
23
+ parser.add_argument("username")
24
+ parser.add_argument(
25
+ "-d", "--download_zip", action="store_true", help="only download zip file"
26
+ )
27
+ parser.add_argument("-p", "--print", action="store_true", help="only print urls")
28
+ parser.add_argument(
29
+ "--version", action="version", version="%(prog)s {}".format(__version__)
30
+ )
31
+ parser.add_argument(
32
+ "--token",
33
+ action="store",
34
+ default="",
35
+ help="GitHub personal access token (or set GITHUB_TOKEN). Required for private repos and higher API rate limits.",
36
+ )
37
+ parser.add_argument(
38
+ "--limit_size",
39
+ type=int,
40
+ default=100,
41
+ help="limit size(MB) of download zip file, if 0 then no limit(default:100).",
42
+ )
43
+
44
+
45
+ def clone_repo(repo, token=""):
46
+ name = repo["name"]
47
+ url = repo["clone_url"]
48
+ cmd = ["git", "clone", url]
49
+ env = None
50
+ if token:
51
+ # Use a credential helper instead of https://x-access-token:TOKEN@...
52
+ # so the token does not leak into `ps` output or .git/config.
53
+ cmd = [
54
+ "git",
55
+ "-c",
56
+ "credential.helper=",
57
+ "-c",
58
+ "credential.helper={}".format(GIT_CREDENTIAL_HELPER),
59
+ "clone",
60
+ url,
61
+ ]
62
+ env = os.environ.copy()
63
+ env["DUMP_GITHUB_TOKEN"] = token
64
+ env["GIT_TERMINAL_PROMPT"] = "0"
65
+ print("Clone repo: {}".format(name))
66
+ subprocess.run(cmd, env=env, check=False)
67
+
68
+
69
+ def download_zip(user_name, reop, token="", limit_size=100):
70
+ ref = reop.get("default_branch") or "main"
71
+ # Always archive the repository the API actually listed. Using the
72
+ # positional username here would point at the wrong owner whenever the
73
+ # repo does not belong to that user.
74
+ full_name = reop.get("full_name") or "{}/{}".format(user_name, reop["name"])
75
+ max_size = limit_size * 1000 * 1000
76
+ file_name = "./{}.zip".format(full_name.replace("/", "_"))
77
+ curl_cmd = [
78
+ "curl",
79
+ "-sS",
80
+ "-L",
81
+ "--connect-timeout",
82
+ "5",
83
+ "--retry",
84
+ "3",
85
+ "--retry-delay",
86
+ "3",
87
+ ]
88
+ if max_size > 0:
89
+ curl_cmd.extend(["--max-filesize", str(max_size)])
90
+ if token:
91
+ url = "https://api.github.com/repos/{}/zipball/{}".format(full_name, ref)
92
+ curl_cmd.extend(
93
+ [
94
+ "-H",
95
+ "Authorization: Bearer {}".format(token),
96
+ "-H",
97
+ "Accept: application/vnd.github+json",
98
+ "-o",
99
+ file_name,
100
+ url,
101
+ ]
102
+ )
103
+ else:
104
+ url = "https://github.com/{}/archive/refs/heads/{}.zip".format(full_name, ref)
105
+ curl_cmd.extend(["-o", file_name, url])
106
+ print("Download {} : {}".format(reop["name"], url))
107
+ subprocess.run(curl_cmd, check=False)
108
+ if (
109
+ max_size > 0
110
+ and os.path.exists(file_name)
111
+ and os.stat(file_name).st_size > max_size
112
+ ):
113
+ os.remove(file_name)
114
+ print("Removed {} because it exceeds the limit size.".format(file_name))
115
+
116
+
117
+ def main(argv=None):
118
+ args = parser.parse_args(argv)
119
+ token = (args.token or "").strip() or (os.environ.get("GITHUB_TOKEN") or "").strip()
120
+ repos = search_user_repos(args.username, token)
121
+ for repo in repos:
122
+ if args.print:
123
+ print(repo["clone_url"])
124
+ elif args.download_zip:
125
+ download_zip(args.username, repo, token, args.limit_size)
126
+ else:
127
+ clone_repo(repo, token)
128
+
129
+
130
+ if __name__ == "__main__":
131
+ main()
@@ -0,0 +1,144 @@
1
+ Metadata-Version: 2.4
2
+ Name: dump-github
3
+ Version: 0.2.0
4
+ Summary: Back up users' GitHub repositories in case they need them later.
5
+ Author-email: core2002 <core2002@aliyun.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/Core2002/dump_github
8
+ Project-URL: Repository, https://github.com/Core2002/dump_github
9
+ Project-URL: Issues, https://github.com/Core2002/dump_github/issues
10
+ Project-URL: Changelog, https://github.com/Core2002/dump_github/blob/main/CHANGELOG.md
11
+ Keywords: github,backup,repositories,cli
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Software Development :: Version Control :: Git
23
+ Classifier: Topic :: System :: Archiving :: Backup
24
+ Requires-Python: >=3.10
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE
27
+ Requires-Dist: requests>=2.28
28
+ Provides-Extra: dev
29
+ Requires-Dist: build>=1.2; extra == "dev"
30
+ Requires-Dist: twine>=5; extra == "dev"
31
+ Dynamic: license-file
32
+
33
+ ### Github Dumper
34
+
35
+ [![CI](https://github.com/Core2002/dump_github/actions/workflows/ci.yml/badge.svg)](https://github.com/Core2002/dump_github/actions/workflows/ci.yml)
36
+ [![PyPI](https://img.shields.io/pypi/v/dump-github.svg)](https://pypi.org/project/dump-github/)
37
+
38
+ Github Dumper is a Python program designed to search for users' GitHub repositories and download the repositories. This tool can be used to back up users' GitHub repositories in case they need them later.
39
+
40
+ **Install (Python 3.10+):**
41
+
42
+ ```
43
+ pip install -U dump-github
44
+ ```
45
+
46
+ **Usage:**
47
+
48
+ ```
49
+ usage: dump-github [-h] [-d] [-p] [--version] [--token TOKEN]
50
+ [--limit_size LIMIT_SIZE]
51
+ username
52
+
53
+ Backup users github repo.
54
+
55
+ positional arguments:
56
+ username
57
+
58
+ options:
59
+ -h, --help show this help message and exit
60
+ -d, --download_zip only download zip file
61
+ -p, --print only print urls
62
+ --version show program's version number and exit
63
+ --token TOKEN GitHub personal access token (or set GITHUB_TOKEN).
64
+ Required for private repos and higher API rate limits.
65
+ --limit_size LIMIT_SIZE
66
+ limit size(MB) of download zip file, if 0 then no
67
+ limit(default:100).
68
+
69
+ https://github.com/Core2002/dump_github
70
+ ```
71
+
72
+ ### Authentication (token)
73
+
74
+ GitHub’s API requires a proper `Authorization: Bearer <token>` header. This tool accepts a **personal access token** in two ways (first match wins):
75
+
76
+ 1. **`--token`** on the command line
77
+ 2. **`GITHUB_TOKEN`** environment variable (if `--token` is empty)
78
+
79
+ **Why use a token?**
80
+
81
+ - **Private repositories**: Without a token, only public repos are listed and can be cloned or archived. With a token that has the right scopes, you can include private repos you are allowed to access (for example when backing up your own account).
82
+ - **Rate limits**: Authenticated API requests get a much higher limit than anonymous requests.
83
+
84
+ **How the token is used**
85
+
86
+ - **Listing repos**: sent as `Bearer` on the REST API and scoped strictly to the requested account:
87
+ - **organisation** → `GET /orgs/{org}/repos?type=all` — only repositories owned by that organisation (private ones included when the token may access them);
88
+ - **your own user account** → `GET /user/repos?affiliation=owner` — private and public repos, without organisation/collaborator repos;
89
+ - **any other user** → `GET /users/{username}/repos?type=owner`.
90
+
91
+ Repositories whose owner is not the requested account are discarded as a final guard, so a user dump never includes organisation repositories and an organisation dump never includes user repositories.
92
+ - **Clone** (default mode): the token is handed to `git` through a one-shot credential helper (`credential.helper` reads `DUMP_GITHUB_TOKEN` from the child process environment), so the clone URL stays `https://github.com/...`. The token is never shown in `ps` output and never written to the cloned repository's `.git/config`; existing credential helpers are reset for that clone so a stale stored credential cannot shadow the token.
93
+ - **Zip download** (`-d`): uses the [repository archive (zipball)](https://docs.github.com/en/rest/repos/repos#download-a-repository-archive-zip) API with the same `Bearer` header (via `curl`), which works for private repos; without a token, public archive URLs are used instead.
94
+
95
+ Create a token under GitHub → **Settings** → **Developer settings** → **Personal access tokens**. For private repo backup, enable access to **repository contents** (classic PAT: `repo` scope; fine-grained: read access to the repositories you need).
96
+
97
+ **Examples**
98
+
99
+ ```bash
100
+ # Public repos only (no token)
101
+ dump-github Core2002 -p
102
+
103
+ # Token on the command line (private + higher API limits)
104
+ dump-github username --token ghp_xxxxxxxxxxxx
105
+
106
+ # Back up an organisation (only that organisation's repositories)
107
+ dump-github some-org --token ghp_xxxxxxxxxxxx
108
+
109
+ # Same, via environment variable (recommended to avoid shell history)
110
+ export GITHUB_TOKEN=ghp_xxxxxxxxxxxx
111
+ dump-github Core2002 -d
112
+ ```
113
+
114
+ **Security note:** Do not commit tokens or paste them into shared logs. Prefer `GITHUB_TOKEN` in a local shell profile or a secret manager, and rotate the token if it leaks. Cloned repositories keep a clean remote URL (`https://github.com/...`), so `.git/config` does not contain the token.
115
+
116
+ ### Development
117
+
118
+ ```bash
119
+ python -m venv .venv
120
+ source .venv/bin/activate # Windows: .venv\Scripts\activate
121
+ python -m pip install -e ".[dev]"
122
+ python -m unittest discover -s tests -v
123
+ python -m build # dist/: sdist + wheel
124
+ python -m twine check dist/*
125
+ ```
126
+
127
+ CI runs the test suite on Python 3.10, 3.12 and 3.13, and checks the build metadata with `twine check` (`.github/workflows/ci.yml`).
128
+
129
+ ### Releasing
130
+
131
+ 1. Bump `__version__` in `dump_github/_version.py` and move the changelog entries in `CHANGELOG.md` to the new version.
132
+ 2. Commit, tag and push:
133
+ ```bash
134
+ git tag v0.2.0
135
+ git push origin main v0.2.0
136
+ ```
137
+ 3. The `Release` workflow runs the tests, builds the sdist and wheel, checks them with `twine check` and publishes both to PyPI through **Trusted Publishing**.
138
+
139
+ One-time setup on PyPI: add a trusted publisher for the `Core2002/dump_github` repository and the `release.yml` workflow. No PyPI API token is stored in the repository. Manual fallback:
140
+
141
+ ```bash
142
+ python -m build
143
+ python -m twine upload dist/*
144
+ ```
@@ -0,0 +1,10 @@
1
+ dump_github/__init__.py,sha256=7bV8yfP0ii_gvNXKfDzFhBj2V5nC82mcJrlZqs9fRZ0,92
2
+ dump_github/_version.py,sha256=Zn1KFblwuFHiDRdRAiRnDBRkbPttWh44jKa5zG2ov0E,22
3
+ dump_github/lib.py,sha256=l35zDGPRRKdMv6KzzcqJXnCmOMLrPY07wnsijcwbfCA,5485
4
+ dump_github/main.py,sha256=lYSma1C2m-7Pl5r4zwbEfeZyKqgVf2H2jFwD-98hnYg,4122
5
+ dump_github-0.2.0.dist-info/licenses/LICENSE,sha256=5tQa-lQLqvLhjTuELEk4bm70I5hcdjUeOn4qf3MK84E,1064
6
+ dump_github-0.2.0.dist-info/METADATA,sha256=vjimbmFSa9hnjYn8L58iX79KvNbL3tq104VVsIXg09I,6766
7
+ dump_github-0.2.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
8
+ dump_github-0.2.0.dist-info/entry_points.txt,sha256=2OAP2WnA1p54LWyCw3tHe44Pf4aR7Thsxf9uWKWfWl8,49
9
+ dump_github-0.2.0.dist-info/top_level.txt,sha256=6oWfdkP2U1AN9zL6AUIUTxe6hYIeo_Nf8M8SWBxElUw,12
10
+ dump_github-0.2.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (82.0.1)
2
+ Generator: setuptools (84.2.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 Core2002
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Core2002
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
@@ -1,92 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: dump_github
3
- Version: 0.1.8
4
- Summary: This tool can be used to back up users' GitHub repositories in case they need them later.
5
- Home-page: https://github.com/core2002/dump_github
6
- Author: core2002
7
- Author-email: core2002@aliyun.com
8
- License: MIT
9
- Classifier: Programming Language :: Python :: 3
10
- Classifier: License :: OSI Approved :: MIT License
11
- Classifier: Operating System :: OS Independent
12
- Description-Content-Type: text/markdown
13
- License-File: LICENSE
14
- Requires-Dist: argparse
15
- Requires-Dist: requests
16
- Dynamic: author
17
- Dynamic: author-email
18
- Dynamic: classifier
19
- Dynamic: description
20
- Dynamic: description-content-type
21
- Dynamic: home-page
22
- Dynamic: license
23
- Dynamic: license-file
24
- Dynamic: requires-dist
25
- Dynamic: summary
26
-
27
- ### Github Dumper
28
-
29
- Github Dumper is a Python program designed to search for users' GitHub repositories and download the repositories. This tool can be used to back up users' GitHub repositories in case they need them later.
30
-
31
- **Install:**
32
-
33
- ```
34
- pip install -U dump-github
35
- ```
36
-
37
- **Usage:**
38
-
39
- ```
40
- usage: dump-github [-h] [-d] [-p] [--token TOKEN] [--limit_size LIMIT_SIZE] username
41
-
42
- Backup users github repo.
43
-
44
- positional arguments:
45
- username
46
-
47
- options:
48
- -h, --help show this help message and exit
49
- -d, --download_zip only download zip file
50
- -p, --print only print urls
51
- --token TOKEN GitHub personal access token (or set GITHUB_TOKEN)
52
- --limit_size LIMIT_SIZE
53
- limit size(MB) of download zip file, if 0 then no limit(default:100).
54
-
55
- https://github.com/Core2002/dump_github
56
- ```
57
-
58
- ### Authentication (token)
59
-
60
- GitHub’s API requires a proper `Authorization: Bearer <token>` header. This tool accepts a **personal access token** in two ways (first match wins):
61
-
62
- 1. **`--token`** on the command line
63
- 2. **`GITHUB_TOKEN`** environment variable (if `--token` is empty)
64
-
65
- **Why use a token?**
66
-
67
- - **Private repositories**: Without a token, only public repos are listed and can be cloned or archived. With a token that has the right scopes, you can include private repos you are allowed to access (for example when backing up your own account).
68
- - **Rate limits**: Authenticated API requests get a much higher limit than anonymous requests.
69
-
70
- **How the token is used**
71
-
72
- - **Listing repos** (`GET /users/{username}/repos`): sent as `Bearer` on the REST API.
73
- - **Clone** (default mode): HTTPS clone URL is turned into `https://x-access-token:<token>@github.com/...` so `git clone` can access private repos.
74
- - **Zip download** (`-d`): uses the [repository archive (zipball)](https://docs.github.com/en/rest/repos/repos#download-a-repository-archive-zip) API with the same `Bearer` header (via `curl`), which works for private repos; without a token, public archive URLs are used instead.
75
-
76
- Create a token under GitHub → **Settings** → **Developer settings** → **Personal access tokens**. For private repo backup, enable access to **repository contents** (classic PAT: `repo` scope; fine-grained: read access to the repositories you need).
77
-
78
- **Examples**
79
-
80
- ```bash
81
- # Public repos only (no token)
82
- dump-github Core2002 -p
83
-
84
- # Token on the command line (private + higher API limits)
85
- dump-github username --token ghp_xxxxxxxxxxxx
86
-
87
- # Same, via environment variable (recommended to avoid shell history)
88
- export GITHUB_TOKEN=ghp_xxxxxxxxxxxx
89
- dump-github Core2002 -d
90
- ```
91
-
92
- **Security note:** Do not commit tokens or paste them into shared logs. Prefer `GITHUB_TOKEN` in a local shell profile or a secret manager, and rotate the token if it leaks.
@@ -1,9 +0,0 @@
1
- dump_github/__init__.py,sha256=5dzWctgs4c0g7raC2Kzas3wck0zHvXifUnSxy-dCPjg,44
2
- dump_github/lib.py,sha256=vEpwlJBrRr-g34spJPZmhRC9bdElngaaHCCxCQ86M1A,1843
3
- dump_github/main.py,sha256=H8QADAbNNbs_zIx5Hk6MzAFLgFfMA7bT06fqRpuyInQ,3150
4
- dump_github-0.1.8.dist-info/licenses/LICENSE,sha256=ac2hzJN6sGcBrmJXe7CkvzfaYdM5sEo8Ny1BWHML1yk,1084
5
- dump_github-0.1.8.dist-info/METADATA,sha256=h8x2qKi_OzFpSSunyfHGpSolUrKJGJJZl-YkWDzgfUY,3606
6
- dump_github-0.1.8.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
7
- dump_github-0.1.8.dist-info/entry_points.txt,sha256=2OAP2WnA1p54LWyCw3tHe44Pf4aR7Thsxf9uWKWfWl8,49
8
- dump_github-0.1.8.dist-info/top_level.txt,sha256=6oWfdkP2U1AN9zL6AUIUTxe6hYIeo_Nf8M8SWBxElUw,12
9
- dump_github-0.1.8.dist-info/RECORD,,