Skip to content

Commit 16a96f3

Browse files
committed
Rebased to gitea-master
1 parent 513db27 commit 16a96f3

File tree

12 files changed

+139
-4
lines changed

12 files changed

+139
-4
lines changed

models/repo.go

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,9 @@ type Repository struct {
185185
NumOpenMilestones int `xorm:"-"`
186186
NumReleases int `xorm:"-"`
187187

188-
IsPrivate bool `xorm:"INDEX"`
189-
IsBare bool `xorm:"INDEX"`
188+
IsPrivate bool `xorm:"INDEX"`
189+
IsBare bool `xorm:"INDEX"`
190+
IsArchived bool `xorm:"INDEX"`
190191

191192
IsMirror bool `xorm:"INDEX"`
192193
*Mirror `xorm:"-"`
@@ -290,6 +291,7 @@ func (repo *Repository) innerAPIFormat(mode AccessMode, isParent bool) *api.Repo
290291
FullName: repo.FullName(),
291292
Description: repo.Description,
292293
Private: repo.IsPrivate,
294+
Archived: repo.IsArchived,
293295
Empty: repo.IsBare,
294296
Size: int(repo.Size / 1024),
295297
Fork: repo.IsFork,
@@ -2389,6 +2391,36 @@ func CheckRepoStats() {
23892391
// ***** END: Repository.NumForks *****
23902392
}
23912393

2394+
// ToggleArchiveRepo changes the status if a repo is archived or not
2395+
func (repo *Repository) ToggleArchiveRepo() (err error) {
2396+
repo.IsArchived = !repo.IsArchived
2397+
_, err = x.Where("id = ?", repo.ID).Cols("is_archived").Update(repo)
2398+
2399+
// Enable/Disable issues and pull requests
2400+
if repo.IsArchived {
2401+
if _, err = x.
2402+
Where("repo_id = ? AND (type = ? OR type = ?)", repo.ID, UnitTypeIssues, UnitTypePullRequests).
2403+
Delete(new(RepoUnit)); err != nil {
2404+
return err
2405+
}
2406+
} else {
2407+
var units []RepoUnit
2408+
units = append(units, RepoUnit{
2409+
RepoID: repo.ID,
2410+
Type: UnitTypeIssues,
2411+
})
2412+
units = append(units, RepoUnit{
2413+
RepoID: repo.ID,
2414+
Type: UnitTypePullRequests,
2415+
})
2416+
2417+
if _, err = x.Insert(units); err != nil {
2418+
return err
2419+
}
2420+
}
2421+
return
2422+
}
2423+
23922424
// ___________ __
23932425
// \_ _____/__________| | __
23942426
// | __)/ _ \_ __ \ |/ /

modules/auth/repo_form.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ type RepoSettingForm struct {
116116
EnableTimetracker bool
117117
AllowOnlyContributorsToTrackTime bool
118118
EnableIssueDependencies bool
119+
IsArchived bool
119120

120121
// Admin settings
121122
EnableHealthCheck bool

options/locale/locale_en-US.ini

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,8 @@ forks = Forks
529529
pick_reaction = Pick your reaction
530530
reactions_more = and %d more
531531
532+
archive.title = This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
533+
532534
form.reach_limit_of_creation = You have already reached your limit of %d repositories.
533535
form.name_reserved = The repository name '%s' is reserved.
534536
form.name_pattern_not_allowed = The pattern '%s' is not allowed in a repository name.
@@ -1150,6 +1152,14 @@ settings.default_branch_desc = Select a default repository branch for pull reque
11501152
settings.choose_branch = Choose a branch…
11511153
settings.no_protected_branch = There are no protected branches.
11521154
settings.edit_protected_branch = Edit
1155+
settings.archive.button = Archive repo
1156+
settings.archive.header = Archive this repo
1157+
settings.archive.text = Archiving the repo will make it entirely read-only. It is hidden from the dashboard, cannot be committed to and no issues or pull-requests can be created.
1158+
settings.archive.success = The repo was successfully archived.
1159+
settings.unarchive.button = Un-Archive repo
1160+
settings.unarchive.header = Un-Archive this repo
1161+
settings.unarchive.text = Un-Archiving the repo will restore its ability to recieve commits and pushes, as well as new issues and pull-requests.
1162+
settings.unarchive.success = The repo was successfully un-archived.
11531163
11541164
diff.browse_source = Browse Source
11551165
diff.parent = parent

public/css/index.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/less/_base.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,3 +588,7 @@ footer {
588588
border-bottom-width: 0 !important;
589589
margin-bottom: 2px !important;
590590
}
591+
592+
.archived-icon{
593+
color: lighten(#000, 70%) !important;
594+
}

routers/repo/http.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ func HTTP(ctx *context.Context) {
7171
return
7272
}
7373

74+
// Don't allow pushing if the repo is archived
75+
if repo.IsArchived && !isPull {
76+
ctx.HandleText(http.StatusForbidden, "This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.")
77+
return
78+
}
79+
7480
// Only public pull don't need auth.
7581
isPublicPull := !repo.IsPrivate && isPull
7682
var (

routers/repo/setting.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,27 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
349349
ctx.Flash.Success(ctx.Tr("repo.settings.wiki_deletion_success"))
350350
ctx.Redirect(ctx.Repo.RepoLink + "/settings")
351351

352+
case "archive":
353+
if !ctx.Repo.IsOwner() {
354+
ctx.Error(403)
355+
return
356+
}
357+
if err := repo.ToggleArchiveRepo(); err != nil {
358+
log.Error(4, "Tried to archive a repo: %s", err)
359+
ctx.Error(500)
360+
ctx.Redirect(ctx.Repo.RepoLink + "/settings")
361+
return
362+
}
363+
364+
log.Trace("Repository was archived: %s/%s", ctx.Repo.Owner.Name, repo.Name)
365+
366+
if repo.IsArchived {
367+
ctx.Flash.Success(ctx.Tr("repo.settings.archive.success"))
368+
} else {
369+
ctx.Flash.Success(ctx.Tr("repo.settings.unarchive.success"))
370+
}
371+
ctx.Redirect(ctx.Repo.RepoLink + "/settings")
372+
352373
default:
353374
ctx.NotFound("", nil)
354375
}

templates/explore/repo_list.tmpl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
{{range .Repos}}
33
<div class="item">
44
<div class="ui header">
5-
<a class="name" href="{{.Link}}">{{if or $.PageIsExplore $.PageIsProfileStarList }}{{if .Owner}}{{.Owner.Name}} / {{end}}{{end}}{{.Name}}</a>
5+
<a class="name" href="{{.Link}}">
6+
{{if or $.PageIsExplore $.PageIsProfileStarList }}{{if .Owner}}{{.Owner.Name}} / {{end}}{{end}}{{.Name}}
7+
{{if .IsArchived}}<i class="archive icon archived-icon"></i>{{end}}
8+
</a>
69
{{if .IsPrivate}}
710
<span class="text gold"><i class="octicon octicon-lock"></i></span>
811
{{else if .IsFork}}

templates/repo/home.tmpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@
5050
<span id="count_prompt">{{.i18n.Tr "repo.topic.count_prompt"}}</span>
5151
<span id="format_prompt">{{.i18n.Tr "repo.topic.format_prompt"}}</span>
5252
</div>
53+
{{if .Repository.IsArchived}}
54+
<div class="ui warning message">
55+
{{.i18n.Tr "repo.archive.title"}}
56+
</div>
57+
{{end}}
5358
{{template "repo/sub_menu" .}}
5459
<div class="ui stackable secondary menu mobile--margin-between-items mobile--no-negative-margins">
5560
{{if and .PullRequestCtx.Allowed .IsViewBranch}}

templates/repo/settings/options.tmpl

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,29 @@
319319
<p>{{.i18n.Tr "repo.settings.delete_desc"}}</p>
320320
</div>
321321
</div>
322+
323+
<div class="ui divider"></div>
324+
325+
<div class="item">
326+
<div class="ui right">
327+
<button class="ui basic red show-modal button" data-modal="#archive-repo-modal">
328+
{{if .Repository.IsArchived}}
329+
{{.i18n.Tr "repo.settings.unarchive.button"}}
330+
{{else}}
331+
{{.i18n.Tr "repo.settings.archive.button"}}
332+
{{end}}
333+
</button>
334+
</div>
335+
<div>
336+
{{if .Repository.IsArchived}}
337+
<h5>{{.i18n.Tr "repo.settings.unarchive.header"}}</h5>
338+
<p>{{.i18n.Tr "repo.settings.unarchive.text"}}</p>
339+
{{else}}
340+
<h5>{{.i18n.Tr "repo.settings.archive.header"}}</h5>
341+
<p>{{.i18n.Tr "repo.settings.archive.text"}}</p>
342+
{{end}}
343+
</div>
344+
</div>
322345
</div>
323346
{{end}}
324347
</div>
@@ -458,6 +481,34 @@
458481
</div>
459482
</div>
460483
{{end}}
484+
485+
<div class="ui basic modal" id="archive-repo-modal">
486+
<div class="ui icon header">
487+
{{if .Repository.IsArchived}}
488+
{{.i18n.Tr "repo.settings.unarchive.header"}}
489+
{{else}}
490+
{{.i18n.Tr "repo.settings.archive.header"}}
491+
{{end}}
492+
</div>
493+
<div class="content center">
494+
<p>
495+
{{if .Repository.IsArchived}}
496+
{{.i18n.Tr "repo.settings.unarchive.text"}}
497+
{{else}}
498+
{{.i18n.Tr "repo.settings.archive.text"}}
499+
{{end}}
500+
</p>
501+
</div>
502+
<form action="{{.Link}}" method="post">
503+
{{.CsrfTokenHtml}}
504+
<input type="hidden" name="action" value="archive">
505+
<input type="hidden" name="repo_id" value="{{.Repository.ID}}">
506+
<div class="center actions">
507+
<div class="ui basic cancel inverted button">{{.i18n.Tr "settings.cancel"}}</div>
508+
<button class="ui basic inverted yellow button">{{.i18n.Tr "modal.yes"}}</button>
509+
</div>
510+
</form>
511+
</div>
461512
{{end}}
462513

463514
{{template "base/footer" .}}

templates/user/dashboard/dashboard.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
<a :href="suburl + '/' + repo.full_name">
7676
<i :class="repoClass(repo)"></i>
7777
<strong class="text truncate item-name">${repo.full_name}</strong>
78+
<i v-if="repo.archived" class="archive icon archived-icon"></i>
7879
<span class="ui right text light grey">
7980
${repo.stars_count} <i class="octicon octicon-star rear"></i>
8081
</span>

vendor/code.gitea.io/sdk/gitea/repo.go

Lines changed: 1 addition & 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)