Skip to content

Commit 481487d

Browse files
authored
Merge pull request #995 from appwrite/ci-max-lines
ci: add 1200 line max
2 parents 5b53236 + 2d2c932 commit 481487d

File tree

3 files changed

+105
-6
lines changed

3 files changed

+105
-6
lines changed

.github/scripts/max-line-length.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
3+
# Check if all required arguments are provided
4+
if [ "$#" -ne 3 ]; then
5+
echo "Usage: $0 <folder_path> <max_line_length> <file_globs>"
6+
exit 1
7+
fi
8+
9+
folder_path="$1"
10+
max_length="$2"
11+
file_globs="$3"
12+
13+
# Function to get relative path
14+
get_relative_path() {
15+
local path="$1"
16+
local base="$(pwd)"
17+
echo "${path#$base/}"
18+
}
19+
20+
# Initialize a flag to check if any lines exceed the max length
21+
found_lines=0
22+
23+
# Convert comma-separated globs to an array
24+
IFS=',' read -ra glob_array <<< "$file_globs"
25+
26+
# Use find to get all files matching the glob patterns
27+
for glob in "${glob_array[@]}"; do
28+
while IFS= read -r -d '' file; do
29+
# Get the relative path
30+
relative_path=$(get_relative_path "$file")
31+
32+
# Use awk to process each file
33+
awk -v max="$max_length" -v file="$relative_path" '
34+
length($0) > max {
35+
print file ":" NR
36+
found = 1
37+
exit 1
38+
}
39+
END {
40+
exit found
41+
}' "$file"
42+
43+
# Check awk's exit status
44+
if [ $? -eq 1 ]; then
45+
found_lines=1
46+
fi
47+
done < <(find "$folder_path" -type f -name "$glob" -print0)
48+
done
49+
50+
# Exit with appropriate code
51+
if [ $found_lines -eq 0 ]; then
52+
echo "All lines are within the $max_length character limit."
53+
exit 0
54+
else
55+
echo "Some lines exceedded the $max_length character limit."
56+
exit 1
57+
fi

.github/workflows/tests.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,16 @@ jobs:
101101

102102
- name: Lint
103103
run: composer lint
104+
105+
max-line-length:
106+
runs-on: ubuntu-latest
107+
108+
steps:
109+
- name: Checkout code
110+
uses: actions/checkout@v4
111+
112+
- name: Make script executable
113+
run: chmod +x ./.github/scripts/max-line-length.sh
114+
115+
- name: Check max lines
116+
run: ./.github/scripts/max-line-length.sh . 1200 "*.twig"

templates/dotnet/Package/Models/Model.cs.twig

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,43 @@ namespace {{ spec.title | caseUcfirst }}.Models
3838
{%~ endif %}
3939
}
4040

41-
public static {{ definition.name | caseUcfirst | overrideIdentifier}} From(Dictionary<string, object> map) => new {{ definition.name | caseUcfirst | overrideIdentifier}}(
41+
public static {{ definition.name | caseUcfirst | overrideIdentifier }} From(Dictionary<string, object> map) => new {{ definition.name | caseUcfirst | overrideIdentifier }}(
4242
{%~ for property in definition.properties %}
43-
{{ property.name | caseCamel | escapeKeyword | removeDollarSign }}: {% if property.sub_schema %}{% if property.type == 'array' %}((JArray)map["{{ property.name }}"]).ToObject<List<Dictionary<string, object>>>().Select(it => {{property.sub_schema | caseUcfirst | overrideIdentifier}}.From(map: it)).ToList(){% else %}{{property.sub_schema | caseUcfirst | overrideIdentifier}}.From(map: ((JObject)map["{{ property.name }}"]).ToObject<Dictionary<string, object>>()!){% endif %}{% else %}{% if property.type == 'array' %}((JArray)map["{{ property.name }}"]).ToObject<{{ property | typeName }}>(){% else %}{% if property.type == "integer" or property.type == "number" %}{% if not property.required %}map["{{ property.name }}"] == null ? null : {% endif %}Convert.To{% if property.type == "integer" %}Int64{% else %}Double{% endif %}(map["{{ property.name }}"]){% else %}{% if property.type == "boolean" %}({{ property | typeName }}{% if not property.required %}?{% endif %})map["{{ property.name }}"]{% else %}map{% if not property.required %}.TryGetValue("{{ property.name }}", out var {{ property.name | caseCamel | escapeKeyword | removeDollarSign }}) ? {{ property.name | caseCamel | escapeKeyword | removeDollarSign }}?.ToString() : null{% else %}["{{ property.name }}"]{% if not property.required %}?{% endif %}.ToString(){% endif %}{% endif %}{% endif %}{% endif %}{% endif %}{% if not loop.last or (loop.last and definition.additionalProperties) %},{% endif %}
44-
43+
{{ property.name | caseCamel | escapeKeyword | removeDollarSign }}:
44+
{%- if property.sub_schema %}
45+
{%~ if property.type == 'array' %}
46+
((JArray)map["{{ property.name }}"])
47+
.ToObject<List<Dictionary<string, object>>>()
48+
.Select(it => {{ property.sub_schema | caseUcfirst | overrideIdentifier }}.From(map: it))
49+
.ToList()
50+
{%- else %}
51+
{{ property.sub_schema | caseUcfirst | overrideIdentifier }}.From(
52+
map: ((JObject)map["{{ property.name }}"])
53+
.ToObject<Dictionary<string, object>>()!
54+
)
55+
{%- endif %}
56+
{%~ else %}
57+
{%~ if property.type == 'array' %}
58+
((JArray)map["{{ property.name }}"]).ToObject<{{ property | typeName }}>()
59+
{%~ else %}
60+
{%~ if property.type == "integer" or property.type == "number" %}
61+
{%~ if not property.required %}map["{{ property.name }}"] == null ? null : {% endif %} Convert.To{% if property.type == "integer" %}Int64{% else %}Double{% endif %}(map["{{ property.name }}"])
62+
{%~ else %}
63+
{%~ if property.type == "boolean" %}
64+
({{ property | typeName }}{% if not property.required %}?{% endif %})map["{{ property.name }}"]
65+
{%~ else %}
66+
{%~ if not property.required %}map.TryGetValue("{{ property.name }}", out var {{ property.name | caseCamel | escapeKeyword | removeDollarSign }}) ? {{ property.name | caseCamel | escapeKeyword | removeDollarSign }}?.ToString() : null
67+
{%~ else %} map["{{ property.name }}"].ToString(){% endif %}
68+
{%- endif %}
69+
{%~ endif %}
70+
{%~ endif %}
71+
{%~ endif %}
72+
{%- if not loop.last or (loop.last and definition.additionalProperties) %},
73+
{%~ endif %}
4574
{%~ endfor %}
46-
{%~ if definition.additionalProperties %}
47-
data: map
48-
{%~ endif %}
75+
{%- if definition.additionalProperties %}
76+
, data: map
77+
{%- endif ~%}
4978
);
5079

5180
public Dictionary<string, object?> ToMap() => new Dictionary<string, object?>()

0 commit comments

Comments
 (0)