Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using FTD #36

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ local_settings.py
db.sqlite3
db.sqlite3-journal
media
.DS_Store
*.packages
*.build

# If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/
# in your Git repository. Update and uncomment the following line accordingly.
Expand Down
1 change: 1 addition & 0 deletions app/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def sync_repositories_for_installation(
installation_instance.installation_id,
installation_instance.creator.get_active_access_token(),
)
print("sync_repositories_for_installation:::", github_manager)
github_manager.sync_repositories()


Expand Down
2 changes: 2 additions & 0 deletions app/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def __init__(self, installation_id: int, user_token: str):

def sync_repositories(self):
repo_generator = self.github_manager_instance.get_repositories()
print("sync_repositories::::", repo_generator)
for repo in repo_generator:
print("repo:::", repo)
app_models.GithubRepository.objects.get_or_create(
repo_id=repo["id"],
repo_name=repo["name"],
Expand Down
126 changes: 124 additions & 2 deletions app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def post(self, request, *args, **kwargs):
if not is_verified:
return HttpResponse("Invalid signature", status=403)
logger.info(
"Recieved Github webhook",
"Received Github webhook",
extra={"data": {"headers": headers, "payload": payload}},
)
EVENT_TYPE = headers.get("X-Github-Event", None)
Expand Down Expand Up @@ -353,6 +353,11 @@ def get(self, request):

@method_decorator(login_required, name="dispatch")
class AllPRView(TemplateView):
# if settings.USING_FTD:
# template_name = '/'
# else:
# template_name = "all_pr_for_org.html"

template_name = "all_pr_for_org.html"

@log_http_event(
Expand All @@ -370,9 +375,62 @@ def get(self, request, *args: Any, **kwargs: Any):
github_user=github_user,
installation=context["repo_mapping"].integration,
)
context.pop('repo_mapping')
return self.render_to_response(context)

def get_context_data(self, **kwargs: Any) -> Dict[str, Any]:
def queryset_to_value(data):
import django
from datetime import date, datetime
print("get_context_data:", isinstance(data, django.db.models.query.QuerySet), isinstance(data, (datetime, date)), type(data))
if settings.USING_FTD and isinstance(data, django.db.models.query.QuerySet):
value = list(data.values())
for idx, val in enumerate(value):
print("isinstance(val, Dict):::", isinstance(val, Dict))
if not isinstance(val, Dict):
continue
for k, v in val.items():
value[idx][k] = queryset_to_value(v)
return value
elif settings.USING_FTD and isinstance(data, (datetime, date)):
return data.isoformat()
else:
return data

def ftd_context(context):
# for key, value in context.items():
# print("key:", key)
# context[key] = queryset_to_value(value)
new_context = {
"owner_account_name": context["repo_mapping"].code_repo.owner.account_name,
"code_repo_full_name": context["repo_mapping"].code_repo.repo_full_name,
"documentation_repo_full_name": context["repo_mapping"].documentation_repo.repo_full_name,
"open_prs": [],
}
for open_pr in context["open_prs"]:
code_pull_request = {
"pr_number": open_pr.code_pull_request.pr_number,
"pr_title": open_pr.code_pull_request.pr_title
}
documentation_pull_request = {
"pr_number": open_pr.documentation_pull_request.pr_number,
"pr_title": open_pr.documentation_pull_request.pr_title
} if open_pr.documentation_pull_request else None
approver_info = {
"approver": open_pr.get_latest_approval().approver.github_user.account_name if open_pr.get_latest_approval().approver else None,
"created_on": open_pr.get_latest_approval().created_on
} if open_pr.get_latest_approval() else None
open_pr_data = {
"pull_request_status": open_pr.pull_request_status,
"code_pull_request": code_pull_request,
"documentation_pull_request": documentation_pull_request,
"pull_request_status_display": open_pr.get_pull_request_status_display(),
"approver_info": approver_info
}
new_context["open_prs"].append(open_pr_data)

return new_context

context = super().get_context_data(**kwargs)
matches = self.request.resolver_match.kwargs
context["all_installations"] = app_models.GithubAppInstallation.objects.filter(
Expand Down Expand Up @@ -410,6 +468,15 @@ def get_context_data(self, **kwargs: Any) -> Dict[str, Any]:
context["all_documentation_prs"] = app_models.GithubPullRequest.objects.filter(
repository=context["repo_mapping"].documentation_repo, pr_state="open"
)

# if settings.USING_FTD:
# new_context = ftd_context(context)
# new_context["repo_mapping"] = context["repo_mapping"]
# new_context["view"] = context["view"]
# context = new_context

print("context::::",context)

return context


Expand Down Expand Up @@ -531,7 +598,12 @@ def post(self, request, *args, **kwargs):


class AppIndexPage(TemplateView):
template_name = "index.html"
if not settings.USING_FTD:
template_name = "index.html"
else:
template_name = "/"

# template_name = "index.html"

def get_okind_ekind(view, request, *args, **kwargs):
if request.method == "GET":
Expand Down Expand Up @@ -571,6 +643,50 @@ def get(self, request, *args, **kwargs) -> HttpResponse:
return super().get(request, *args, **kwargs)

def get_context_data(self, **kwargs: Any) -> Dict[str, Any]:

def ftd_context(context):
new_context = {
"github-login-url": context.get("github_login_url"),
"is-authenticated": self.request.user.is_authenticated,
"all-repo-map": [],
"unmapped-repos-display": [],
"available-repos-for-mapping": []
}

for repo_map in (context.get("all_repo_map") or []):
code_repo = {
"get-url": repo_map.code_repo.get_url(),
"repo-full-name": repo_map.code_repo.repo_full_name
} if repo_map.code_repo else None

documentation_repo = {
"get-url": repo_map.documentation_repo.get_url(),
"repo-full-name": repo_map.documentation_repo.repo_full_name
} if repo_map.documentation_repo else None

new_context["all-repo-map"].append({
"code-repo": code_repo,
"documentation-repo": documentation_repo
})

for repo in (context.get("unmapped_repos_display") or []):
new_context["unmapped-repos-display"].append({
"get-url": repo.get_url(),
"repo-full-name": repo.repo_full_name,
"id": repo.id,
})

for repo in (context.get("available_repos_for_mapping") or []):
new_context["available-repos-for-mapping"].append({
"get-url": repo.get_url(),
"repo-full-name": repo.repo_full_name,
"id": repo.id,
})
new_context["view"] = context["view"]

return new_context


context = super().get_context_data(**kwargs)
if self.request.user.is_authenticated:
all_installations = app_models.GithubAppInstallation.objects.filter(
Expand Down Expand Up @@ -618,6 +734,12 @@ def get_context_data(self, **kwargs: Any) -> Dict[str, Any]:
req.prepare_url(url, params)
context["github_login_url"] = req.url


if settings.USING_FTD:
context = ftd_context(context)

# print("context::::", context)

return context


Expand Down
11 changes: 7 additions & 4 deletions cdoc/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"localhost",
"0.0.0.0",
"fifthtry-cdoc.herokuapp.com",
"a51f-14-141-47-2.in.ngrok.io",
DEPLOYMENT_HOST_NAME,
]

Expand Down Expand Up @@ -85,10 +86,10 @@
],
},
},
# {
# "BACKEND": "ftd_django.TemplateBackend",
# "DIRS": ["cdoc-doc"],
# },
{
"BACKEND": "ftd_django.TemplateBackend",
"DIRS": ["templates_ftd"],
},
]

WSGI_APPLICATION = "cdoc.wsgi.application"
Expand Down Expand Up @@ -247,6 +248,8 @@
"NAME": BASE_DIR / "db.sqlite3",
}

USING_FTD = False

try:
from .local_settings import * # noqa
except ModuleNotFoundError:
Expand Down
6 changes: 5 additions & 1 deletion cdoc/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@
),
path("ftd/", app_views.IndexView.as_view()),
]
# + ftd_django.static()



if settings.USING_FTD:
urlpatterns += ftd_django.static()


def make_v(template, context):
Expand Down
1 change: 1 addition & 0 deletions lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def _get_repository_page(self, page: int, per_page: Optional[int] = None):
f"https://api.github.com/user/installations/{self.installation_id}/repositories?per_page={per_page}&page={page}",
headers=headers,
)
print("_get_repository_page response::", response.text)
if response.ok:
response_data = response.json()
logger.info(response.content.decode())
Expand Down
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ whitenoise
sentry-sdk
rq
django-rq
ftd-django==0.1.1
ftd-django==0.1.3
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ django-extensions==3.1.5
# via -r requirements.in
django-rq==2.5.1
# via -r requirements.in
ftd==0.1.2
ftd==0.1.3
# via ftd-django
ftd-django==0.1.1
ftd-django==0.1.3
# via -r requirements.in
ftd-sys==0.1.0
ftd-sys==0.1.1
# via ftd
gunicorn==20.1.0
# via -r requirements.in
Expand Down
12 changes: 12 additions & 0 deletions templates_ftd/FPM.ftd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- import: fpm

-- fpm.package: templates-ftd

-- fpm.auto-import: templates-ftd/assets

-- fpm.dependency: fifthtry.github.io/inter
-- fpm.font: Octicon
display: swap
style: normal
weight: normal
woff: -/fifthtry.github.io/octicon/static/octicons.woff
3 changes: 3 additions & 0 deletions templates_ftd/assets/images/Icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added templates_ftd/assets/images/Union.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added templates_ftd/assets/images/Vector.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added templates_ftd/assets/images/back-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added templates_ftd/assets/images/fifthtry-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions templates_ftd/assets/images/icon-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added templates_ftd/assets/images/icon-github.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions templates_ftd/assets/images/icon-github.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added templates_ftd/assets/images/icon-language.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added templates_ftd/assets/images/icon-moon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added templates_ftd/assets/images/icon9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading