Skip to content

Commit c41bc4f

Browse files
JakobDevsilverwindlunny
authored
Display when a repo was archived (#22664)
This adds the date a repo is archived to Gitea and shows it in the UI and API. A feature, that GitHub has been [introduced recently](https://github.blog/changelog/2022-11-23-repository-archive-date-now-shown-in-ui/). I currently don't know how to correctly deal with the Date in the template, as different languages have different ways of writing a date. ![grafik](https://user-images.githubusercontent.com/15185051/234315187-7db5763e-d96e-4080-b894-9be178bfb6e1.png) --------- Co-authored-by: silverwind <[email protected]> Co-authored-by: Lunny Xiao <[email protected]>
1 parent 61d08f4 commit c41bc4f

File tree

11 files changed

+59
-6
lines changed

11 files changed

+59
-6
lines changed

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,8 @@ var migrations = []Migration{
487487
NewMigration("Fix ExternalTracker and ExternalWiki accessMode in owner and admin team", v1_20.FixExternalTrackerAndExternalWikiAccessModeInOwnerAndAdminTeam),
488488
// v254 -> v255
489489
NewMigration("Add ActionTaskOutput table", v1_20.AddActionTaskOutputTable),
490+
// v255 -> v256
491+
NewMigration("Add ArchivedUnix Column", v1_20.AddArchivedUnixToRepository),
490492
}
491493

492494
// GetCurrentDBVersion returns the current db version

models/migrations/v1_20/v255.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_20 //nolint
5+
6+
import (
7+
"code.gitea.io/gitea/modules/timeutil"
8+
9+
"xorm.io/xorm"
10+
)
11+
12+
func AddArchivedUnixToRepository(x *xorm.Engine) error {
13+
type Repository struct {
14+
ArchivedUnix timeutil.TimeStamp `xorm:"DEFAULT 0"`
15+
}
16+
17+
if err := x.Sync(new(Repository)); err != nil {
18+
return err
19+
}
20+
21+
_, err := x.Exec("UPDATE repository SET archived_unix = updated_unix WHERE is_archived = ? AND archived_unix = 0", true)
22+
return err
23+
}

models/repo/archiver.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@ func FindRepoArchives(opts FindRepoArchiversOption) ([]*RepoArchiver, error) {
146146
// SetArchiveRepoState sets if a repo is archived
147147
func SetArchiveRepoState(repo *Repository, isArchived bool) (err error) {
148148
repo.IsArchived = isArchived
149-
_, err = db.GetEngine(db.DefaultContext).Where("id = ?", repo.ID).Cols("is_archived").NoAutoTime().Update(repo)
149+
150+
if isArchived {
151+
repo.ArchivedUnix = timeutil.TimeStampNow()
152+
} else {
153+
repo.ArchivedUnix = timeutil.TimeStamp(0)
154+
}
155+
156+
_, err = db.GetEngine(db.DefaultContext).ID(repo.ID).Cols("is_archived", "archived_unix").NoAutoTime().Update(repo)
150157
return err
151158
}

models/repo/repo.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,9 @@ type Repository struct {
174174
// Avatar: ID(10-20)-md5(32) - must fit into 64 symbols
175175
Avatar string `xorm:"VARCHAR(64)"`
176176

177-
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
178-
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
177+
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
178+
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
179+
ArchivedUnix timeutil.TimeStamp `xorm:"DEFAULT 0"`
179180
}
180181

181182
func init() {

modules/structs/repo.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ type Repository struct {
8080
Created time.Time `json:"created_at"`
8181
// swagger:strfmt date-time
8282
Updated time.Time `json:"updated_at"`
83+
ArchivedAt time.Time `json:"archived_at"`
8384
Permissions *Permission `json:"permissions,omitempty"`
8485
HasIssues bool `json:"has_issues"`
8586
InternalTracker *InternalTracker `json:"internal_tracker,omitempty"`

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,7 @@ template.one_item = Must select at least one template item
992992
template.invalid = Must select a template repository
993993
994994
archive.title = This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
995+
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.
995996
archive.issue.nocomment = This repo is archived. You cannot comment on issues.
996997
archive.pull.nocomment = This repo is archived. You cannot comment on pull requests.
997998

services/convert/repository.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ func innerToRepo(ctx context.Context, repo *repo_model.Repository, mode perm.Acc
183183
DefaultBranch: repo.DefaultBranch,
184184
Created: repo.CreatedUnix.AsTime(),
185185
Updated: repo.UpdatedUnix.AsTime(),
186+
ArchivedAt: repo.ArchivedUnix.AsTime(),
186187
Permissions: permission,
187188
HasIssues: hasIssues,
188189
ExternalTracker: externalTracker,

templates/repo/diff/compare.tmpl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,11 @@
219219
</div>
220220
{{else if .Repository.IsArchived}}
221221
<div class="ui warning message">
222-
{{.locale.Tr "repo.archive.title"}}
222+
{{if .Repository.ArchivedUnix.IsZero}}
223+
{{.locale.Tr "repo.archive.title"}}
224+
{{else}}
225+
{{.locale.Tr "repo.archive.title_date" (DateTime "long" .Repository.ArchivedUnix) | Safe}}
226+
{{end}}
223227
</div>
224228
{{end}}
225229
{{if $.IsSigned}}

templates/repo/empty.tmpl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
{{template "base/alert" .}}
88
{{if .Repository.IsArchived}}
99
<div class="ui warning message">
10-
{{.locale.Tr "repo.archive.title"}}
10+
{{if .Repository.ArchivedUnix.IsZero}}
11+
{{.locale.Tr "repo.archive.title"}}
12+
{{else}}
13+
{{.locale.Tr "repo.archive.title_date" (DateTime "long" .Repository.ArchivedUnix) | Safe}}
14+
{{end}}
1115
</div>
1216
{{end}}
1317
{{if .Repository.IsBroken}}

templates/repo/home.tmpl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@
5353
{{end}}
5454
{{if .Repository.IsArchived}}
5555
<div class="ui warning message">
56-
{{.locale.Tr "repo.archive.title"}}
56+
{{if .Repository.ArchivedUnix.IsZero}}
57+
{{.locale.Tr "repo.archive.title"}}
58+
{{else}}
59+
{{.locale.Tr "repo.archive.title_date" (DateTime "long" .Repository.ArchivedUnix) | Safe}}
60+
{{end}}
5761
</div>
5862
{{end}}
5963
{{template "repo/sub_menu" .}}

templates/swagger/v1_json.tmpl

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)