From 0516ddc9fb03c20d92584a140c0b5f858985c18c Mon Sep 17 00:00:00 2001 From: JakobDev Date: Mon, 30 Jan 2023 09:53:58 +0100 Subject: [PATCH 01/19] Add archive date --- models/migrations/migrations.go | 2 ++ models/migrations/v1_19/v240.go | 14 ++++++++++++++ models/repo/archiver.go | 9 ++++++++- models/repo/repo.go | 5 +++-- modules/structs/repo.go | 1 + modules/timeutil/timestamp.go | 10 ++++++++++ options/locale/locale_en-US.ini | 1 + services/convert/repository.go | 1 + templates/repo/home.tmpl | 6 +++++- templates/swagger/v1_json.tmpl | 5 +++++ 10 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 models/migrations/v1_19/v240.go diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 2058fcec0fe05..739f84909e86b 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -453,6 +453,8 @@ var migrations = []Migration{ NewMigration("Add updated unix to LFSMetaObject", v1_19.AddUpdatedUnixToLFSMetaObject), // v239 -> v240 NewMigration("Add scope for access_token", v1_19.AddScopeForAccessTokens), + // v240 -> v241 + NewMigration("Add archived_unix for repository", v1_19.AddArchivedUnixForRepository), } // GetCurrentDBVersion returns the current db version diff --git a/models/migrations/v1_19/v240.go b/models/migrations/v1_19/v240.go new file mode 100644 index 0000000000000..ac79669c7aaca --- /dev/null +++ b/models/migrations/v1_19/v240.go @@ -0,0 +1,14 @@ +// Copyright 2022 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_19 //nolint + +import ( + "xorm.io/xorm" +) + +func AddArchivedUnixForRepository(x *xorm.Engine) error { + // all previous tokens have `all` and `sudo` scopes + _, err := x.Exec("UPDATE repository SET archived_unix = 0 WHERE archived_unix IS NULL") + return err +} diff --git a/models/repo/archiver.go b/models/repo/archiver.go index 11ecaff34c694..4acf45a2eb52d 100644 --- a/models/repo/archiver.go +++ b/models/repo/archiver.go @@ -146,6 +146,13 @@ func FindRepoArchives(opts FindRepoArchiversOption) ([]*RepoArchiver, error) { // SetArchiveRepoState sets if a repo is archived func SetArchiveRepoState(repo *Repository, isArchived bool) (err error) { repo.IsArchived = isArchived - _, err = db.GetEngine(db.DefaultContext).Where("id = ?", repo.ID).Cols("is_archived").NoAutoTime().Update(repo) + + if isArchived { + repo.ArchivedUnix = timeutil.TimeStampNow() + } else { + repo.ArchivedUnix = timeutil.TimeStamp(0) + } + + _, err = db.GetEngine(db.DefaultContext).Where("id = ?", repo.ID).Cols("is_archived", "archived_unix").NoAutoTime().Update(repo) return err } diff --git a/models/repo/repo.go b/models/repo/repo.go index e5e1ac43b41fd..e60c1626fc9b8 100644 --- a/models/repo/repo.go +++ b/models/repo/repo.go @@ -171,8 +171,9 @@ type Repository struct { // Avatar: ID(10-20)-md5(32) - must fit into 64 symbols Avatar string `xorm:"VARCHAR(64)"` - CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` - UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` + CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` + UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` + ArchivedUnix timeutil.TimeStamp } func init() { diff --git a/modules/structs/repo.go b/modules/structs/repo.go index 16f3d9dd26b7b..b260eb4bbe278 100644 --- a/modules/structs/repo.go +++ b/modules/structs/repo.go @@ -79,6 +79,7 @@ type Repository struct { Created time.Time `json:"created_at"` // swagger:strfmt date-time Updated time.Time `json:"updated_at"` + ArchivedAt *time.Time `json:"archived_at"` Permissions *Permission `json:"permissions,omitempty"` HasIssues bool `json:"has_issues"` InternalTracker *InternalTracker `json:"internal_tracker,omitempty"` diff --git a/modules/timeutil/timestamp.go b/modules/timeutil/timestamp.go index c8e0d4bdc114a..868cdc43a50a4 100644 --- a/modules/timeutil/timestamp.go +++ b/modules/timeutil/timestamp.go @@ -58,6 +58,16 @@ func (ts TimeStamp) AsTime() (tm time.Time) { return ts.AsTimeInLocation(setting.DefaultUILocation) } +// AsOptionalTime convert timestamp as *time.Time in Local locale. Returns nil if the time is zero. +func (ts TimeStamp) AsOptionalTime() (tm *time.Time) { + if ts.IsZero() { + return nil + } else { + timePointer := ts.AsTimeInLocation(setting.DefaultUILocation) + return &timePointer + } +} + // AsLocalTime convert timestamp as time.Time in local location func (ts TimeStamp) AsLocalTime() time.Time { return time.Unix(int64(ts), 0) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 74ba85ca90161..f302a3f6a69cc 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -955,6 +955,7 @@ template.one_item = Must select at least one template item template.invalid = Must select a template repository archive.title = This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests. +archive.titleDate = This repository has been archived on %s. You can view files and clone it, but cannot push or open issues/pull-requests. archive.issue.nocomment = This repo is archived. You cannot comment on issues. archive.pull.nocomment = This repo is archived. You cannot comment on pull requests. diff --git a/services/convert/repository.go b/services/convert/repository.go index ce53a6669237c..bd9be05949f2b 100644 --- a/services/convert/repository.go +++ b/services/convert/repository.go @@ -166,6 +166,7 @@ func innerToRepo(ctx context.Context, repo *repo_model.Repository, mode perm.Acc DefaultBranch: repo.DefaultBranch, Created: repo.CreatedUnix.AsTime(), Updated: repo.UpdatedUnix.AsTime(), + ArchivedAt: repo.ArchivedUnix.AsOptionalTime(), Permissions: permission, HasIssues: hasIssues, ExternalTracker: externalTracker, diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index 82e6626e333a5..703411acd053d 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -58,7 +58,11 @@ {{if .Repository.IsArchived}}
- {{.locale.Tr "repo.archive.title"}} + {{if .Repository.ArchivedUnix.IsZero}} + {{.locale.Tr "repo.archive.title"}} + {{else}} + {{.locale.Tr "repo.archive.titleDate" .Repository.ArchivedUnix.FormatDate}} + {{end}}
{{end}} {{template "repo/sub_menu" .}} diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 726b771cfc734..be38819d0120d 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -18999,6 +18999,11 @@ "type": "boolean", "x-go-name": "Archived" }, + "archived_at": { + "type": "string", + "format": "date-time", + "x-go-name": "ArchivedAt" + }, "avatar_url": { "type": "string", "x-go-name": "AvatarURL" From 4cceff0edb0a0964e320c63a2af36f8678dac066 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Mon, 30 Jan 2023 14:11:45 +0100 Subject: [PATCH 02/19] Use local date format --- templates/repo/home.tmpl | 2 +- web_src/js/features/repo-home.js | 16 ++++++++++++++++ web_src/js/index.js | 3 ++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index 703411acd053d..5a23813c45407 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -61,7 +61,7 @@ {{if .Repository.ArchivedUnix.IsZero}} {{.locale.Tr "repo.archive.title"}} {{else}} - {{.locale.Tr "repo.archive.titleDate" .Repository.ArchivedUnix.FormatDate}} + {{.locale.Tr "repo.archive.titleDate" .Repository.ArchivedUnix.FormatShort}} {{end}} {{end}} diff --git a/web_src/js/features/repo-home.js b/web_src/js/features/repo-home.js index c4bdf3d4506dc..f2ed540c0a249 100644 --- a/web_src/js/features/repo-home.js +++ b/web_src/js/features/repo-home.js @@ -3,6 +3,9 @@ import {stripTags} from '../utils.js'; const {appSubUrl, csrfToken} = window.config; +const {lang} = document.documentElement; +const shortDateFormatter = new Intl.DateTimeFormat(lang, {year: 'numeric', month: 'short', day: 'numeric'}); + export function initRepoTopicBar() { const mgrBtn = $('#manage_topic'); const editDiv = $('#topic_edit'); @@ -179,3 +182,16 @@ export function initRepoTopicBar() { } }); } + +export function initRepoArchiveDateText() { + const archiveDateText = document.getElementById("archive-date-text"); + + if (!archiveDateText) { + return; + } + + const archiveDate = new Date(archiveDateText.attributes["date"].value); + const archiveText = archiveDateText.attributes["text"].value; + + archiveDateText.innerText = archiveText.replace("%s", shortDateFormatter.format(archiveDate)); +} diff --git a/web_src/js/index.js b/web_src/js/index.js index a866184203fd6..dccfaeb0adc3f 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -60,7 +60,7 @@ import { initHeadNavbarContentToggle, initGlobalTooltips, } from './features/common-global.js'; -import {initRepoTopicBar} from './features/repo-home.js'; +import {initRepoTopicBar, initRepoArchiveDateText} from './features/repo-home.js'; import {initAdminEmails} from './features/admin/emails.js'; import {initAdminCommon} from './features/admin/common.js'; import {initRepoTemplateSearch} from './features/repo-template.js'; @@ -185,6 +185,7 @@ $(document).ready(() => { initRepoSettingsCollaboration(); initRepoTemplateSearch(); initRepoTopicBar(); + initRepoArchiveDateText(); initRepoWikiForm(); initRepository(); From 0e2b687b7985d5be427df8acbf54ad4a0603b1c7 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Mon, 30 Jan 2023 14:20:04 +0100 Subject: [PATCH 03/19] Fix lint --- modules/timeutil/timestamp.go | 6 +++--- web_src/js/features/repo-home.js | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/timeutil/timestamp.go b/modules/timeutil/timestamp.go index 868cdc43a50a4..34ed3e0b1d3fb 100644 --- a/modules/timeutil/timestamp.go +++ b/modules/timeutil/timestamp.go @@ -62,10 +62,10 @@ func (ts TimeStamp) AsTime() (tm time.Time) { func (ts TimeStamp) AsOptionalTime() (tm *time.Time) { if ts.IsZero() { return nil - } else { - timePointer := ts.AsTimeInLocation(setting.DefaultUILocation) - return &timePointer } + + timePointer := ts.AsTimeInLocation(setting.DefaultUILocation) + return &timePointer } // AsLocalTime convert timestamp as time.Time in local location diff --git a/web_src/js/features/repo-home.js b/web_src/js/features/repo-home.js index f2ed540c0a249..e8ca472e3ec25 100644 --- a/web_src/js/features/repo-home.js +++ b/web_src/js/features/repo-home.js @@ -184,14 +184,14 @@ export function initRepoTopicBar() { } export function initRepoArchiveDateText() { - const archiveDateText = document.getElementById("archive-date-text"); + const archiveDateText = document.getElementById('archive-date-text'); if (!archiveDateText) { return; } - const archiveDate = new Date(archiveDateText.attributes["date"].value); - const archiveText = archiveDateText.attributes["text"].value; + const archiveDate = new Date(archiveDateText.attributes['date'].value); + const archiveText = archiveDateText.attributes['text'].value; - archiveDateText.innerText = archiveText.replace("%s", shortDateFormatter.format(archiveDate)); + archiveDateText.innerText = archiveText.replace('%s', shortDateFormatter.format(archiveDate)); } From 90b7e335362c18050977709e66248921739975de Mon Sep 17 00:00:00 2001 From: JakobDev Date: Mon, 30 Jan 2023 14:27:13 +0100 Subject: [PATCH 04/19] Use DEFAULT 0 --- models/migrations/migrations.go | 2 -- models/migrations/v1_19/v240.go | 14 -------------- models/repo/repo.go | 2 +- 3 files changed, 1 insertion(+), 17 deletions(-) delete mode 100644 models/migrations/v1_19/v240.go diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 739f84909e86b..2058fcec0fe05 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -453,8 +453,6 @@ var migrations = []Migration{ NewMigration("Add updated unix to LFSMetaObject", v1_19.AddUpdatedUnixToLFSMetaObject), // v239 -> v240 NewMigration("Add scope for access_token", v1_19.AddScopeForAccessTokens), - // v240 -> v241 - NewMigration("Add archived_unix for repository", v1_19.AddArchivedUnixForRepository), } // GetCurrentDBVersion returns the current db version diff --git a/models/migrations/v1_19/v240.go b/models/migrations/v1_19/v240.go deleted file mode 100644 index ac79669c7aaca..0000000000000 --- a/models/migrations/v1_19/v240.go +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2022 The Gitea Authors. All rights reserved. -// SPDX-License-Identifier: MIT - -package v1_19 //nolint - -import ( - "xorm.io/xorm" -) - -func AddArchivedUnixForRepository(x *xorm.Engine) error { - // all previous tokens have `all` and `sudo` scopes - _, err := x.Exec("UPDATE repository SET archived_unix = 0 WHERE archived_unix IS NULL") - return err -} diff --git a/models/repo/repo.go b/models/repo/repo.go index e60c1626fc9b8..48d87a68a69f8 100644 --- a/models/repo/repo.go +++ b/models/repo/repo.go @@ -173,7 +173,7 @@ type Repository struct { CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` - ArchivedUnix timeutil.TimeStamp + ArchivedUnix timeutil.TimeStamp `xorm:"Default 0"` } func init() { From 0f2c93b30a2d834199ad1951ba629cf767de3e63 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Mon, 30 Jan 2023 14:29:42 +0100 Subject: [PATCH 05/19] Use snake case --- options/locale/locale_en-US.ini | 2 +- templates/repo/home.tmpl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index f302a3f6a69cc..2f35ff2cd4935 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -955,7 +955,7 @@ template.one_item = Must select at least one template item template.invalid = Must select a template repository archive.title = This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests. -archive.titleDate = This repository has been archived on %s. You can view files and clone it, but cannot push or open issues/pull-requests. +archive.title_date = This repository has been archived on %s. You can view files and clone it, but cannot push or open issues/pull-requests. archive.issue.nocomment = This repo is archived. You cannot comment on issues. archive.pull.nocomment = This repo is archived. You cannot comment on pull requests. diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index 5a23813c45407..1b7d4ae2dce1d 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -61,7 +61,7 @@ {{if .Repository.ArchivedUnix.IsZero}} {{.locale.Tr "repo.archive.title"}} {{else}} - {{.locale.Tr "repo.archive.titleDate" .Repository.ArchivedUnix.FormatShort}} + {{.locale.Tr "repo.archive.title_date" .Repository.ArchivedUnix.FormatShort}} {{end}} {{end}} From 84cebb4f608bfabffb18e6849ef5eaa64f7d2cb8 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Mon, 30 Jan 2023 14:30:58 +0100 Subject: [PATCH 06/19] Use .ID instead .Where --- models/repo/archiver.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/repo/archiver.go b/models/repo/archiver.go index 4acf45a2eb52d..70f53cfe158d0 100644 --- a/models/repo/archiver.go +++ b/models/repo/archiver.go @@ -153,6 +153,6 @@ func SetArchiveRepoState(repo *Repository, isArchived bool) (err error) { repo.ArchivedUnix = timeutil.TimeStamp(0) } - _, err = db.GetEngine(db.DefaultContext).Where("id = ?", repo.ID).Cols("is_archived", "archived_unix").NoAutoTime().Update(repo) + _, err = db.GetEngine(db.DefaultContext).ID(repo.ID).Cols("is_archived", "archived_unix").NoAutoTime().Update(repo) return err } From b09dabedbe19f571d94d593d0d5b240b8d1a57f1 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Fri, 14 Apr 2023 16:43:35 +0200 Subject: [PATCH 07/19] Add migration --- models/migrations/v1_20/v253.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 models/migrations/v1_20/v253.go diff --git a/models/migrations/v1_20/v253.go b/models/migrations/v1_20/v253.go new file mode 100644 index 0000000000000..f453bbab3ce21 --- /dev/null +++ b/models/migrations/v1_20/v253.go @@ -0,0 +1,14 @@ +// Copyright 2023 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_20 //nolint + +import "xorm.io/xorm" + +func AddArchivedUnixToRepository(x *xorm.Engine) error { + type Repository struct { + ArchivedUnix timeutil.TimeStamp `xorm:"Default 0"` + } + + return x.Sync(new(Repository)) +} \ No newline at end of file From 5ebc651355a1f676798136c5f622d213f3ac659d Mon Sep 17 00:00:00 2001 From: JakobDev Date: Fri, 21 Apr 2023 16:18:56 +0200 Subject: [PATCH 08/19] Try to fix Migration again --- models/migrations/v1_20/v253.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/models/migrations/v1_20/v253.go b/models/migrations/v1_20/v253.go index f453bbab3ce21..2b3a760b3d2f7 100644 --- a/models/migrations/v1_20/v253.go +++ b/models/migrations/v1_20/v253.go @@ -10,5 +10,8 @@ func AddArchivedUnixToRepository(x *xorm.Engine) error { ArchivedUnix timeutil.TimeStamp `xorm:"Default 0"` } - return x.Sync(new(Repository)) -} \ No newline at end of file + x.Sync(new(Repository)) + + _, err := x.Exec("UPDATE repository SET archived_unix = 0") + return err +} From 66342e318655459240a3aa0bd47d27901db33b38 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Mon, 24 Apr 2023 10:46:16 +0200 Subject: [PATCH 09/19] Make Migration number bigger --- models/migrations/migrations.go | 2 ++ models/migrations/v1_20/{v253.go => v255.go} | 0 2 files changed, 2 insertions(+) rename models/migrations/v1_20/{v253.go => v255.go} (100%) diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 35a18fb7f2bbc..1f33a02d75832 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -483,6 +483,8 @@ var migrations = []Migration{ NewMigration("Fix incorrect owner team unit access mode", v1_20.FixIncorrectOwnerTeamUnitAccessMode), // v252 -> v253 NewMigration("Fix incorrect admin team unit access mode", v1_20.FixIncorrectAdminTeamUnitAccessMode), + // v255 -> v256 + NewMigration("Add ArchivedUnix Column", v1_20.AddArchivedUnixToRepository), } // GetCurrentDBVersion returns the current db version diff --git a/models/migrations/v1_20/v253.go b/models/migrations/v1_20/v255.go similarity index 100% rename from models/migrations/v1_20/v253.go rename to models/migrations/v1_20/v255.go From 9780e2496ae0f4108443d63ab17d1f95beede676 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Mon, 24 Apr 2023 11:07:05 +0200 Subject: [PATCH 10/19] fix Migration syntax --- models/migrations/migrations.go | 4 ++-- models/migrations/v1_20/v255.go | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index a71d43f30756b..45cad1134bbfd 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -487,8 +487,8 @@ var migrations = []Migration{ NewMigration("Fix ExternalTracker and ExternalWiki accessMode in owner and admin team", v1_20.FixExternalTrackerAndExternalWikiAccessModeInOwnerAndAdminTeam), // v254 -> v255 NewMigration("Add ActionTaskOutput table", v1_20.AddActionTaskOutputTable), - // v255 -> v256 - NewMigration("Add ArchivedUnix Column", v1_20.AddArchivedUnixToRepository + // v255 -> v256 + NewMigration("Add ArchivedUnix Column", v1_20.AddArchivedUnixToRepository), } // GetCurrentDBVersion returns the current db version diff --git a/models/migrations/v1_20/v255.go b/models/migrations/v1_20/v255.go index 2b3a760b3d2f7..7eff53aa4c8d2 100644 --- a/models/migrations/v1_20/v255.go +++ b/models/migrations/v1_20/v255.go @@ -3,7 +3,11 @@ package v1_20 //nolint -import "xorm.io/xorm" +import ( + "code.gitea.io/gitea/modules/timeutil" + + "xorm.io/xorm" +) func AddArchivedUnixToRepository(x *xorm.Engine) error { type Repository struct { @@ -11,7 +15,7 @@ func AddArchivedUnixToRepository(x *xorm.Engine) error { } x.Sync(new(Repository)) - + _, err := x.Exec("UPDATE repository SET archived_unix = 0") return err } From bc1471915607059c4e14f41bf7869405851c2eae Mon Sep 17 00:00:00 2001 From: JakobDev Date: Mon, 24 Apr 2023 11:20:37 +0200 Subject: [PATCH 11/19] Use Datetime function --- models/migrations/migrations.go | 4 ++-- templates/repo/home.tmpl | 2 +- web_src/js/features/repo-home.js | 16 ---------------- web_src/js/index.js | 3 +-- 4 files changed, 4 insertions(+), 21 deletions(-) diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 45cad1134bbfd..1f1f43796cf4a 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -487,8 +487,8 @@ var migrations = []Migration{ NewMigration("Fix ExternalTracker and ExternalWiki accessMode in owner and admin team", v1_20.FixExternalTrackerAndExternalWikiAccessModeInOwnerAndAdminTeam), // v254 -> v255 NewMigration("Add ActionTaskOutput table", v1_20.AddActionTaskOutputTable), - // v255 -> v256 - NewMigration("Add ArchivedUnix Column", v1_20.AddArchivedUnixToRepository), + // v255 -> v256 + NewMigration("Add ArchivedUnix Column", v1_20.AddArchivedUnixToRepository), } // GetCurrentDBVersion returns the current db version diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index 1aa1dfcff780e..0dc98038420f9 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -56,7 +56,7 @@ {{if .Repository.ArchivedUnix.IsZero}} {{.locale.Tr "repo.archive.title"}} {{else}} - {{.locale.Tr "repo.archive.title_date" .Repository.ArchivedUnix.FormatShort}} + {{.locale.Tr "repo.archive.title_date" (DateTime "short" .Repository.ArchivedUnix.FormatLong .Repository.ArchivedUnix.FormatShort) | Safe}} {{end}} {{end}} diff --git a/web_src/js/features/repo-home.js b/web_src/js/features/repo-home.js index c265ee56e2fd4..55a27710542c0 100644 --- a/web_src/js/features/repo-home.js +++ b/web_src/js/features/repo-home.js @@ -4,9 +4,6 @@ import {hideElem, showElem} from '../utils/dom.js'; const {appSubUrl, csrfToken} = window.config; -const {lang} = document.documentElement; -const shortDateFormatter = new Intl.DateTimeFormat(lang, {year: 'numeric', month: 'short', day: 'numeric'}); - export function initRepoTopicBar() { const mgrBtn = $('#manage_topic'); if (!mgrBtn.length) return; @@ -181,16 +178,3 @@ export function initRepoTopicBar() { } }); } - -export function initRepoArchiveDateText() { - const archiveDateText = document.getElementById('archive-date-text'); - - if (!archiveDateText) { - return; - } - - const archiveDate = new Date(archiveDateText.attributes['date'].value); - const archiveText = archiveDateText.attributes['text'].value; - - archiveDateText.innerText = archiveText.replace('%s', shortDateFormatter.format(archiveDate)); -} diff --git a/web_src/js/index.js b/web_src/js/index.js index 22bb3112711b8..f7cbb24e8562e 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -48,7 +48,7 @@ import { initGlobalLinkActions, initHeadNavbarContentToggle, } from './features/common-global.js'; -import {initRepoTopicBar, initRepoArchiveDateText} from './features/repo-home.js'; +import {initRepoTopicBar} from './features/repo-home.js'; import {initAdminEmails} from './features/admin/emails.js'; import {initAdminCommon} from './features/admin/common.js'; import {initRepoTemplateSearch} from './features/repo-template.js'; @@ -162,7 +162,6 @@ onDomReady(() => { initRepoSettingsCollaboration(); initRepoTemplateSearch(); initRepoTopicBar(); - initRepoArchiveDateText(); initRepoWikiForm(); initRepository(); initRepositoryActionView(); From 548d9c8711498e9265487397416db9831aaf28ed Mon Sep 17 00:00:00 2001 From: JakobDev Date: Mon, 24 Apr 2023 11:32:06 +0200 Subject: [PATCH 12/19] Changes requested by delv --- models/migrations/v1_20/v255.go | 2 +- models/repo/repo.go | 2 +- options/locale/locale_en-US.ini | 2 +- templates/repo/home.tmpl | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/models/migrations/v1_20/v255.go b/models/migrations/v1_20/v255.go index 7eff53aa4c8d2..a4028fcdf9343 100644 --- a/models/migrations/v1_20/v255.go +++ b/models/migrations/v1_20/v255.go @@ -11,7 +11,7 @@ import ( func AddArchivedUnixToRepository(x *xorm.Engine) error { type Repository struct { - ArchivedUnix timeutil.TimeStamp `xorm:"Default 0"` + ArchivedUnix timeutil.TimeStamp `xorm:"DEFAULT 0"` } x.Sync(new(Repository)) diff --git a/models/repo/repo.go b/models/repo/repo.go index c8b7557d69268..f9de6d493db45 100644 --- a/models/repo/repo.go +++ b/models/repo/repo.go @@ -176,7 +176,7 @@ type Repository struct { CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` - ArchivedUnix timeutil.TimeStamp `xorm:"Default 0"` + ArchivedUnix timeutil.TimeStamp `xorm:"DEFAULT 0"` } func init() { diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 1fb68ff775034..a0ea201768d85 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -991,7 +991,7 @@ template.issue_labels = Issue Labels template.one_item = Must select at least one template item template.invalid = Must select a template repository -archive.title = This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests. +archive.title_no_date = This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests. archive.title_date = This repository has been archived on %s. You can view files and clone it, but cannot push or open issues/pull-requests. archive.issue.nocomment = This repo is archived. You cannot comment on issues. archive.pull.nocomment = This repo is archived. You cannot comment on pull requests. diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index 0dc98038420f9..b1e3377d8c492 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -54,7 +54,7 @@ {{if .Repository.IsArchived}}
{{if .Repository.ArchivedUnix.IsZero}} - {{.locale.Tr "repo.archive.title"}} + {{.locale.Tr "repo.archive.title_no_date"}} {{else}} {{.locale.Tr "repo.archive.title_date" (DateTime "short" .Repository.ArchivedUnix.FormatLong .Repository.ArchivedUnix.FormatShort) | Safe}} {{end}} From 25a56fd4be5017d8d1039154740b3fc59a2b5ade Mon Sep 17 00:00:00 2001 From: JakobDev Date: Mon, 24 Apr 2023 14:16:20 +0200 Subject: [PATCH 13/19] Apply requested changes --- modules/timeutil/timestamp.go | 10 ---------- services/convert/repository.go | 2 +- templates/repo/home.tmpl | 2 +- 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/modules/timeutil/timestamp.go b/modules/timeutil/timestamp.go index f5ba7ab057507..c60d287faee13 100644 --- a/modules/timeutil/timestamp.go +++ b/modules/timeutil/timestamp.go @@ -58,16 +58,6 @@ func (ts TimeStamp) AsTime() (tm time.Time) { return ts.AsTimeInLocation(setting.DefaultUILocation) } -// AsOptionalTime convert timestamp as *time.Time in Local locale. Returns nil if the time is zero. -func (ts TimeStamp) AsOptionalTime() (tm *time.Time) { - if ts.IsZero() { - return nil - } - - timePointer := ts.AsTimeInLocation(setting.DefaultUILocation) - return &timePointer -} - // AsLocalTime convert timestamp as time.Time in local location func (ts TimeStamp) AsLocalTime() time.Time { return time.Unix(int64(ts), 0) diff --git a/services/convert/repository.go b/services/convert/repository.go index 803695d441a7a..f470fd16564ea 100644 --- a/services/convert/repository.go +++ b/services/convert/repository.go @@ -183,7 +183,7 @@ func innerToRepo(ctx context.Context, repo *repo_model.Repository, mode perm.Acc DefaultBranch: repo.DefaultBranch, Created: repo.CreatedUnix.AsTime(), Updated: repo.UpdatedUnix.AsTime(), - ArchivedAt: repo.ArchivedUnix.AsOptionalTime(), + ArchivedAt: repo.ArchivedUnix.AsTime(), Permissions: permission, HasIssues: hasIssues, ExternalTracker: externalTracker, diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index b1e3377d8c492..e2b3ec297d9ea 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -56,7 +56,7 @@ {{if .Repository.ArchivedUnix.IsZero}} {{.locale.Tr "repo.archive.title_no_date"}} {{else}} - {{.locale.Tr "repo.archive.title_date" (DateTime "short" .Repository.ArchivedUnix.FormatLong .Repository.ArchivedUnix.FormatShort) | Safe}} + {{.locale.Tr "repo.archive.title_date" (DateTime "long" .Repository.ArchivedUnix.FormatLong .Repository.ArchivedUnix.FormatShort) | Safe}} {{end}}
{{end}} From e6cf7d2b22e9ca45a09af054ea71d54f19ee3eba Mon Sep 17 00:00:00 2001 From: JakobDev Date: Mon, 24 Apr 2023 14:38:29 +0200 Subject: [PATCH 14/19] Update Migration SQL command --- models/migrations/v1_20/v255.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/migrations/v1_20/v255.go b/models/migrations/v1_20/v255.go index a4028fcdf9343..1a5e1444ffa78 100644 --- a/models/migrations/v1_20/v255.go +++ b/models/migrations/v1_20/v255.go @@ -16,6 +16,6 @@ func AddArchivedUnixToRepository(x *xorm.Engine) error { x.Sync(new(Repository)) - _, err := x.Exec("UPDATE repository SET archived_unix = 0") + _, err := x.Exec("UPDATE repository SET archived_unix = updated_unix WHERE is_archived = 1 AND archived_unix = 0") return err } From 253196014c765311c6d195f380daa52c0ee183ed Mon Sep 17 00:00:00 2001 From: JakobDev Date: Mon, 24 Apr 2023 14:47:15 +0200 Subject: [PATCH 15/19] Don't use Pointer --- modules/structs/repo.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/structs/repo.go b/modules/structs/repo.go index bb789b0fd5d9f..259c230571573 100644 --- a/modules/structs/repo.go +++ b/modules/structs/repo.go @@ -80,7 +80,7 @@ type Repository struct { Created time.Time `json:"created_at"` // swagger:strfmt date-time Updated time.Time `json:"updated_at"` - ArchivedAt *time.Time `json:"archived_at"` + ArchivedAt time.Time `json:"archived_at"` Permissions *Permission `json:"permissions,omitempty"` HasIssues bool `json:"has_issues"` InternalTracker *InternalTracker `json:"internal_tracker,omitempty"` From 03fb26a8578f551894233905d00b6c09de6da91c Mon Sep 17 00:00:00 2001 From: JakobDev Date: Tue, 25 Apr 2023 08:15:36 +0200 Subject: [PATCH 16/19] Fix broken translations --- templates/repo/diff/compare.tmpl | 6 +++++- templates/repo/empty.tmpl | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/templates/repo/diff/compare.tmpl b/templates/repo/diff/compare.tmpl index c7538a7969638..7b5dd347c06e5 100644 --- a/templates/repo/diff/compare.tmpl +++ b/templates/repo/diff/compare.tmpl @@ -219,7 +219,11 @@ {{else if .Repository.IsArchived}}
- {{.locale.Tr "repo.archive.title"}} + {{if .Repository.ArchivedUnix.IsZero}} + {{.locale.Tr "repo.archive.title_no_date"}} + {{else}} + {{.locale.Tr "repo.archive.title_date" (DateTime "long" .Repository.ArchivedUnix.FormatLong .Repository.ArchivedUnix.FormatShort) | Safe}} + {{end}}
{{end}} {{if $.IsSigned}} diff --git a/templates/repo/empty.tmpl b/templates/repo/empty.tmpl index 0acb08933aa14..ea8fc7835369f 100644 --- a/templates/repo/empty.tmpl +++ b/templates/repo/empty.tmpl @@ -7,7 +7,11 @@ {{template "base/alert" .}} {{if .Repository.IsArchived}}
- {{.locale.Tr "repo.archive.title"}} + {{if .Repository.ArchivedUnix.IsZero}} + {{.locale.Tr "repo.archive.title_no_date"}} + {{else}} + {{.locale.Tr "repo.archive.title_date" (DateTime "long" .Repository.ArchivedUnix.FormatLong .Repository.ArchivedUnix.FormatShort) | Safe}} + {{end}}
{{end}} {{if .Repository.IsBroken}} From b72d5abb19c70fdee056dcda6499f6c7bdaf9c90 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Tue, 25 Apr 2023 08:22:22 +0200 Subject: [PATCH 17/19] Try to make Migration work with all Databases --- models/migrations/v1_20/v255.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/migrations/v1_20/v255.go b/models/migrations/v1_20/v255.go index 1a5e1444ffa78..5f2987c2fa472 100644 --- a/models/migrations/v1_20/v255.go +++ b/models/migrations/v1_20/v255.go @@ -16,6 +16,6 @@ func AddArchivedUnixToRepository(x *xorm.Engine) error { x.Sync(new(Repository)) - _, err := x.Exec("UPDATE repository SET archived_unix = updated_unix WHERE is_archived = 1 AND archived_unix = 0") + _, err := x.Exec("UPDATE repository SET archived_unix = updated_unix WHERE is_archived = ? AND archived_unix = 0", true) return err } From aebcdba5825db2ed681d5794d01ec56bf2400966 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Wed, 26 Apr 2023 15:15:24 +0200 Subject: [PATCH 18/19] Do requested changes --- options/locale/locale_en-US.ini | 2 +- templates/repo/diff/compare.tmpl | 4 ++-- templates/repo/empty.tmpl | 4 ++-- templates/repo/home.tmpl | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index a0ea201768d85..1fb68ff775034 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -991,7 +991,7 @@ template.issue_labels = Issue Labels template.one_item = Must select at least one template item template.invalid = Must select a template repository -archive.title_no_date = This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests. +archive.title = This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests. archive.title_date = This repository has been archived on %s. You can view files and clone it, but cannot push or open issues/pull-requests. archive.issue.nocomment = This repo is archived. You cannot comment on issues. archive.pull.nocomment = This repo is archived. You cannot comment on pull requests. diff --git a/templates/repo/diff/compare.tmpl b/templates/repo/diff/compare.tmpl index 7b5dd347c06e5..3ec08b00ac3d2 100644 --- a/templates/repo/diff/compare.tmpl +++ b/templates/repo/diff/compare.tmpl @@ -220,9 +220,9 @@ {{else if .Repository.IsArchived}}
{{if .Repository.ArchivedUnix.IsZero}} - {{.locale.Tr "repo.archive.title_no_date"}} + {{.locale.Tr "repo.archive.title"}} {{else}} - {{.locale.Tr "repo.archive.title_date" (DateTime "long" .Repository.ArchivedUnix.FormatLong .Repository.ArchivedUnix.FormatShort) | Safe}} + {{.locale.Tr "repo.archive.title_date" (DateTime "long" .Repository.ArchivedUnix) | Safe}} {{end}}
{{end}} diff --git a/templates/repo/empty.tmpl b/templates/repo/empty.tmpl index ea8fc7835369f..e099ee9d3cca7 100644 --- a/templates/repo/empty.tmpl +++ b/templates/repo/empty.tmpl @@ -8,9 +8,9 @@ {{if .Repository.IsArchived}}
{{if .Repository.ArchivedUnix.IsZero}} - {{.locale.Tr "repo.archive.title_no_date"}} + {{.locale.Tr "repo.archive.title"}} {{else}} - {{.locale.Tr "repo.archive.title_date" (DateTime "long" .Repository.ArchivedUnix.FormatLong .Repository.ArchivedUnix.FormatShort) | Safe}} + {{.locale.Tr "repo.archive.title_date" (DateTime "long" .Repository.ArchivedUnix) | Safe}} {{end}}
{{end}} diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index e2b3ec297d9ea..8731d5b6da858 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -54,9 +54,9 @@ {{if .Repository.IsArchived}}
{{if .Repository.ArchivedUnix.IsZero}} - {{.locale.Tr "repo.archive.title_no_date"}} + {{.locale.Tr "repo.archive.title"}} {{else}} - {{.locale.Tr "repo.archive.title_date" (DateTime "long" .Repository.ArchivedUnix.FormatLong .Repository.ArchivedUnix.FormatShort) | Safe}} + {{.locale.Tr "repo.archive.title_date" (DateTime "long" .Repository.ArchivedUnix) | Safe}} {{end}}
{{end}} From c189ca94372bfb931d0e8fd1a49648c23a75d0cf Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 26 Apr 2023 22:17:44 +0800 Subject: [PATCH 19/19] Check the sync returned argument --- models/migrations/v1_20/v255.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/models/migrations/v1_20/v255.go b/models/migrations/v1_20/v255.go index 5f2987c2fa472..14b70f8f962f9 100644 --- a/models/migrations/v1_20/v255.go +++ b/models/migrations/v1_20/v255.go @@ -14,7 +14,9 @@ func AddArchivedUnixToRepository(x *xorm.Engine) error { ArchivedUnix timeutil.TimeStamp `xorm:"DEFAULT 0"` } - x.Sync(new(Repository)) + if err := x.Sync(new(Repository)); err != nil { + return err + } _, err := x.Exec("UPDATE repository SET archived_unix = updated_unix WHERE is_archived = ? AND archived_unix = 0", true) return err