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

Add template linting via djlint #25212

Merged
merged 17 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from 11 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
7 changes: 7 additions & 0 deletions .github/workflows/files-changed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ on:
actions:
description: "whether actions files changed"
value: ${{ jobs.detect.outputs.actions }}
templates:
description: "whether templates files changed"
value: ${{ jobs.detect.outputs.templates }}

jobs:
detect:
Expand All @@ -27,6 +30,7 @@ jobs:
frontend: ${{ steps.changes.outputs.frontend }}
docs: ${{ steps.changes.outputs.docs }}
actions: ${{ steps.changes.outputs.actions }}
templates: ${{ steps.changes.outputs.templates }}
steps:
- uses: actions/checkout@v3
- uses: dorny/paths-filter@v2
Expand All @@ -51,3 +55,6 @@ jobs:

actions:
- ".github/workflows/*"

templates:
- "**/*.tmpl"
silverwind marked this conversation as resolved.
Show resolved Hide resolved
13 changes: 13 additions & 0 deletions .github/workflows/pull-compliance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ jobs:
env:
TAGS: bindata sqlite sqlite_unlock_notify

lint-templates:
if: needs.files-changed.outputs.templates == 'true'
needs: files-changed
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.11"
- run: pip install -U poetry
silverwind marked this conversation as resolved.
Show resolved Hide resolved
- run: make deps-py
- run: make lint-templates

lint-go-windows:
if: needs.files-changed.outputs.backend == 'true'
needs: files-changed
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ cpu.out
/tests/*.ini
/tests/**/*.git/**/*.sample
/node_modules
/.venv
/yarn.lock
/yarn-error.log
/npm-debug.log*
Expand Down
15 changes: 14 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ help:
@echo " - deps-frontend install frontend dependencies"
@echo " - deps-backend install backend dependencies"
@echo " - deps-tools install tool dependencies"
@echo " - deps-py install python dependencies"
@echo " - lint lint everything"
@echo " - lint-fix lint everything and fix issues"
@echo " - lint-actions lint action workflow files"
Expand All @@ -214,6 +215,7 @@ help:
@echo " - lint-css-fix lint css files and fix issues"
@echo " - lint-md lint markdown files"
@echo " - lint-swagger lint swagger files"
@echo " - lint-templates lint template files"
@echo " - checks run various consistency checks"
@echo " - checks-frontend check frontend files"
@echo " - checks-backend check backend files"
Expand Down Expand Up @@ -417,6 +419,10 @@ lint-editorconfig:
lint-actions:
$(GO) run $(ACTIONLINT_PACKAGE)

.PHONY: lint-templates
lint-templates: .venv
@poetry run djlint $(shell find templates -type f -iname '*.tmpl')

.PHONY: watch
watch:
@bash build/watch.sh
Expand Down Expand Up @@ -893,7 +899,10 @@ deps-docs:
fi

.PHONY: deps
deps: deps-frontend deps-backend deps-tools deps-docs
deps: deps-frontend deps-backend deps-tools deps-docs deps-py

.PHONY: deps-py
deps-py: .venv

.PHONY: deps-frontend
deps-frontend: node_modules
Expand All @@ -920,6 +929,10 @@ node_modules: package-lock.json
npm install --no-save
@touch node_modules

.venv: poetry.lock
poetry install
@touch .venv

.PHONY: npm-update
npm-update: node-check | node_modules
npx updates -cu
Expand Down
3 changes: 3 additions & 0 deletions docs/content/doc/development/hacking-on-gitea.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ Gitea uses `gofmt` to format source code. However, the results of
recommended to install the version of Go that our continuous integration is
running. As of last update, the Go version should be {{< go-version >}}.

To lint the template files, ensure [Python](https://www.python.org/) and
[Poetry](https://python-poetry.org/) are installed.

## Installing Make

Gitea makes heavy use of Make to automate tasks and improve development. This
Expand Down
331 changes: 331 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions poetry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[virtualenvs]
in-project = true
no-pip = true
no-setuptools = true
19 changes: 19 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[tool.poetry]
name = "gitea"
version = "0.0.0"
description = ""
authors = []

[tool.poetry.dependencies]
python = "^3.8"

[tool.poetry.group.dev.dependencies]
djlint = "1.31.0"

[tool.djlint]
profile="golang"
ignore="H005,H006,H008,H013,H014,H016,H020,H021,H023,H026,H030,H031,T027"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
30 changes: 15 additions & 15 deletions templates/admin/auth/edit.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
</div>
<div class="required field">
<label for="host">{{.locale.Tr "admin.auths.host"}}</label>
<input id="host" name="host" value="{{$cfg.Host}}" placeholder="e.g. mydomain.com" required>
<input id="host" name="host" value="{{$cfg.Host}}" placeholder="mydomain.com" required>
</div>
<div class="required field">
<label for="port">{{.locale.Tr "admin.auths.port"}}</label>
<input id="port" name="port" value="{{$cfg.Port}}" placeholder="e.g. 636" required>
<input id="port" name="port" value="{{$cfg.Port}}" placeholder="636" required>
</div>
<div class="has-tls inline field {{if not .HasTLS}}gt-hidden{{end}}">
<div class="ui checkbox">
Expand All @@ -51,7 +51,7 @@
{{if .Source.IsLDAP}}
<div class="field">
<label for="bind_dn">{{.locale.Tr "admin.auths.bind_dn"}}</label>
<input id="bind_dn" name="bind_dn" value="{{$cfg.BindDN}}" placeholder="e.g. cn=Search,dc=mydomain,dc=com">
<input id="bind_dn" name="bind_dn" value="{{$cfg.BindDN}}" placeholder="cn=Search,dc=mydomain,dc=com">
</div>
<div class="field">
<label for="bind_password">{{.locale.Tr "admin.auths.bind_password"}}</label>
Expand All @@ -60,17 +60,17 @@
{{end}}
<div class="{{if .Source.IsLDAP}}required{{end}} field">
<label for="user_base">{{.locale.Tr "admin.auths.user_base"}}</label>
<input id="user_base" name="user_base" value="{{$cfg.UserBase}}" placeholder="e.g. ou=Users,dc=mydomain,dc=com" {{if .Source.IsLDAP}}required{{end}}>
<input id="user_base" name="user_base" value="{{$cfg.UserBase}}" placeholder="ou=Users,dc=mydomain,dc=com" {{if .Source.IsLDAP}}required{{end}}>
</div>
{{if .Source.IsDLDAP}}
<div class="required field">
<label for="user_dn">{{.locale.Tr "admin.auths.user_dn"}}</label>
<input id="user_dn" name="user_dn" value="{{$cfg.UserDN}}" placeholder="e.g. uid=%s,ou=Users,dc=mydomain,dc=com" required>
<input id="user_dn" name="user_dn" value="{{$cfg.UserDN}}" placeholder="uid=%s,ou=Users,dc=mydomain,dc=com" required>
</div>
{{end}}
<div class="required field">
<label for="filter">{{.locale.Tr "admin.auths.filter"}}</label>
<input id="filter" name="filter" value="{{$cfg.Filter}}" placeholder="e.g. (&(objectClass=posixAccount)(|(uid=%[1]s)(mail=%[1]s)))" required>
<input id="filter" name="filter" value="{{$cfg.Filter}}" placeholder="(&(objectClass=posixAccount)(|(uid=%[1]s)(mail=%[1]s)))" required>
</div>
<div class="field">
<label for="admin_filter">{{.locale.Tr "admin.auths.admin_filter"}}</label>
Expand All @@ -95,15 +95,15 @@
</div>
<div class="required field">
<label for="attribute_mail">{{.locale.Tr "admin.auths.attribute_mail"}}</label>
<input id="attribute_mail" name="attribute_mail" value="{{$cfg.AttributeMail}}" placeholder="e.g. mail" required>
<input id="attribute_mail" name="attribute_mail" value="{{$cfg.AttributeMail}}" placeholder="mail" required>
</div>
<div class="field">
<label for="attribute_ssh_public_key">{{.locale.Tr "admin.auths.attribute_ssh_public_key"}}</label>
<input id="attribute_ssh_public_key" name="attribute_ssh_public_key" value="{{$cfg.AttributeSSHPublicKey}}" placeholder="e.g. SshPublicKey">
<input id="attribute_ssh_public_key" name="attribute_ssh_public_key" value="{{$cfg.AttributeSSHPublicKey}}" placeholder="SshPublicKey">
</div>
<div class="field">
<label for="attribute_avatar">{{.locale.Tr "admin.auths.attribute_avatar"}}</label>
<input id="attribute_avatar" name="attribute_avatar" value="{{$cfg.AttributeAvatar}}" placeholder="e.g. jpegPhoto">
<input id="attribute_avatar" name="attribute_avatar" value="{{$cfg.AttributeAvatar}}" placeholder="jpegPhoto">
</div>


Expand All @@ -117,23 +117,23 @@
<div id="ldap-group-options" class="ui segment secondary {{if not $cfg.GroupsEnabled}}gt-hidden{{end}}">
<div class="field">
<label>{{.locale.Tr "admin.auths.group_search_base"}}</label>
<input name="group_dn" value="{{$cfg.GroupDN}}" placeholder="e.g. ou=group,dc=mydomain,dc=com">
<input name="group_dn" value="{{$cfg.GroupDN}}" placeholder="ou=group,dc=mydomain,dc=com">
</div>
<div class="field">
<label>{{.locale.Tr "admin.auths.group_attribute_list_users"}}</label>
<input name="group_member_uid" value="{{$cfg.GroupMemberUID}}" placeholder="e.g. memberUid">
<input name="group_member_uid" value="{{$cfg.GroupMemberUID}}" placeholder="memberUid">
</div>
<div class="field">
<label>{{.locale.Tr "admin.auths.user_attribute_in_group"}}</label>
<input name="user_uid" value="{{$cfg.UserUID}}" placeholder="e.g. uid">
<input name="user_uid" value="{{$cfg.UserUID}}" placeholder="uid">
</div>
<div class="field">
<label>{{.locale.Tr "admin.auths.verify_group_membership"}}</label>
<input name="group_filter" value="{{$cfg.GroupFilter}}" placeholder="e.g. (|(cn=gitea_users)(cn=admins))">
<input name="group_filter" value="{{$cfg.GroupFilter}}" placeholder="(|(cn=gitea_users)(cn=admins))">
</div>
<div class="field">
<label>{{.locale.Tr "admin.auths.map_group_to_team"}}</label>
<textarea name="group_team_map" rows="5" placeholder='e.g. {"cn=my-group,cn=groups,dc=example,dc=org": {"MyGiteaOrganization": ["MyGiteaTeam1", "MyGiteaTeam2"]}}'>{{$cfg.GroupTeamMap}}</textarea>
<textarea name="group_team_map" rows="5" placeholder='{"cn=my-group,cn=groups,dc=example,dc=org": {"MyGiteaOrganization": ["MyGiteaTeam1", "MyGiteaTeam2"]}}'>{{$cfg.GroupTeamMap}}</textarea>
</div>
<div class="ui checkbox">
<label>{{.locale.Tr "admin.auths.map_group_to_team_removal"}}</label>
Expand Down Expand Up @@ -360,7 +360,7 @@
</div>
<div class="field">
<label>{{.locale.Tr "admin.auths.oauth2_map_group_to_team"}}</label>
<textarea name="oauth2_group_team_map" rows="5" placeholder='e.g. {"Developer": {"MyGiteaOrganization": ["MyGiteaTeam1", "MyGiteaTeam2"]}}'>{{$cfg.GroupTeamMap}}</textarea>
<textarea name="oauth2_group_team_map" rows="5" placeholder='{"Developer": {"MyGiteaOrganization": ["MyGiteaTeam1", "MyGiteaTeam2"]}}'>{{$cfg.GroupTeamMap}}</textarea>
</div>
<div class="ui checkbox">
<label>{{.locale.Tr "admin.auths.oauth2_map_group_to_team_removal"}}</label>
Expand Down
28 changes: 14 additions & 14 deletions templates/admin/auth/source/ldap.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
</div>
<div class="required field">
<label for="host">{{.locale.Tr "admin.auths.host"}}</label>
<input id="host" name="host" value="{{.host}}" placeholder="e.g. mydomain.com">
<input id="host" name="host" value="{{.host}}" placeholder="mydomain.com">
</div>
<div class="required field">
<label for="port">{{.locale.Tr "admin.auths.port"}}</label>
<input id="port" name="port" value="{{.port}}" placeholder="e.g. 636">
<input id="port" name="port" value="{{.port}}" placeholder="636">
</div>
<div class="has-tls inline field {{if not .HasTLS}}gt-hidden{{end}}">
<div class="ui checkbox">
Expand All @@ -28,23 +28,23 @@
</div>
<div class="ldap field {{if not (eq .type 2)}}gt-hidden{{end}}">
<label for="bind_dn">{{.locale.Tr "admin.auths.bind_dn"}}</label>
<input id="bind_dn" name="bind_dn" value="{{.bind_dn}}" placeholder="e.g. cn=Search,dc=mydomain,dc=com">
<input id="bind_dn" name="bind_dn" value="{{.bind_dn}}" placeholder="cn=Search,dc=mydomain,dc=com">
</div>
<div class="ldap field {{if not (eq .type 2)}}gt-hidden{{end}}">
<label for="bind_password">{{.locale.Tr "admin.auths.bind_password"}}</label>
<input id="bind_password" name="bind_password" type="password" autocomplete="off" value="{{.bind_password}}">
</div>
<div class="binddnrequired {{if (eq .type 2)}}required{{end}} field">
<label for="user_base">{{.locale.Tr "admin.auths.user_base"}}</label>
<input id="user_base" name="user_base" value="{{.user_base}}" placeholder="e.g. ou=Users,dc=mydomain,dc=com">
<input id="user_base" name="user_base" value="{{.user_base}}" placeholder="ou=Users,dc=mydomain,dc=com">
</div>
<div class="dldap required field {{if not (eq .type 5)}}gt-hidden{{end}}">
<label for="user_dn">{{.locale.Tr "admin.auths.user_dn"}}</label>
<input id="user_dn" name="user_dn" value="{{.user_dn}}" placeholder="e.g. uid=%s,ou=Users,dc=mydomain,dc=com">
<input id="user_dn" name="user_dn" value="{{.user_dn}}" placeholder="uid=%s,ou=Users,dc=mydomain,dc=com">
</div>
<div class="required field">
<label for="filter">{{.locale.Tr "admin.auths.filter"}}</label>
<input id="filter" name="filter" value="{{.filter}}" placeholder="e.g. (&(objectClass=posixAccount)(|(uid=%[1]s)(mail=%[1]s)))">
<input id="filter" name="filter" value="{{.filter}}" placeholder="(&(objectClass=posixAccount)(|(uid=%[1]s)(mail=%[1]s)))">
</div>
<div class="field">
<label for="admin_filter">{{.locale.Tr "admin.auths.admin_filter"}}</label>
Expand All @@ -69,15 +69,15 @@
</div>
<div class="required field">
<label for="attribute_mail">{{.locale.Tr "admin.auths.attribute_mail"}}</label>
<input id="attribute_mail" name="attribute_mail" value="{{.attribute_mail}}" placeholder="e.g. mail">
<input id="attribute_mail" name="attribute_mail" value="{{.attribute_mail}}" placeholder="mail">
</div>
<div class="field">
<label for="attribute_ssh_public_key">{{.locale.Tr "admin.auths.attribute_ssh_public_key"}}</label>
<input id="attribute_ssh_public_key" name="attribute_ssh_public_key" value="{{.attribute_ssh_public_key}}" placeholder="e.g. SshPublicKey">
<input id="attribute_ssh_public_key" name="attribute_ssh_public_key" value="{{.attribute_ssh_public_key}}" placeholder="SshPublicKey">
</div>
<div class="field">
<label for="attribute_avatar">{{.locale.Tr "admin.auths.attribute_avatar"}}</label>
<input id="attribute_avatar" name="attribute_avatar" value="{{.attribute_avatar}}" placeholder="e.g. jpegPhoto">
<input id="attribute_avatar" name="attribute_avatar" value="{{.attribute_avatar}}" placeholder="jpegPhoto">
</div>

<!-- ldap group begin -->
Expand All @@ -90,23 +90,23 @@
<div id="ldap-group-options" class="ui segment secondary">
<div class="field">
<label>{{.locale.Tr "admin.auths.group_search_base"}}</label>
<input name="group_dn" value="{{.group_dn}}" placeholder="e.g. ou=group,dc=mydomain,dc=com">
<input name="group_dn" value="{{.group_dn}}" placeholder="ou=group,dc=mydomain,dc=com">
</div>
<div class="field">
<label>{{.locale.Tr "admin.auths.group_attribute_list_users"}}</label>
<input name="group_member_uid" value="{{.group_member_uid}}" placeholder="e.g. memberUid">
<input name="group_member_uid" value="{{.group_member_uid}}" placeholder="memberUid">
</div>
<div class="field">
<label>{{.locale.Tr "admin.auths.user_attribute_in_group"}}</label>
<input name="user_uid" value="{{.user_uid}}" placeholder="e.g. uid">
<input name="user_uid" value="{{.user_uid}}" placeholder="uid">
</div>
<div class="field">
<label>{{.locale.Tr "admin.auths.verify_group_membership"}}</label>
<input name="group_filter" value="{{.group_filter}}" placeholder="e.g. (|(cn=gitea_users)(cn=admins))">
<input name="group_filter" value="{{.group_filter}}" placeholder="(|(cn=gitea_users)(cn=admins))">
</div>
<div class="field">
<label>{{.locale.Tr "admin.auths.map_group_to_team"}}</label>
<textarea name="group_team_map" rows="5" placeholder='e.g. {"cn=my-group,cn=groups,dc=example,dc=org": {"MyGiteaOrganization": ["MyGiteaTeam1", "MyGiteaTeam2"]}}'>{{.group_team_map}}</textarea>
<textarea name="group_team_map" rows="5" placeholder='{"cn=my-group,cn=groups,dc=example,dc=org": {"MyGiteaOrganization": ["MyGiteaTeam1", "MyGiteaTeam2"]}}'>{{.group_team_map}}</textarea>
</div>
<div class="ui checkbox">
<label>{{.locale.Tr "admin.auths.map_group_to_team_removal"}}</label>
Expand Down
2 changes: 1 addition & 1 deletion templates/admin/auth/source/oauth.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
</div>
<div class="field">
<label>{{.locale.Tr "admin.auths.oauth2_map_group_to_team"}}</label>
<textarea name="oauth2_group_team_map" rows="5" placeholder='e.g. {"Developer": {"MyGiteaOrganization": ["MyGiteaTeam1", "MyGiteaTeam2"]}}'>{{.oauth2_group_team_map}}</textarea>
<textarea name="oauth2_group_team_map" rows="5" placeholder='{"Developer": {"MyGiteaOrganization": ["MyGiteaTeam1", "MyGiteaTeam2"]}}'>{{.oauth2_group_team_map}}</textarea>
</div>
<div class="ui checkbox">
<label>{{.locale.Tr "admin.auths.oauth2_map_group_to_team_removal"}}</label>
Expand Down
2 changes: 1 addition & 1 deletion templates/admin/queue.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<td>{{$q.GetItemTypeName}}</td>
<td>{{$sum := $q.GetWorkerNumber}}{{if lt $sum 0}}-{{else}}{{$sum}}{{end}}</td>
<td>{{$sum = $q.GetQueueItemNumber}}{{if lt $sum 0}}-{{else}}{{$sum}}{{end}}</td>
<td><a href="{{$.Link}}/{{$qid}}" class="button">{{if lt $sum 0}}{{$.locale.Tr "admin.monitor.queue.review"}}{{else}}{{$.locale.Tr "admin.monitor.queue.review_add"}}{{end}}</a>
<td><a href="{{$.Link}}/{{$qid}}" class="button">{{if lt $sum 0}}{{$.locale.Tr "admin.monitor.queue.review"}}{{else}}{{$.locale.Tr "admin.monitor.queue.review_add"}}{{end}}</a></td>
</tr>
{{end}}
</tbody>
Expand Down
2 changes: 1 addition & 1 deletion templates/admin/queue_manage.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</h4>
<div class="ui attached segment">
<p>{{.locale.Tr "admin.monitor.queue.settings.desc"}}</p>
<form method="POST" action="{{.Link}}/set">
<form method="post" action="{{.Link}}/set">
{{$.CsrfTokenHtml}}
<div class="ui form">
<div class="inline field">
Expand Down
4 changes: 2 additions & 2 deletions templates/admin/repo/unadopted.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<div class="content">
<p>{{$.locale.Tr "repo.adopt_preexisting_content" $dir}}</p>
</div>
<form class="ui form" method="POST" action="{{AppSubUrl}}/admin/repos/unadopted">
<form class="ui form" method="post" action="{{AppSubUrl}}/admin/repos/unadopted">
{{$.CsrfTokenHtml}}
<input type="hidden" name="id" value="{{$dir}}">
<input type="hidden" name="action" value="adopt">
Expand All @@ -48,7 +48,7 @@
<div class="content">
<p>{{$.locale.Tr "repo.delete_preexisting_content" $dir}}</p>
</div>
<form class="ui form" method="POST" action="{{AppSubUrl}}/admin/repos/unadopted">
<form class="ui form" method="post" action="{{AppSubUrl}}/admin/repos/unadopted">
{{$.CsrfTokenHtml}}
<input type="hidden" name="id" value="{{$dir}}">
<input type="hidden" name="action" value="delete">
Expand Down
4 changes: 2 additions & 2 deletions templates/admin/user/edit.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
</div>
<div class="field {{if .Err_Website}}error{{end}}">
<label for="website">{{.locale.Tr "settings.website"}}</label>
<input id="website" name="website" type="url" value="{{.User.Website}}" placeholder="e.g. http://mydomain.com or https://mydomain.com" maxlength="255">
<input id="website" name="website" type="url" value="{{.User.Website}}" placeholder="http://mydomain.com or https://mydomain.com" maxlength="255">
</div>
<div class="field {{if .Err_Location}}error{{end}}">
<label for="location">{{.locale.Tr "settings.location"}}</label>
Expand Down Expand Up @@ -197,7 +197,7 @@
{{svg "octicon-trash"}}
{{.locale.Tr "settings.delete_account_title"}}
</div>
<form class="ui form" method="POST" action="{{.Link}}/delete">
<form class="ui form" method="post" action="{{.Link}}/delete">
<div class="content">
<p>{{.locale.Tr "settings.delete_account_desc"}}</p>
{{$.CsrfTokenHtml}}
Expand Down
Loading