From 3561cc710b8704534d7265634a292ea83fcb1be1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9ana=20=E6=B1=9F?= Date: Mon, 20 May 2024 18:47:35 +0000 Subject: [PATCH] [I18N] Injected updated time in translation string (#3837) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hello, It is more idiomatic to put the date/time before the action in Mandarin (in this context). To achieve this, instead of having the time following the string that's passed to the translating function, I added it as a parameter so that one can reference it and reorder the sentence for better translatability. Only Traditional Chinese has been changed at the time of opening this PR, as this is more of a proof of concept and I would like to have feedbacks on whether this is a good solution or is there a better alternative. Thank you and have a nice day :) Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/3837 Reviewed-by: Earl Warren Reviewed-by: 0ko <0ko@noreply.codeberg.org> Co-authored-by: Léana 江 Co-committed-by: Léana 江 --- options/locale/locale_ar.ini | 2 +- options/locale/locale_bg.ini | 2 +- options/locale/locale_cs-CZ.ini | 2 +- options/locale/locale_de-DE.ini | 2 +- options/locale/locale_el-GR.ini | 2 +- options/locale/locale_en-US.ini | 2 +- options/locale/locale_es-ES.ini | 2 +- options/locale/locale_fa-IR.ini | 2 +- options/locale/locale_fi-FI.ini | 2 +- options/locale/locale_fil.ini | 2 +- options/locale/locale_fr-FR.ini | 2 +- options/locale/locale_hu-HU.ini | 2 +- options/locale/locale_id-ID.ini | 2 +- options/locale/locale_is-IS.ini | 2 +- options/locale/locale_it-IT.ini | 2 +- options/locale/locale_ja-JP.ini | 2 +- options/locale/locale_ko-KR.ini | 2 +- options/locale/locale_lv-LV.ini | 2 +- options/locale/locale_nl-NL.ini | 2 +- options/locale/locale_pl-PL.ini | 2 +- options/locale/locale_pt-BR.ini | 2 +- options/locale/locale_pt-PT.ini | 2 +- options/locale/locale_ru-RU.ini | 2 +- options/locale/locale_si-LK.ini | 2 +- options/locale/locale_sv-SE.ini | 2 +- options/locale/locale_tr-TR.ini | 2 +- options/locale/locale_uk-UA.ini | 2 +- options/locale/locale_zh-CN.ini | 2 +- options/locale/locale_zh-HK.ini | 2 +- options/locale/locale_zh-TW.ini | 2 +- templates/explore/repo_list.tmpl | 2 +- templates/repo/branch/list.tmpl | 4 +- tests/integration/last_updated_time_test.go | 71 +++++++++++++++++++++ 33 files changed, 104 insertions(+), 33 deletions(-) create mode 100644 tests/integration/last_updated_time_test.go diff --git a/options/locale/locale_ar.ini b/options/locale/locale_ar.ini index 04372ceeae..3b6d78e545 100644 --- a/options/locale/locale_ar.ini +++ b/options/locale/locale_ar.ini @@ -503,7 +503,7 @@ settings.delete_org_desc = هذه المنظمة ستحذف إلى الأبد، create_org = أنشئ منظمة teams.add_all_repos_desc = سيضيف هذا كل مستودعات المنظمة إلى الفريق. settings.labels_desc = أضف التصنيفات القابلة للاستخدام في المسائل التابعة لكل مستودعات هذه المنظمة. -repo_updated = حُدِّث +repo_updated = حُدِّث %s org_desc = الوصف org_name_helper = ينبغي أن تكون أسماء المنظمات قصيرة وسهلة التذكر. team_permission_desc = الأذونات diff --git a/options/locale/locale_bg.ini b/options/locale/locale_bg.ini index d34a33e18c..dd6058d183 100644 --- a/options/locale/locale_bg.ini +++ b/options/locale/locale_bg.ini @@ -1210,7 +1210,7 @@ settings.delete_prompt = Организацията ще бъде премахн settings.labels_desc = Добавете етикети, които могат да се използват за задачи за всички хранилища в тази организация. teams.none_access = Без достъп teams.members.none = Няма членове в този екип. -repo_updated = Обновено +repo_updated = Обновено %s teams.delete_team_success = Екипът е изтрит. teams.search_repo_placeholder = Потърсете хранилище… teams.delete_team_title = Изтриване на екипа diff --git a/options/locale/locale_cs-CZ.ini b/options/locale/locale_cs-CZ.ini index c83bdfbb35..100d02fb12 100644 --- a/options/locale/locale_cs-CZ.ini +++ b/options/locale/locale_cs-CZ.ini @@ -2772,7 +2772,7 @@ org_name_holder=Název organizace org_full_name_holder=Celý název organizace org_name_helper=Jména organizací by měla být krátká a zapamatovatelná. create_org=Vytvořit organizaci -repo_updated=Upraveno +repo_updated=Upraveno %s members=Členové teams=Týmy code=Kód diff --git a/options/locale/locale_de-DE.ini b/options/locale/locale_de-DE.ini index 52e353874f..d8a80311ee 100644 --- a/options/locale/locale_de-DE.ini +++ b/options/locale/locale_de-DE.ini @@ -2749,7 +2749,7 @@ org_name_holder=Name der Organisation org_full_name_holder=Vollständiger Name der Organisation org_name_helper=Organisationsnamen sollten kurz und einprägsam sein. create_org=Organisation erstellen -repo_updated=Aktualisiert +repo_updated=Aktualisiert %s members=Mitglieder teams=Teams code=Quelltext diff --git a/options/locale/locale_el-GR.ini b/options/locale/locale_el-GR.ini index 3c4e0108ea..b5024e49f0 100644 --- a/options/locale/locale_el-GR.ini +++ b/options/locale/locale_el-GR.ini @@ -2737,7 +2737,7 @@ org_name_holder=Όνομα οργανισμού org_full_name_holder=Πλήρες όνομα οργανισμού org_name_helper=Τα ονόματα οργανισμών θα πρέπει να είναι σύντομα και εύκολα στην απομνημόνευση. create_org=Δημιουργία οργανισμού -repo_updated=Ενημερώθηκε +repo_updated=Ενημερώθηκε %s members=Μέλη teams=Ομάδες code=Κώδικας diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index e55eb73c42..f9df8ac46c 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -2732,7 +2732,7 @@ org_full_name_holder = Organization full name org_name_helper = Organization names should be short and memorable. create_org = Create organization open_dashboard = Open dashboard -repo_updated = Updated +repo_updated = Updated %s members = Members teams = Teams code = Code diff --git a/options/locale/locale_es-ES.ini b/options/locale/locale_es-ES.ini index bda807c87a..849b845323 100644 --- a/options/locale/locale_es-ES.ini +++ b/options/locale/locale_es-ES.ini @@ -2623,7 +2623,7 @@ org_name_holder=Nombre de la organización org_full_name_holder=Nombre completo de la organización org_name_helper=Los nombres de organización deben ser cortos y destacados. create_org=Crear Organización -repo_updated=Actualizado +repo_updated=Actualizado %s members=Miembros teams=Equipos code=Código diff --git a/options/locale/locale_fa-IR.ini b/options/locale/locale_fa-IR.ini index 8ab6f7cca1..7ab52fb241 100644 --- a/options/locale/locale_fa-IR.ini +++ b/options/locale/locale_fa-IR.ini @@ -1981,7 +1981,7 @@ org_name_holder=نام سازمان org_full_name_holder=نام کامل سازمان org_name_helper=نام سازمان باید کوتاه و قابل حفظ کردن باشد. create_org=ایجاد سازمان -repo_updated=به روز رسانی شده +repo_updated=به روز رسانی شده %s members=اعضاء teams=تیم‌ها lower_members=اعضا diff --git a/options/locale/locale_fi-FI.ini b/options/locale/locale_fi-FI.ini index 8f47918874..c0a8abcf20 100644 --- a/options/locale/locale_fi-FI.ini +++ b/options/locale/locale_fi-FI.ini @@ -1352,7 +1352,7 @@ org_name_holder=Organisaatio org_full_name_holder=Organisaation täydellinen nimi org_name_helper=Organisaation nimen tulisi olla lyhyt ja mieleenpainuva. create_org=Luo organisaatio -repo_updated=Päivitetty +repo_updated=Päivitetty %s members=Jäsenet teams=Tiimit lower_members=jäsenet diff --git a/options/locale/locale_fil.ini b/options/locale/locale_fil.ini index eec28738fa..0df2569d14 100644 --- a/options/locale/locale_fil.ini +++ b/options/locale/locale_fil.ini @@ -1827,7 +1827,7 @@ config.ssh_keygen_path = Path ng keygen ("ssh-keygen") config.ssh_key_test_path = Path ng key test [org] -repo_updated = Binago +repo_updated = Binago %s team_access_desc = Access ng repositoryo team_permission_desc = Pahintulot org_desc = Deskripsyon diff --git a/options/locale/locale_fr-FR.ini b/options/locale/locale_fr-FR.ini index 5d53ddc93f..d00caafb7f 100644 --- a/options/locale/locale_fr-FR.ini +++ b/options/locale/locale_fr-FR.ini @@ -2769,7 +2769,7 @@ org_name_holder=Nom de l'organisation org_full_name_holder=Nom complet de l'organisation org_name_helper=Le nom de l'organisation doit être court et mémorable. create_org=Créer une organisation -repo_updated=Actualisé +repo_updated=Actualisé %s members=Membres teams=Équipes code=Code diff --git a/options/locale/locale_hu-HU.ini b/options/locale/locale_hu-HU.ini index e1fa369c7c..c3c32987f6 100644 --- a/options/locale/locale_hu-HU.ini +++ b/options/locale/locale_hu-HU.ini @@ -1179,7 +1179,7 @@ org_name_holder=Szervezet neve org_full_name_holder=Szervezet teljes neve org_name_helper=A szervezetek nevének rövidnek és megjegyezhetőnek kell lennie. create_org=Szervezet létrehozása -repo_updated=Frissítve +repo_updated=Frissítve %s members=Tagok teams=Csoportok lower_members=tagok diff --git a/options/locale/locale_id-ID.ini b/options/locale/locale_id-ID.ini index 5370a404f0..d85cb78abb 100644 --- a/options/locale/locale_id-ID.ini +++ b/options/locale/locale_id-ID.ini @@ -963,7 +963,7 @@ branch.deleted_by=Dihapus oleh %s org_name_holder=Nama Organisasi org_full_name_holder=Organisasi Nama Lengkap create_org=Buat Organisasi -repo_updated=Diperbarui +repo_updated=Diperbarui %s members=Anggota teams=Tim lower_members=anggota diff --git a/options/locale/locale_is-IS.ini b/options/locale/locale_is-IS.ini index 4d947b3b93..8195e61c42 100644 --- a/options/locale/locale_is-IS.ini +++ b/options/locale/locale_is-IS.ini @@ -1120,7 +1120,7 @@ topic.done=Í lagi [graphs] [org] -repo_updated=Uppfært +repo_updated=Uppfært %s members=Meðlimar teams=Lið lower_members=meðlimar diff --git a/options/locale/locale_it-IT.ini b/options/locale/locale_it-IT.ini index 6a7f3bfa76..36cee3696a 100644 --- a/options/locale/locale_it-IT.ini +++ b/options/locale/locale_it-IT.ini @@ -2748,7 +2748,7 @@ org_name_holder=Nome dell'organizzazione org_full_name_holder=Nome completo dell'organizzazione org_name_helper=I nomi delle organizzazioni devono essere brevi e semplici da ricordare. create_org=Crea organizzazione -repo_updated=Aggiornato +repo_updated=Aggiornato %s members=Membri teams=Team lower_members=membri diff --git a/options/locale/locale_ja-JP.ini b/options/locale/locale_ja-JP.ini index be76f3fb45..f4e1bcd663 100644 --- a/options/locale/locale_ja-JP.ini +++ b/options/locale/locale_ja-JP.ini @@ -2745,7 +2745,7 @@ org_name_holder=組織名 org_full_name_holder=組織のフルネーム org_name_helper=組織名は短く覚えやすいものにしましょう。 create_org=組織を作成 -repo_updated=最終更新 +repo_updated=最終更新 %s members=メンバー teams=チーム code=コード diff --git a/options/locale/locale_ko-KR.ini b/options/locale/locale_ko-KR.ini index 3848656325..f8a9a17ba7 100644 --- a/options/locale/locale_ko-KR.ini +++ b/options/locale/locale_ko-KR.ini @@ -1283,7 +1283,7 @@ pulls.blocked_by_official_review_requests = 이 풀 리퀘스트는 공식 검 org_name_holder=조직 이름 org_full_name_holder=조직 전체 이름 create_org=새로운 조직 -repo_updated=업데이트됨 +repo_updated=업데이트됨 %s members=멤버 teams=팀 lower_members=회원 diff --git a/options/locale/locale_lv-LV.ini b/options/locale/locale_lv-LV.ini index d42ef8638e..fa9a5d0063 100644 --- a/options/locale/locale_lv-LV.ini +++ b/options/locale/locale_lv-LV.ini @@ -2581,7 +2581,7 @@ org_name_holder=Organizācijas nosaukums org_full_name_holder=Organizācijas pilnais nosaukums org_name_helper=Organizāciju nosaukumiem vēlams būt īsiem un tādiem, ko viegli atcerēties. create_org=Izveidot organizāciju -repo_updated=Atjaunināts +repo_updated=Atjaunināts %s members=Dalībnieki teams=Komandas code=Kods diff --git a/options/locale/locale_nl-NL.ini b/options/locale/locale_nl-NL.ini index d999fc2334..784d53bee5 100644 --- a/options/locale/locale_nl-NL.ini +++ b/options/locale/locale_nl-NL.ini @@ -2731,7 +2731,7 @@ org_name_holder=Organisatienaam org_full_name_holder=Volledige naam organisatie org_name_helper=Organisatienamen horen kort en memorabel zijn. create_org=Nieuwe organisatie aanmaken -repo_updated=Geupdate +repo_updated=Geupdate %s members=Leden teams=Teams lower_members=leden diff --git a/options/locale/locale_pl-PL.ini b/options/locale/locale_pl-PL.ini index 989dedd731..0a03defdfa 100644 --- a/options/locale/locale_pl-PL.ini +++ b/options/locale/locale_pl-PL.ini @@ -2033,7 +2033,7 @@ org_name_holder=Nazwa organizacji org_full_name_holder=Pełna nazwa organizacji org_name_helper=Nazwa organizacji powinna być krótka i łatwa do zapamiętania. create_org=Utwórz organizację -repo_updated=Zaktualizowano +repo_updated=Zaktualizowano %s members=Członkowie teams=Zespoły lower_members=członkowie diff --git a/options/locale/locale_pt-BR.ini b/options/locale/locale_pt-BR.ini index 69305cf73b..d8bb0908db 100644 --- a/options/locale/locale_pt-BR.ini +++ b/options/locale/locale_pt-BR.ini @@ -2610,7 +2610,7 @@ org_name_holder=Nome da organização org_full_name_holder=Nome completo da organização org_name_helper=Nomes de organização devem ser curtos e memoráveis. create_org=Criar organização -repo_updated=Atualizado +repo_updated=Atualizado %s members=Membros teams=Equipes code=Código diff --git a/options/locale/locale_pt-PT.ini b/options/locale/locale_pt-PT.ini index 7b3243fbcf..8f781fe85f 100644 --- a/options/locale/locale_pt-PT.ini +++ b/options/locale/locale_pt-PT.ini @@ -2750,7 +2750,7 @@ org_name_holder=Nome da organização org_full_name_holder=Nome completo da organização org_name_helper=Nomes das organizações devem ser curtos e memoráveis. create_org=Criar organização -repo_updated=Modificado +repo_updated=Modificado %s members=Membros teams=Equipas code=Código diff --git a/options/locale/locale_ru-RU.ini b/options/locale/locale_ru-RU.ini index 97d14452c8..7b53e0234d 100644 --- a/options/locale/locale_ru-RU.ini +++ b/options/locale/locale_ru-RU.ini @@ -2749,7 +2749,7 @@ org_name_holder=Название организации org_full_name_holder=Полное название org_name_helper=Лучшие названия организаций коротки и запоминаемы. create_org=Создать организацию -repo_updated=Обновлено +repo_updated=Обновлено %s members=Участники teams=Команды code=Код diff --git a/options/locale/locale_si-LK.ini b/options/locale/locale_si-LK.ini index ac8f4a2acd..eae82f6007 100644 --- a/options/locale/locale_si-LK.ini +++ b/options/locale/locale_si-LK.ini @@ -1921,7 +1921,7 @@ org_name_holder=සංවිධානයේ නම org_full_name_holder=සංවිධානයේ සම්පූර්ණ නම org_name_helper=සංවිධාන නම් කෙටි හා අමතක නොවන විය යුතුය. create_org=සංවිධානය සාදන්න -repo_updated=යාවත්කාල කෙරිණි +repo_updated=යාවත්කාල කෙරිණි %s members=සාමාජිකයින් teams=කණ්ඩායම් lower_members=සාමාජිකයින් diff --git a/options/locale/locale_sv-SE.ini b/options/locale/locale_sv-SE.ini index 19dc2a3ba8..e2c7277987 100644 --- a/options/locale/locale_sv-SE.ini +++ b/options/locale/locale_sv-SE.ini @@ -1546,7 +1546,7 @@ org_name_holder=Organisationsnamn org_full_name_holder=Organisationens Fullständiga Namn org_name_helper=Organisationsnamn bör vara korta och enkla att komma ihåg. create_org=Skapa organisation -repo_updated=Uppdaterad +repo_updated=Uppdaterad %s members=Medlemmar teams=Grupper lower_members=medlemmar diff --git a/options/locale/locale_tr-TR.ini b/options/locale/locale_tr-TR.ini index 50d03458be..b178158bdd 100644 --- a/options/locale/locale_tr-TR.ini +++ b/options/locale/locale_tr-TR.ini @@ -2591,7 +2591,7 @@ org_name_holder=Organizasyon Adı org_full_name_holder=Organizasyon Tam Adı org_name_helper=Organizasyon adları kısa ve hatırlanabilir olmalıdır. create_org=Organizasyon Oluştur -repo_updated=Güncellendi +repo_updated=Güncellendi %s members=Üyeler teams=Takımlar code=Kod diff --git a/options/locale/locale_uk-UA.ini b/options/locale/locale_uk-UA.ini index 99a262a4a4..d8ee5c6fa4 100644 --- a/options/locale/locale_uk-UA.ini +++ b/options/locale/locale_uk-UA.ini @@ -2078,7 +2078,7 @@ org_name_holder=Назва організації org_full_name_holder=Повна назва організації org_name_helper=Назва організації має бути простою та зрозумілою. create_org=Створити організацію -repo_updated=Оновлено +repo_updated=Оновлено %s members=Учасники teams=Команди lower_members=учасники diff --git a/options/locale/locale_zh-CN.ini b/options/locale/locale_zh-CN.ini index b66877004e..6eecc38674 100644 --- a/options/locale/locale_zh-CN.ini +++ b/options/locale/locale_zh-CN.ini @@ -2767,7 +2767,7 @@ org_name_holder=组织名称 org_full_name_holder=组织全名 org_name_helper=组织名字应该简单明了。 create_org=创建组织 -repo_updated=最后更新于 +repo_updated=于 %s 更新 members=成员 teams=团队 code=代码 diff --git a/options/locale/locale_zh-HK.ini b/options/locale/locale_zh-HK.ini index f8c7b690d8..5faf719a35 100644 --- a/options/locale/locale_zh-HK.ini +++ b/options/locale/locale_zh-HK.ini @@ -676,7 +676,7 @@ release.downloads=下載附件 org_name_holder=組織名稱 org_full_name_holder=組織全名 create_org=建立組織 -repo_updated=最後更新於 +repo_updated=最後更新於 %s members=成員數 teams=組織團隊 lower_members=名成員 diff --git a/options/locale/locale_zh-TW.ini b/options/locale/locale_zh-TW.ini index eca366e9f2..f52c5e6879 100644 --- a/options/locale/locale_zh-TW.ini +++ b/options/locale/locale_zh-TW.ini @@ -2511,7 +2511,7 @@ org_name_holder=組織名稱 org_full_name_holder=組織全名 org_name_helper=組織名稱應該要簡短且方便記憶 create_org=建立組織 -repo_updated=更新於 +repo_updated=於 %s 更新 members=成員 teams=團隊 code=程式碼 diff --git a/templates/explore/repo_list.tmpl b/templates/explore/repo_list.tmpl index 6381f1217e..59bc6c8a95 100644 --- a/templates/explore/repo_list.tmpl +++ b/templates/explore/repo_list.tmpl @@ -62,7 +62,7 @@ {{end}} {{end}} -
{{ctx.Locale.Tr "org.repo_updated"}} {{TimeSinceUnix .UpdatedUnix ctx.Locale}}
+
{{ctx.Locale.Tr "org.repo_updated" (TimeSinceUnix .UpdatedUnix ctx.Locale)}}
{{else}} diff --git a/templates/repo/branch/list.tmpl b/templates/repo/branch/list.tmpl index b047e74d81..18ec95df24 100644 --- a/templates/repo/branch/list.tmpl +++ b/templates/repo/branch/list.tmpl @@ -25,7 +25,7 @@ {{template "repo/commit_statuses" dict "Status" (index $.CommitStatus .DefaultBranchBranch.DBBranch.CommitID) "Statuses" (index $.CommitStatuses .DefaultBranchBranch.DBBranch.CommitID)}} -

{{svg "octicon-git-commit" 16 "tw-mr-1"}}{{ShortSha .DefaultBranchBranch.DBBranch.CommitID}} · {{RenderCommitMessage $.Context .DefaultBranchBranch.DBBranch.CommitMessage (.Repository.ComposeMetas ctx)}} · {{ctx.Locale.Tr "org.repo_updated"}} {{TimeSince .DefaultBranchBranch.DBBranch.CommitTime.AsTime ctx.Locale}}{{if .DefaultBranchBranch.DBBranch.Pusher}}  {{template "shared/user/avatarlink" dict "user" .DefaultBranchBranch.DBBranch.Pusher}}{{template "shared/user/namelink" .DefaultBranchBranch.DBBranch.Pusher}}{{end}}

+

{{svg "octicon-git-commit" 16 "tw-mr-1"}}{{ShortSha .DefaultBranchBranch.DBBranch.CommitID}} · {{RenderCommitMessage $.Context .DefaultBranchBranch.DBBranch.CommitMessage (.Repository.ComposeMetas ctx)}} · {{ctx.Locale.Tr "org.repo_updated" (TimeSince .DefaultBranchBranch.DBBranch.CommitTime.AsTime ctx.Locale)}} {{if .DefaultBranchBranch.DBBranch.Pusher}}  {{template "shared/user/avatarlink" dict "user" .DefaultBranchBranch.DBBranch.Pusher}}{{template "shared/user/namelink" .DefaultBranchBranch.DBBranch.Pusher}}{{end}}

{{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted)}} @@ -98,7 +98,7 @@ {{template "repo/commit_statuses" dict "Status" (index $.CommitStatus .DBBranch.CommitID) "Statuses" (index $.CommitStatuses .DBBranch.CommitID)}} -

{{svg "octicon-git-commit" 16 "tw-mr-1"}}{{ShortSha .DBBranch.CommitID}} · {{RenderCommitMessage $.Context .DBBranch.CommitMessage ($.Repository.ComposeMetas ctx)}} · {{ctx.Locale.Tr "org.repo_updated"}} {{TimeSince .DBBranch.CommitTime.AsTime ctx.Locale}}{{if .DBBranch.Pusher}}  {{template "shared/user/avatarlink" dict "user" .DBBranch.Pusher}}  {{template "shared/user/namelink" .DBBranch.Pusher}}{{end}}

+

{{svg "octicon-git-commit" 16 "tw-mr-1"}}{{ShortSha .DBBranch.CommitID}} · {{RenderCommitMessage $.Context .DBBranch.CommitMessage ($.Repository.ComposeMetas ctx)}} · {{ctx.Locale.Tr "org.repo_updated" (TimeSince .DBBranch.CommitTime.AsTime ctx.Locale)}} {{if .DBBranch.Pusher}}  {{template "shared/user/avatarlink" dict "user" .DBBranch.Pusher}}  {{template "shared/user/namelink" .DBBranch.Pusher}}{{end}}

{{end}} diff --git a/tests/integration/last_updated_time_test.go b/tests/integration/last_updated_time_test.go new file mode 100644 index 0000000000..c1b3f515e1 --- /dev/null +++ b/tests/integration/last_updated_time_test.go @@ -0,0 +1,71 @@ +package integration + +import ( + "net/http" + "net/url" + "path" + "strings" + "testing" + + "github.com/PuerkitoBio/goquery" + "github.com/stretchr/testify/assert" +) + +func TestRepoLastUpdatedTime(t *testing.T) { + onGiteaRun(t, func(t *testing.T, u *url.URL) { + user := "user2" + session := loginUser(t, user) + + req := NewRequest(t, "GET", path.Join("explore", "repos")) + resp := session.MakeRequest(t, req, http.StatusOK) + doc := NewHTMLParser(t, resp.Body) + node := doc.doc.Find(".flex-item-body").First() + + { + buf := "" + findTextNonNested(t, node, &buf) + assert.Equal(t, "Updated", strings.TrimSpace(buf)) + } + + // Relative time should be present as a descendent + { + relativeTime := node.Find("relative-time").Text() + assert.Equal(t, true, strings.HasPrefix(relativeTime, "19")) // ~1970, might underflow with timezone + } + }) +} + +func TestBranchLastUpdatedTime(t *testing.T) { + onGiteaRun(t, func(t *testing.T, u *url.URL) { + user := "user2" + repo := "repo1" + session := loginUser(t, user) + + req := NewRequest(t, "GET", path.Join(user, repo, "branches")) + resp := session.MakeRequest(t, req, http.StatusOK) + doc := NewHTMLParser(t, resp.Body) + node := doc.doc.Find("p:has(span.commit-message)") + + { + buf := "" + findTextNonNested(t, node, &buf) + assert.Equal(t, true, strings.Contains(buf, "Updated")) + } + + { + relativeTime := node.Find("relative-time").Text() + assert.Equal(t, true, strings.HasPrefix(relativeTime, "2017")) + } + }) +} + +// Find all text that are direct descendents +func findTextNonNested(t *testing.T, n *goquery.Selection, buf *string) { + t.Helper() + + n.Contents().Each(func(i int, s *goquery.Selection) { + if goquery.NodeName(s) == "#text" { + *buf += s.Text() + } + }) +}