Skip to content

Commit 042f81f

Browse files
committed
show a nice spinning gif while the repo is being cloned
1 parent 120c5e4 commit 042f81f

File tree

6 files changed

+65
-21
lines changed

6 files changed

+65
-21
lines changed

src/avatar.v

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ fn (app App) build_avatar_file_path(avatar_filename string) string {
4040

4141
fn (app App) build_avatar_file_url(avatar_filename string) string {
4242
clean_path := app.config.avatars_path.trim_string_left('./')
43-
4443
return os.join_path('/', clean_path, avatar_filename)
4544
}
4645

@@ -55,14 +54,11 @@ fn (app App) write_user_avatar(avatar_filename string, file_content string) bool
5554
fn (app App) prepare_user_avatar_url(avatar_filename_or_url string) string {
5655
is_url := avatar_filename_or_url.starts_with('http')
5756
is_default_avatar := avatar_filename_or_url == default_avatar_name
58-
5957
if is_url {
6058
return avatar_filename_or_url
6159
}
62-
6360
if is_default_avatar {
6461
return os.join_path('/', assets_path, avatar_filename_or_url)
6562
}
66-
6763
return app.build_avatar_file_url(avatar_filename_or_url)
6864
}

src/repo.v

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ mut:
3737
lang_stats []LangStat @[skip]
3838
created_at int
3939
nr_contributors int
40-
labels []Label @[skip]
41-
status RepoStatus @[skip]
40+
labels []Label @[skip]
41+
status RepoStatus
4242
msg_cache map[string]string @[skip]
4343
}
4444

@@ -48,10 +48,10 @@ const log_field_separator = '\x7F'
4848
const ignored_folder = ['thirdparty']
4949

5050
enum RepoStatus {
51-
done
52-
caching
53-
clone_failed
54-
clone_done
51+
done = 0
52+
caching = 1
53+
clone_failed = 2
54+
cloning = 3
5555
}
5656

5757
enum ArchiveFormat {
@@ -201,6 +201,12 @@ fn (mut app App) set_repo_webhook_secret(repo_id int, secret string) ! {
201201
}!
202202
}
203203

204+
fn (mut app App) set_repo_status(repo_id int, status RepoStatus) ! {
205+
sql app.db {
206+
update Repo set status = status where id == repo_id
207+
}!
208+
}
209+
204210
fn (mut app App) increment_repo_issues(repo_id int) ! {
205211
sql app.db {
206212
update Repo set nr_open_issues = nr_open_issues + 1 where id == repo_id
@@ -210,7 +216,7 @@ fn (mut app App) increment_repo_issues(repo_id int) ! {
210216
fn (mut app App) get_count_repo() int {
211217
return sql app.db {
212218
select count from Repo
213-
} or {0}
219+
} or { 0 }
214220
}
215221

216222
fn (mut app App) add_repo(repo Repo) ! {
@@ -778,7 +784,7 @@ fn (mut app App) update_repo_primary_branch(repo_id int, branch string) ! {
778784
}
779785

780786
fn (mut r Repo) clone() {
781-
println('R CLONE')
787+
eprintln('R CLONE')
782788
if r.git_repo != unsafe { nil } {
783789
r.git_repo.clone(r.clone_url, r.git_dir)
784790
} else {
@@ -798,7 +804,8 @@ fn (mut r Repo) clone() {
798804
}
799805
*/
800806

801-
r.status = .clone_done
807+
r.status = .done
808+
eprintln('clone done')
802809
}
803810

804811
fn (r &Repo) read_file(branch string, path string) string {
@@ -844,7 +851,8 @@ fn find_readme_file(items []File) ?File {
844851

845852
fn find_license_file(items []File) ?File {
846853
// List of common license file names
847-
license_common_files := ['license', 'license.md', 'license.txt', 'licence', 'licence.md', 'licence.txt']
854+
license_common_files := ['license', 'license.md', 'license.txt', 'licence', 'licence.md',
855+
'licence.txt']
848856

849857
files := items.filter(license_common_files.contains(it.name.to_lower()))
850858

src/repo_routes.v

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,23 +201,23 @@ pub fn (mut app App) handle_new_repo(mut ctx Context, name string, clone_url str
201201
ctx.error('The repository name is too long (should be fewer than ${max_repo_name_len} characters)')
202202
return app.new(mut ctx)
203203
}
204-
println(1)
204+
eprintln(1)
205205
if _ := app.find_repo_by_name_and_username(name, ctx.user.username) {
206206
ctx.error('A repository with the name "${name}" already exists')
207207
return app.new(mut ctx)
208208
}
209-
println(2)
209+
eprintln(2)
210210
if name.contains(' ') {
211211
ctx.error('Repository name cannot contain spaces')
212212
return app.new(mut ctx)
213213
}
214-
println(3)
214+
eprintln(3)
215215
is_repo_name_valid := validation.is_repository_name_valid(name)
216216
if !is_repo_name_valid {
217217
ctx.error('The repository name is not valid')
218218
return app.new(mut ctx)
219219
}
220-
println(4)
220+
eprintln(4)
221221
has_clone_url_https_prefix := clone_url.starts_with('https://')
222222
if !is_clone_url_empty {
223223
if !has_clone_url_https_prefix {
@@ -253,7 +253,8 @@ pub fn (mut app App) handle_new_repo(mut ctx Context, name string, clone_url str
253253
app.debug('cloning')
254254
// t := time.now()
255255

256-
spawn app.foo(mut new_repo)
256+
new_repo.status = .cloning
257+
spawn app.clone_repo(mut new_repo)
257258
// new_repo.clone()
258259
// println(time.since(t))
259260
}
@@ -292,21 +293,30 @@ pub fn (mut app App) handle_new_repo(mut ctx Context, name string, clone_url str
292293
if !has_first_repo_activity {
293294
app.add_activity(ctx.user.id, 'first_repo') or { app.info(err.str()) }
294295
}
295-
return ctx.redirect('/${ctx.user.username}/repos')
296+
return ctx.redirect('/${ctx.user.username}/${new_repo.name}')
296297
}
297298

298-
pub fn (mut app App) foo(mut new_repo Repo) {
299+
pub fn (mut app App) clone_repo(mut new_repo Repo) {
299300
new_repo.clone()
300301
app.debug('cloning done')
301302
app.update_repo_from_fs(mut new_repo) or {}
303+
app.set_repo_status(new_repo.id, .done) or {}
302304
// git.clone(valid_clone_url, repo_path)
303305
}
304306

307+
pub fn (mut app App) kekw(mut ctx Context) veb.Result {
308+
return $veb.html('templates/cloning_in_process.html')
309+
}
310+
305311
@['/:username/:repo_name/tree/:branch_name/:path...']
306312
pub fn (mut app App) tree(mut ctx Context, username string, repo_name string, branch_name string, path string) veb.Result {
307313
mut repo := app.find_repo_by_name_and_username(repo_name, username) or {
308314
return ctx.not_found()
309315
}
316+
eprintln('!!! REPO STATUS = ${repo.status}')
317+
if repo.status == .cloning {
318+
return $veb.html('templates/cloning_in_process.html')
319+
}
310320

311321
_, user := app.check_username(username)
312322
if !repo.is_public {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
@include 'layout/head.html'
5+
<meta http-equiv="refresh" content="2">
6+
</head>
7+
<body>
8+
@include 'layout/header.html'
9+
10+
<div class="content">
11+
12+
13+
<div style='margin-top:25%'>
14+
<center>
15+
%repo_being_cloned_plz_wait
16+
<br>
17+
<img width=200 src='/assets/circular_progress_bar.gif'>
18+
</center>
19+
20+
</div>
21+
</div>
22+
23+
24+
@include 'layout/footer.html'
25+
</body>
26+
</html>

translations/en.tr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Register an admin account
1111
new_repository
1212
New repository
1313
-----
14+
repo_being_cloned_plz_wait
15+
Your repo is being cloned. Please wait a bit...
1416

1517

1618

translations/ru.tr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ register_admin_account
1111
new_repository
1212
Новый репозиторий
1313
-----
14+
repo_being_cloned_plz_wait
15+
Your repo is being cloned. Please wait a bit...

0 commit comments

Comments
 (0)