Skip to content

Commit

Permalink
Rebased to gitea-master
Browse files Browse the repository at this point in the history
  • Loading branch information
kolaente committed Oct 3, 2018
1 parent 513db27 commit 16a96f3
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 4 deletions.
36 changes: 34 additions & 2 deletions models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,9 @@ type Repository struct {
NumOpenMilestones int `xorm:"-"`
NumReleases int `xorm:"-"`

IsPrivate bool `xorm:"INDEX"`
IsBare bool `xorm:"INDEX"`
IsPrivate bool `xorm:"INDEX"`
IsBare bool `xorm:"INDEX"`
IsArchived bool `xorm:"INDEX"`

IsMirror bool `xorm:"INDEX"`
*Mirror `xorm:"-"`
Expand Down Expand Up @@ -290,6 +291,7 @@ func (repo *Repository) innerAPIFormat(mode AccessMode, isParent bool) *api.Repo
FullName: repo.FullName(),
Description: repo.Description,
Private: repo.IsPrivate,
Archived: repo.IsArchived,
Empty: repo.IsBare,
Size: int(repo.Size / 1024),
Fork: repo.IsFork,
Expand Down Expand Up @@ -2389,6 +2391,36 @@ func CheckRepoStats() {
// ***** END: Repository.NumForks *****
}

// ToggleArchiveRepo changes the status if a repo is archived or not
func (repo *Repository) ToggleArchiveRepo() (err error) {
repo.IsArchived = !repo.IsArchived
_, err = x.Where("id = ?", repo.ID).Cols("is_archived").Update(repo)

// Enable/Disable issues and pull requests
if repo.IsArchived {
if _, err = x.
Where("repo_id = ? AND (type = ? OR type = ?)", repo.ID, UnitTypeIssues, UnitTypePullRequests).
Delete(new(RepoUnit)); err != nil {
return err
}
} else {
var units []RepoUnit
units = append(units, RepoUnit{
RepoID: repo.ID,
Type: UnitTypeIssues,
})
units = append(units, RepoUnit{
RepoID: repo.ID,
Type: UnitTypePullRequests,
})

if _, err = x.Insert(units); err != nil {
return err
}
}
return
}

// ___________ __
// \_ _____/__________| | __
// | __)/ _ \_ __ \ |/ /
Expand Down
1 change: 1 addition & 0 deletions modules/auth/repo_form.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ type RepoSettingForm struct {
EnableTimetracker bool
AllowOnlyContributorsToTrackTime bool
EnableIssueDependencies bool
IsArchived bool

// Admin settings
EnableHealthCheck bool
Expand Down
10 changes: 10 additions & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,8 @@ forks = Forks
pick_reaction = Pick your reaction
reactions_more = and %d more
archive.title = This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
form.reach_limit_of_creation = You have already reached your limit of %d repositories.
form.name_reserved = The repository name '%s' is reserved.
form.name_pattern_not_allowed = The pattern '%s' is not allowed in a repository name.
Expand Down Expand Up @@ -1150,6 +1152,14 @@ settings.default_branch_desc = Select a default repository branch for pull reque
settings.choose_branch = Choose a branch…
settings.no_protected_branch = There are no protected branches.
settings.edit_protected_branch = Edit
settings.archive.button = Archive repo
settings.archive.header = Archive this repo
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.
settings.archive.success = The repo was successfully archived.
settings.unarchive.button = Un-Archive repo
settings.unarchive.header = Un-Archive this repo
settings.unarchive.text = Un-Archiving the repo will restore its ability to recieve commits and pushes, as well as new issues and pull-requests.
settings.unarchive.success = The repo was successfully un-archived.
diff.browse_source = Browse Source
diff.parent = parent
Expand Down
2 changes: 1 addition & 1 deletion public/css/index.css

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions public/less/_base.less
Original file line number Diff line number Diff line change
Expand Up @@ -588,3 +588,7 @@ footer {
border-bottom-width: 0 !important;
margin-bottom: 2px !important;
}

.archived-icon{
color: lighten(#000, 70%) !important;
}
6 changes: 6 additions & 0 deletions routers/repo/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ func HTTP(ctx *context.Context) {
return
}

// Don't allow pushing if the repo is archived
if repo.IsArchived && !isPull {
ctx.HandleText(http.StatusForbidden, "This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.")
return
}

// Only public pull don't need auth.
isPublicPull := !repo.IsPrivate && isPull
var (
Expand Down
21 changes: 21 additions & 0 deletions routers/repo/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,27 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
ctx.Flash.Success(ctx.Tr("repo.settings.wiki_deletion_success"))
ctx.Redirect(ctx.Repo.RepoLink + "/settings")

case "archive":
if !ctx.Repo.IsOwner() {
ctx.Error(403)
return
}
if err := repo.ToggleArchiveRepo(); err != nil {
log.Error(4, "Tried to archive a repo: %s", err)
ctx.Error(500)
ctx.Redirect(ctx.Repo.RepoLink + "/settings")
return
}

log.Trace("Repository was archived: %s/%s", ctx.Repo.Owner.Name, repo.Name)

if repo.IsArchived {
ctx.Flash.Success(ctx.Tr("repo.settings.archive.success"))
} else {
ctx.Flash.Success(ctx.Tr("repo.settings.unarchive.success"))
}
ctx.Redirect(ctx.Repo.RepoLink + "/settings")

default:
ctx.NotFound("", nil)
}
Expand Down
5 changes: 4 additions & 1 deletion templates/explore/repo_list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
{{range .Repos}}
<div class="item">
<div class="ui header">
<a class="name" href="{{.Link}}">{{if or $.PageIsExplore $.PageIsProfileStarList }}{{if .Owner}}{{.Owner.Name}} / {{end}}{{end}}{{.Name}}</a>
<a class="name" href="{{.Link}}">
{{if or $.PageIsExplore $.PageIsProfileStarList }}{{if .Owner}}{{.Owner.Name}} / {{end}}{{end}}{{.Name}}
{{if .IsArchived}}<i class="archive icon archived-icon"></i>{{end}}
</a>
{{if .IsPrivate}}
<span class="text gold"><i class="octicon octicon-lock"></i></span>
{{else if .IsFork}}
Expand Down
5 changes: 5 additions & 0 deletions templates/repo/home.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
<span id="count_prompt">{{.i18n.Tr "repo.topic.count_prompt"}}</span>
<span id="format_prompt">{{.i18n.Tr "repo.topic.format_prompt"}}</span>
</div>
{{if .Repository.IsArchived}}
<div class="ui warning message">
{{.i18n.Tr "repo.archive.title"}}
</div>
{{end}}
{{template "repo/sub_menu" .}}
<div class="ui stackable secondary menu mobile--margin-between-items mobile--no-negative-margins">
{{if and .PullRequestCtx.Allowed .IsViewBranch}}
Expand Down
51 changes: 51 additions & 0 deletions templates/repo/settings/options.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,29 @@
<p>{{.i18n.Tr "repo.settings.delete_desc"}}</p>
</div>
</div>

<div class="ui divider"></div>

<div class="item">
<div class="ui right">
<button class="ui basic red show-modal button" data-modal="#archive-repo-modal">
{{if .Repository.IsArchived}}
{{.i18n.Tr "repo.settings.unarchive.button"}}
{{else}}
{{.i18n.Tr "repo.settings.archive.button"}}
{{end}}
</button>
</div>
<div>
{{if .Repository.IsArchived}}
<h5>{{.i18n.Tr "repo.settings.unarchive.header"}}</h5>
<p>{{.i18n.Tr "repo.settings.unarchive.text"}}</p>
{{else}}
<h5>{{.i18n.Tr "repo.settings.archive.header"}}</h5>
<p>{{.i18n.Tr "repo.settings.archive.text"}}</p>
{{end}}
</div>
</div>
</div>
{{end}}
</div>
Expand Down Expand Up @@ -458,6 +481,34 @@
</div>
</div>
{{end}}

<div class="ui basic modal" id="archive-repo-modal">
<div class="ui icon header">
{{if .Repository.IsArchived}}
{{.i18n.Tr "repo.settings.unarchive.header"}}
{{else}}
{{.i18n.Tr "repo.settings.archive.header"}}
{{end}}
</div>
<div class="content center">
<p>
{{if .Repository.IsArchived}}
{{.i18n.Tr "repo.settings.unarchive.text"}}
{{else}}
{{.i18n.Tr "repo.settings.archive.text"}}
{{end}}
</p>
</div>
<form action="{{.Link}}" method="post">
{{.CsrfTokenHtml}}
<input type="hidden" name="action" value="archive">
<input type="hidden" name="repo_id" value="{{.Repository.ID}}">
<div class="center actions">
<div class="ui basic cancel inverted button">{{.i18n.Tr "settings.cancel"}}</div>
<button class="ui basic inverted yellow button">{{.i18n.Tr "modal.yes"}}</button>
</div>
</form>
</div>
{{end}}

{{template "base/footer" .}}
1 change: 1 addition & 0 deletions templates/user/dashboard/dashboard.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
<a :href="suburl + '/' + repo.full_name">
<i :class="repoClass(repo)"></i>
<strong class="text truncate item-name">${repo.full_name}</strong>
<i v-if="repo.archived" class="archive icon archived-icon"></i>
<span class="ui right text light grey">
${repo.stars_count} <i class="octicon octicon-star rear"></i>
</span>
Expand Down
1 change: 1 addition & 0 deletions vendor/code.gitea.io/sdk/gitea/repo.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 16a96f3

Please sign in to comment.