Skip to content

Commit 24942e8

Browse files
committed
adding v2 python code.
1 parent b1e829d commit 24942e8

22 files changed

+2685
-3
lines changed

.circleci/config.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ jobs:
33
build:
44
# The primary container is an instance of the first image listed. The job's commands run in this container.
55
docker:
6-
- image: circleci/node:12.3.1
6+
- image: circleci/python:3.7.0-node
77
steps:
88
- checkout
99
- run:
@@ -26,7 +26,7 @@ jobs:
2626
command: npm ls || true
2727
test:
2828
docker:
29-
- image: circleci/node:12.3.1
29+
- image: circleci/python:3.7.0-node
3030
steps:
3131
- checkout
3232
- restore_cache:
@@ -45,7 +45,7 @@ jobs:
4545
# prefix: coverage
4646
deploy:
4747
docker:
48-
- image: circleci/node:12.3.1
48+
- image: circleci/python:3.7.0-node
4949
steps:
5050
- checkout
5151
- run:

.gitignore

+151
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
/lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
pip-wheel-metadata/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.nox/
44+
.coverage
45+
.coverage.*
46+
.cache
47+
nosetests.xml
48+
coverage.xml
49+
*.cover
50+
*.py,cover
51+
.hypothesis/
52+
.pytest_cache/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
target/
76+
77+
# Jupyter Notebook
78+
.ipynb_checkpoints
79+
80+
# IPython
81+
profile_default/
82+
ipython_config.py
83+
84+
# pyenv
85+
.python-version
86+
87+
# pipenv
88+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
90+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
91+
# install all needed dependencies.
92+
#Pipfile.lock
93+
94+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
95+
__pypackages__/
96+
97+
# Celery stuff
98+
celerybeat-schedule
99+
celerybeat.pid
100+
101+
# SageMath parsed files
102+
*.sage.py
103+
104+
# Environments
105+
.env
106+
.venv
107+
env/
108+
venv/
109+
ENV/
110+
env.bak/
111+
venv.bak/
112+
113+
# Spyder project settings
114+
.spyderproject
115+
.spyproject
116+
117+
# Rope project settings
118+
.ropeproject
119+
120+
# mkdocs documentation
121+
/site
122+
123+
# mypy
124+
.mypy_cache/
125+
.dmypy.json
126+
dmypy.json
127+
128+
# Pyre type checker
129+
.pyre/
130+
131+
132+
# Distribution / packaging
133+
.Python
134+
env/
135+
build/
136+
develop-eggs/
137+
dist/
138+
downloads/
139+
eggs/
140+
.eggs/
141+
/lib/
142+
lib64/
143+
parts/
144+
sdist/
145+
var/
146+
*.egg-info/
147+
.installed.cfg
148+
*.egg
149+
150+
# Serverless directories
151+
.serverless

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Jason Kulatunga
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+
SOFTWARE.

Pipfile

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[[source]]
2+
name = "pypi"
3+
url = "https://pypi.org/simple"
4+
verify_ssl = true
5+
6+
[dev-packages]
7+
8+
[packages]
9+
dulwich = "*"
10+
pygithub = "*"
11+
12+
[requires]
13+
python_version = "3.7"

Pipfile.lock

+101
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+35
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,41 @@
88

99

1010

11+
12+
# Contributing
13+
14+
15+
```
16+
pipenv install packge_name
17+
pipenv run pip freeze > requirements.txt
18+
19+
sls requirements install
20+
PYTHONPATH=/Users/jason/Library/Caches/serverless-python-requirements/2674a9f8121c5816727ff9f31e4684c72875956b15f0bbb0eb0d69838d6ad47b_slspyc sls offline start
21+
22+
23+
```
24+
25+
# Applying test packfile
26+
```
27+
GIT_TRACE=1 GIT_TRACE_PACKFILE=/Users/jason/repos/gitmask/packfile.txt GIT_TRACE_CURL=2 GIT_CURL_VERBOSE=2 git push test beta2
28+
29+
30+
cd /tmp/tmp7ci900n2
31+
git unpack-objects -r < /Users/jason/repos/gitmask/packfile.txt
32+
33+
```
34+
35+
36+
# References
37+
38+
- https://janakiev.com/blog/python-shell-commands/
39+
- https://mincong.io/2018/05/04/git-and-http/
40+
- https://github.com/qhzhyt/http-git-server
41+
42+
43+
44+
45+
1146
# Goals for V2
1247

1348
- ability to use gitmask as a remote, rather than requiring bundles to use it.

gitmask/git-info-refs.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from dulwich.protocol import Protocol
2+
from gitmask.lib.scm.github_backend import GithubBackend
3+
from gitmask.lib.gitmask_receive_pack_handler import GitmaskReceivePackHandler
4+
import io
5+
6+
def handler(event, context):
7+
print(event)
8+
owner = event['pathParameters']['org']
9+
reponame = event['pathParameters']['repo'].replace('.git', '')
10+
11+
# from receive_pack(path=".", inf=None, outf=None): https://github.com/dulwich/dulwich/blob/master/dulwich/porcelain.py#L1137
12+
repo_fullpath = "{0}/{1}".format(owner, reponame)
13+
14+
inf = io.BytesIO()
15+
outf = io.BytesIO()
16+
17+
backend = GithubBackend()
18+
19+
def send_fn(data):
20+
outf.write(data)
21+
# outf.flush()
22+
23+
proto = Protocol(inf.read, send_fn)
24+
handler = GitmaskReceivePackHandler(backend, [repo_fullpath], proto)
25+
handler.handle_info_refs()
26+
27+
# send receive pack handler response to client
28+
29+
response = {
30+
"statusCode": 200,
31+
"headers": {'Content-Type': "application/x-{0}-advertisement".format(event['queryStringParameters']['service'])},
32+
"body": outf.getvalue().decode("utf-8")
33+
}
34+
35+
return response

0 commit comments

Comments
 (0)