Arcadia822 commited on
Commit
1f8e463
·
0 Parent(s):

init commit

Browse files
.gitattributes ADDED
@@ -0,0 +1 @@
 
 
1
+ * text=auto eol=lf
.github/workflows/sync_huggingface.yml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Sync to Hugging Face hub
2
+ on:
3
+ push:
4
+ branches: [master]
5
+
6
+ # to run this workflow manually from the Actions tab
7
+ workflow_dispatch:
8
+
9
+ jobs:
10
+ sync-to-hub:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v3
14
+ with:
15
+ fetch-depth: 0
16
+ lfs: true
17
+ - name: Checkout main
18
+ run: git checkout -b main
19
+ - name: Push to hub
20
+ env:
21
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
22
+ REPO_ID: codedog-ai/codedog-demo
23
+ run: git push https://HF_USERNAME:$HF_TOKEN@huggingface.co/spaces/$REPO_ID main
.gitignore ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # .vscode files
31
+ .vscode/
32
+ # Pycharm
33
+ .idea/
34
+
35
+ # PyInstaller
36
+ # Usually these files are written by a python script from a template
37
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
38
+ *.manifest
39
+ *.spec
40
+
41
+ # Installer logs
42
+ pip-log.txt
43
+ pip-delete-this-directory.txt
44
+
45
+ # Unit test / coverage rerts
46
+ htmlcov/
47
+ .tox/
48
+ .nox/
49
+ .coverage
50
+ .coverage.*
51
+ .cache
52
+ nosetests.xml
53
+ coverage.xml
54
+ *.cover
55
+ *.py,cover
56
+ .hypothesis/
57
+ .pytest_cache/
58
+
59
+ # Translations
60
+ *.mo
61
+ *.pot
62
+
63
+ # Django stuff:
64
+ *.log
65
+ local_settings.py
66
+ db.sqlite3
67
+ db.sqlite3-journal
68
+
69
+ # Flask stuff:
70
+ instance/
71
+ .webassets-cache
72
+
73
+ # Scrapy stuff:
74
+ .scrapy
75
+
76
+ # Sphinx documentation
77
+ docs/_build/
78
+
79
+ # PyBuilder
80
+ target/
81
+
82
+ # Jupyter Notebook
83
+ .ipynb_checkpoints
84
+
85
+ # IPython
86
+ profile_default/
87
+ ipython_config.py
88
+
89
+ # pyenv
90
+ .python-version
91
+
92
+ # pipenv
93
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
94
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
95
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
96
+ # install all needed dependencies.
97
+ #Pipfile.lock
98
+
99
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow
100
+ __pypackages__/
101
+
102
+ # Celery stuff
103
+ celerybeat-schedule
104
+ celerybeat.pid
105
+
106
+ # SageMath parsed files
107
+ *.sage.py
108
+
109
+ # Environments
110
+ .env
111
+ .env.bat
112
+ .venv
113
+ env/
114
+ venv/
115
+ ENV/
116
+ env.bak/
117
+ venv.bak/
118
+ myvenv/
119
+ tmp/
120
+ *.pem
121
+
122
+ # Spyder project settings
123
+ .spyderproject
124
+ .spyproject
125
+
126
+ # Rope project settings
127
+ .ropeproject
128
+
129
+ # mkdocs documentation
130
+ /site
131
+
132
+ # mypy
133
+ .mypy_cache/
134
+ .dmypy.json
135
+ dmypy.json
136
+
137
+ # Pyre type checker
138
+ .pyre/
139
+
140
+ # macOS .DS_Store files
141
+ .DS_Store
142
+
143
+ .python_packages
README.md ADDED
@@ -0,0 +1 @@
 
 
1
+ # Codedog Demo
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ from codedog_demo.callbacks import get_sample_choices, request_pr_review, show_sample
4
+
5
+ sample_choices = get_sample_choices()
6
+
7
+
8
+ with gr.Blocks(theme="xiaobaiyuan/theme_brief") as demo:
9
+ gr.Markdown("# Codedog Demo")
10
+
11
+ with gr.Tab(label="Try Yourself"):
12
+ custom_pr_url = gr.Textbox(max_lines=1, placeholder="Paste Github PR URL here", show_label=False)
13
+ custom_submit = gr.Button(value="Review It")
14
+ custom_content = gr.Markdown(value="")
15
+
16
+ custom_submit.click(request_pr_review, inputs=[custom_pr_url], outputs=[custom_content])
17
+
18
+ with gr.Tab(label="Samples"):
19
+ sample_choice = gr.Radio(choices=sample_choices, type="index", show_label=False)
20
+ sample_content = gr.Markdown(value="")
21
+
22
+ sample_choice.input(show_sample, inputs=[sample_choice], outputs=[sample_content])
23
+
24
+
25
+ if __name__ == "__main__":
26
+ demo.launch()
codedog_demo/__init__.py ADDED
File without changes
codedog_demo/callbacks.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from os import environ as env
2
+ from os import listdir
3
+ from typing import List
4
+
5
+ import requests
6
+
7
+ from codedog_demo.github_utils import parse_github_pr_url
8
+
9
+ codedog_api = env.get("CODEDOG_API_URL", "")
10
+ installation = int(env.get("INSTALLATION_ID", 0))
11
+
12
+
13
+ sample_names = []
14
+ sample_contents = []
15
+ for file in listdir("samples"):
16
+ sample_names.append(file.replace("@", "/"))
17
+ with open("samples/" + file, "r") as f:
18
+ sample_contents.append(f.read())
19
+
20
+
21
+ def request_pr_review(url: str):
22
+ repo, pr_number = parse_github_pr_url(url)
23
+ if not repo or not pr_number:
24
+ return "Invalid URL. Accept format is: https://www.github.com/{owner}/{repository}/pull/{pr_number}"
25
+
26
+ response = requests.post(
27
+ codedog_api, json={"repository": repo, "pull_request_number": pr_number, "installation_id": installation}
28
+ )
29
+ result = response.text
30
+ return result
31
+
32
+
33
+ def get_sample_choices() -> List[str]:
34
+ return sample_names
35
+
36
+
37
+ def show_sample(idx: int) -> str:
38
+ return sample_contents[idx]
codedog_demo/github_utils.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Tuple
2
+
3
+
4
+ def parse_github_pr_url(url: str) -> Tuple[str, int]:
5
+ # Input = https://github.com/codedog-ai/codedog/pull/11
6
+ # Output = codedog-ai/codedog, 11
7
+ if not url:
8
+ return ("", 0)
9
+
10
+ try:
11
+ parts = url.split("/")
12
+ owner_repo = parts[3] + "/" + parts[4]
13
+ pr_number = int(parts[-1])
14
+ except Exception:
15
+ return ("", 0)
16
+
17
+ return (owner_repo, pr_number)
config.toml ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [server]
2
+ runOnSave = true
poetry.lock ADDED
The diff for this file is too large to render. See raw diff
 
poetry.toml ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [virtualenvs]
2
+ in-project = true
pyproject.toml ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [tool.poetry]
2
+ name = "codedog-demo"
3
+ version = "0.1.0"
4
+ description = "Demo pull request review ability"
5
+ authors = ["arcadia822 <arcadia822@gmail.com>"]
6
+ license = "MIT"
7
+ readme = "README.md"
8
+ packages = [{ include = "codedog_demo" }]
9
+
10
+ [tool.poetry.dependencies]
11
+ python = "^3.10"
12
+ gradio = "^3.39.0"
13
+
14
+
15
+ [build-system]
16
+ requires = ["poetry-core"]
17
+ build-backend = "poetry.core.masonry.api"
samples/codedog-ai@codedog #2 ADDED
@@ -0,0 +1 @@
 
 
1
+ # Sample