Skip to content

Commit f958d24

Browse files
committed
pr diff file tree; pay button only on gitly.org
1 parent fca4242 commit f958d24

6 files changed

Lines changed: 381 additions & 40 deletions

File tree

‎pr_routes.v‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,64 @@ struct PrReviewCommentWithUser {
3838
user User
3939
}
4040

41+
struct PrFileTreeRow {
42+
path string
43+
name string
44+
depth int
45+
indent_px int
46+
is_dir bool
47+
is_new bool
48+
is_deleted bool
49+
is_renamed bool
50+
additions int
51+
deletions int
52+
}
53+
54+
fn build_pr_file_tree_rows(file_diffs []FileDiff) []PrFileTreeRow {
55+
mut sorted := file_diffs.clone()
56+
sorted.sort(a.path < b.path)
57+
mut rows := []PrFileTreeRow{}
58+
mut seen_dirs := map[string]bool{}
59+
for fd in sorted {
60+
parts := fd.path.split('/')
61+
if parts.len == 0 {
62+
continue
63+
}
64+
mut current_path := ''
65+
if parts.len > 1 {
66+
for idx := 0; idx < parts.len - 1; idx++ {
67+
part := parts[idx]
68+
if part == '' {
69+
continue
70+
}
71+
current_path = if current_path == '' { part } else { '${current_path}/${part}' }
72+
if current_path !in seen_dirs {
73+
seen_dirs[current_path] = true
74+
rows << PrFileTreeRow{
75+
path: current_path
76+
name: part
77+
depth: idx
78+
indent_px: 10 + idx * 16
79+
is_dir: true
80+
}
81+
}
82+
}
83+
}
84+
rows << PrFileTreeRow{
85+
path: fd.path
86+
name: parts[parts.len - 1]
87+
depth: parts.len - 1
88+
indent_px: 10 + (parts.len - 1) * 16
89+
is_new: fd.is_new
90+
is_deleted: fd.is_deleted
91+
is_renamed: fd.is_renamed
92+
additions: fd.additions
93+
deletions: fd.deletions
94+
}
95+
}
96+
return rows
97+
}
98+
4199
// GET /:username/:repo_name/pulls
42100
@['/:username/:repo_name/pulls']
43101
pub fn (mut app App) handle_get_repo_pulls(mut ctx Context, username string, repo_name string) veb.Result {
@@ -231,6 +289,7 @@ pub fn (mut app App) pull_request_files(mut ctx Context, username string, repo_n
231289
all_adds += fd.additions
232290
all_dels += fd.deletions
233291
}
292+
file_tree := build_pr_file_tree_rows(file_diffs)
234293
rcomments := app.get_pr_review_comments(pr.id)
235294
mut comments_by_key := map[string][]PrReviewCommentWithUser{}
236295
for rc in rcomments {

‎repo/repo_routes.v‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,10 @@ pub fn (mut app App) handle_new_repo(mut ctx Context, name string, clone_url str
319319
if !is_clone_url_empty {
320320
app.debug('cloning')
321321
clone_job_repo := *new_repo
322+
enforce_clone_size_limit := should_enforce_clone_size_limit(ctx.is_admin(),
323+
clone_size_limit_flag_enabled())
322324
spawn clone_repo(clone_job_repo, app.config, import_issues, import_prs, ctx.user.id,
323-
!ctx.is_admin())
325+
enforce_clone_size_limit)
324326
}
325327
new_repo2 := app.find_repo_by_name_and_username(new_repo.name, owner_name) or {
326328
app.info('Repo was not inserted')
@@ -377,6 +379,14 @@ fn bg_fetch_files_info(repo_ Repo, branch string, path string, conf config.Confi
377379
app.db.close() or {}
378380
}
379381

382+
fn clone_size_limit_flag_enabled() bool {
383+
return os.exists('gitly_not_self_hosted')
384+
}
385+
386+
fn should_enforce_clone_size_limit(is_admin bool, not_self_hosted bool) bool {
387+
return not_self_hosted && !is_admin
388+
}
389+
380390
fn clone_repo(new_repo Repo, conf config.Config, import_issues bool, import_prs bool, owner_user_id int, enforce_clone_size_limit bool) {
381391
mut cloned_repo := new_repo
382392
cloned_repo.clone(enforce_clone_size_limit)

‎static/assets/version‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
80b7125
1+
fca4242

‎static/css/gitly.scss‎

Lines changed: 137 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2295,50 +2295,163 @@ form {
22952295

22962296
.pr-files-sidebar__list {
22972297
display: block;
2298-
max-height: calc(100vh - 116px);
2298+
max-height: calc(100vh - 170px);
22992299
overflow: auto;
23002300
}
23012301

2302-
.pr-file-link {
2302+
.pr-files-filter {
23032303
display: grid;
2304-
grid-template-columns: 22px minmax(0, 1fr) auto;
2304+
grid-template-columns: 18px minmax(0, 1fr) 28px;
23052305
align-items: center;
23062306
gap: 8px;
2307-
padding: 7px 10px;
2307+
padding: 10px;
2308+
border-bottom: 1px solid #d8dee4;
2309+
background-color: $white;
2310+
}
2311+
2312+
.pr-files-filter__icon {
2313+
color: #57606a;
2314+
2315+
svg {
2316+
display: block;
2317+
width: 16px;
2318+
height: 16px;
2319+
}
2320+
}
2321+
2322+
.pr-files-filter__input {
2323+
width: 100%;
2324+
min-width: 0;
2325+
box-sizing: border-box;
2326+
padding: 5px 8px;
2327+
font-size: 13px;
2328+
background-color: $white;
2329+
}
2330+
2331+
.pr-files-filter__clear {
2332+
display: inline-flex;
2333+
align-items: center;
2334+
justify-content: center;
2335+
width: 28px !important;
2336+
height: 28px;
2337+
padding: 0;
2338+
color: #57606a;
2339+
background-color: $white;
2340+
border-color: #d8dee4;
2341+
2342+
svg {
2343+
width: 14px;
2344+
height: 14px;
2345+
}
2346+
2347+
&:hover {
2348+
color: $black;
2349+
background-color: #f6f8fa;
2350+
border-color: #d8dee4;
2351+
}
2352+
2353+
&[hidden] {
2354+
display: none;
2355+
}
2356+
}
2357+
2358+
.pr-file-tree-row {
2359+
display: grid;
2360+
grid-template-columns: 16px 18px minmax(0, 1fr) auto auto;
2361+
align-items: center;
2362+
gap: 7px;
2363+
width: 100% !important;
2364+
box-sizing: border-box;
2365+
padding: 6px 10px;
23082366
border-top: 1px solid #eef1f4;
2367+
border-right: 0;
2368+
border-bottom: 0;
2369+
border-left: 0;
2370+
border-radius: 0;
2371+
background-color: $white;
23092372
color: $black !important;
2373+
cursor: pointer;
23102374
font-size: 12px;
2375+
text-align: left;
2376+
font-family: inherit;
23112377

23122378
&:first-child {
23132379
border-top: none;
23142380
}
23152381

23162382
&:hover {
23172383
background-color: #f6f8fa;
2384+
border-color: #eef1f4;
23182385
text-decoration: none;
2386+
color: $black !important;
23192387
}
23202388
}
23212389

2322-
.pr-file-link__status {
2390+
.pr-file-tree-row--dir {
2391+
grid-template-columns: 16px 18px minmax(0, 1fr);
2392+
font-weight: 600;
2393+
}
2394+
2395+
.pr-file-tree-row__chevron,
2396+
.pr-file-tree-row__spacer,
2397+
.pr-file-tree-row__folder,
2398+
.pr-file-tree-row__file {
23232399
display: inline-flex;
23242400
align-items: center;
23252401
justify-content: center;
2326-
width: 20px;
2327-
height: 20px;
2328-
border-radius: 50%;
2329-
background-color: #eef3f8;
2402+
width: 16px;
2403+
height: 16px;
23302404
color: #57606a;
2331-
font-size: 10px;
2332-
font-weight: 700;
2333-
line-height: 1;
23342405
}
23352406

2336-
.pr-file-link__path {
2407+
.pr-file-tree-row__chevron svg {
2408+
width: 14px;
2409+
height: 14px;
2410+
transition: transform 0.08s;
2411+
}
2412+
2413+
.pr-file-tree-row--dir[aria-expanded="true"] .pr-file-tree-row__chevron svg {
2414+
transform: rotate(90deg);
2415+
}
2416+
2417+
.pr-file-tree-row__folder {
2418+
color: #54aeff;
2419+
2420+
svg {
2421+
width: 16px;
2422+
height: 16px;
2423+
}
2424+
}
2425+
2426+
.pr-file-tree-row__file {
2427+
color: #57606a;
2428+
2429+
svg {
2430+
width: 15px;
2431+
height: 15px;
2432+
}
2433+
}
2434+
2435+
.pr-file-tree-row__name {
23372436
min-width: 0;
23382437
overflow: hidden;
23392438
text-overflow: ellipsis;
23402439
white-space: nowrap;
2341-
font-family: SFMono-Regular, Menlo, Monaco, Consolas, monospace;
2440+
line-height: 1.35;
2441+
}
2442+
2443+
.pr-file-link__status {
2444+
display: inline-flex;
2445+
align-items: center;
2446+
justify-content: center;
2447+
width: 18px;
2448+
height: 18px;
2449+
border-radius: 50%;
2450+
background-color: #eef3f8;
2451+
color: #57606a;
2452+
font-size: 10px;
2453+
font-weight: 700;
2454+
line-height: 1;
23422455
}
23432456

23442457
.pr-file-link__counts {
@@ -2349,6 +2462,13 @@ form {
23492462
font-weight: 600;
23502463
}
23512464

2465+
.pr-files-filter-empty {
2466+
padding: 12px;
2467+
border-top: 1px solid #eef1f4;
2468+
color: #57606a;
2469+
font-size: 13px;
2470+
}
2471+
23522472
.pr-files-diffs {
23532473
min-width: 0;
23542474
}
@@ -2617,12 +2737,12 @@ form {
26172737
flex-direction: column;
26182738
}
26192739

2620-
.pr-file-link {
2621-
grid-template-columns: 22px minmax(0, 1fr);
2740+
.pr-file-tree-row--file {
2741+
grid-template-columns: 16px 18px minmax(0, 1fr) 18px;
26222742
}
26232743

26242744
.pr-file-link__counts {
2625-
grid-column: 2;
2745+
grid-column: 3 / -1;
26262746
}
26272747
}
26282748

0 commit comments

Comments
 (0)