Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide option to unlink a fork #11858

Merged
merged 9 commits into from
Jul 2, 2020
12 changes: 1 addition & 11 deletions models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,19 +208,9 @@ func (repo *Repository) SanitizedOriginalURL() string {

// ColorFormat returns a colored string to represent this repo
func (repo *Repository) ColorFormat(s fmt.State) {
var ownerName interface{}

if repo.OwnerName != "" {
ownerName = repo.OwnerName
} else if repo.Owner != nil {
ownerName = repo.Owner.Name
} else {
ownerName = log.NewColoredIDValue(strconv.FormatInt(repo.OwnerID, 10))
}

log.ColorFprintf(s, "%d:%s/%s",
log.NewColoredIDValue(repo.ID),
ownerName,
repo.OwnerName,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This set of changes just tidies up this function since we changed to always store the OwnerName

repo.Name)
}

Expand Down
5 changes: 5 additions & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1372,6 +1372,11 @@ settings.convert_desc = You can convert this mirror into a regular repository. T
settings.convert_notices_1 = This operation will convert the mirror into a regular repository and cannot be undone.
settings.convert_confirm = Convert Repository
settings.convert_succeed = The mirror has been converted into a regular repository.
settings.convert_fork = Convert to Regular Repository
settings.convert_fork_desc = You can convert this fork into a regular repository. This cannot be undone.
settings.convert_fork_notices_1 = This operation will convert the mirror into a regular repository and cannot be undone.
zeripath marked this conversation as resolved.
Show resolved Hide resolved
settings.convert_fork_confirm = Convert Repository
settings.convert_fork_succeed = The mirror has been converted into a regular repository.
zeripath marked this conversation as resolved.
Show resolved Hide resolved
settings.transfer = Transfer Ownership
settings.transfer_desc = Transfer this repository to a user or to an organization for which you have administrator rights.
settings.transfer_notices_1 = - You will lose access to the repository if you transfer it to an individual user.
Expand Down
30 changes: 28 additions & 2 deletions routers/repo/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,35 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
ctx.ServerError("DeleteMirrorByRepoID", err)
return
}
log.Trace("Repository converted from mirror to regular: %s/%s", ctx.Repo.Owner.Name, repo.Name)
log.Trace("Repository converted from mirror to regular: %s", repo.FullName())
ctx.Flash.Success(ctx.Tr("repo.settings.convert_succeed"))
ctx.Redirect(setting.AppSubURL + "/" + ctx.Repo.Owner.Name + "/" + repo.Name)
ctx.Redirect(repo.Link())

case "convert_fork":
if !ctx.Repo.IsOwner() {
ctx.Error(404)
return
}
if repo.Name != form.RepoName {
ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_repo_name"), tplSettingsOptions, nil)
return
}

if !repo.IsFork {
ctx.Error(404)
return
}
repo.IsFork = false
repo.ForkID = 0
if err := models.UpdateRepository(repo, false); err != nil {
log.Error("Unable to update repository %-v whilst converting from fork", repo)
ctx.ServerError("Convert Fork", err)
return
}

log.Trace("Repository converted from fork to regular: %s", repo.FullName())
ctx.Flash.Success(ctx.Tr("repo.settings.convert_fork_succeed"))
ctx.Redirect(repo.Link())

case "transfer":
if !ctx.Repo.IsOwner() {
Expand Down
109 changes: 75 additions & 34 deletions templates/repo/settings/options.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -358,17 +358,28 @@
</h4>
<div class="ui attached warning table danger segment">
{{if .Repository.IsMirror}}
<div class="item">
<div class="ui right">
<button class="ui basic red show-modal button" data-modal="#convert-repo-modal">{{.i18n.Tr "repo.settings.convert"}}</button>
<div class="item">
<div class="ui right">
<button class="ui basic red show-modal button" data-modal="#convert-repo-modal">{{.i18n.Tr "repo.settings.convert"}}</button>
</div>
<div>
<h5>{{.i18n.Tr "repo.settings.convert"}}</h5>
<p>{{.i18n.Tr "repo.settings.convert_desc"}}</p>
</div>
</div>
<div>
<h5>{{.i18n.Tr "repo.settings.convert"}}</h5>
<p>{{.i18n.Tr "repo.settings.convert_desc"}}</p>
<div class="ui divider"></div>
{{end}}
{{if .Repository.IsFork}}
<div class="item">
<div class="ui right">
<button class="ui basic red show-modal button" data-modal="#convert-fork-repo-modal">{{.i18n.Tr "repo.settings.convert_fork"}}</button>
</div>
<div>
<h5>{{.i18n.Tr "repo.settings.convert_fork"}}</h5>
<p>{{.i18n.Tr "repo.settings.convert_fork_desc"}}</p>
</div>
</div>
</div>

<div class="ui divider"></div>
<div class="ui divider"></div>
{{end}}
<div class="item">
<div class="ui right">
Expand Down Expand Up @@ -437,37 +448,67 @@

{{if .Permission.IsOwner}}
{{if .Repository.IsMirror}}
<div class="ui small modal" id="convert-repo-modal">
<div class="header">
{{.i18n.Tr "repo.settings.convert"}}
</div>
<div class="content">
<div class="ui warning message text left">
{{.i18n.Tr "repo.settings.convert_notices_1"}}
<div class="ui small modal" id="convert-repo-modal">
<div class="header">
{{.i18n.Tr "repo.settings.convert"}}
</div>
<form class="ui form" action="{{.Link}}" method="post">
{{.CsrfTokenHtml}}
<input type="hidden" name="action" value="convert">
<div class="field">
<label>
{{.i18n.Tr "repo.settings.transfer_form_title"}}
<span class="text red">{{.Repository.Name}}</span>
</label>
</div>
<div class="required field">
<label for="repo_name">{{.i18n.Tr "repo.repo_name"}}</label>
<input id="repo_name" name="repo_name" required>
<div class="content">
<div class="ui warning message text left">
{{.i18n.Tr "repo.settings.convert_notices_1"}}
</div>
<form class="ui form" action="{{.Link}}" method="post">
{{.CsrfTokenHtml}}
<input type="hidden" name="action" value="convert">
<div class="field">
<label>
{{.i18n.Tr "repo.settings.transfer_form_title"}}
<span class="text red">{{.Repository.Name}}</span>
</label>
</div>
<div class="required field">
<label for="repo_name">{{.i18n.Tr "repo.repo_name"}}</label>
<input id="repo_name" name="repo_name" required>
</div>

<div class="text right actions">
<div class="ui cancel button">{{.i18n.Tr "settings.cancel"}}</div>
<button class="ui red button">{{.i18n.Tr "repo.settings.convert_confirm"}}</button>
</div>
</form>
<div class="text right actions">
<div class="ui cancel button">{{.i18n.Tr "settings.cancel"}}</div>
<button class="ui red button">{{.i18n.Tr "repo.settings.convert_confirm"}}</button>
</div>
</form>
</div>
</div>
</div>
{{end}}
{{if .Repository.IsFork}}
<div class="ui small modal" id="convert-fork-repo-modal">
<div class="header">
{{.i18n.Tr "repo.settings.convert_fork"}}
</div>
<div class="content">
<div class="ui warning message text left">
{{.i18n.Tr "repo.settings.convert_fork_notices_1"}}
</div>
<form class="ui form" action="{{.Link}}" method="post">
{{.CsrfTokenHtml}}
<input type="hidden" name="action" value="convert_fork">
<div class="field">
<label>
{{.i18n.Tr "repo.settings.transfer_form_title"}}
<span class="text red">{{.Repository.Name}}</span>
</label>
</div>
<div class="required field">
<label for="repo_name">{{.i18n.Tr "repo.repo_name"}}</label>
<input id="repo_name" name="repo_name" required>
</div>

<div class="text right actions">
<div class="ui cancel button">{{.i18n.Tr "settings.cancel"}}</div>
<button class="ui red button">{{.i18n.Tr "repo.settings.convert_fork_confirm"}}</button>
</div>
</form>
</div>
</div>
{{end}}
<div class="ui small modal" id="transfer-repo-modal">
<div class="header">
{{.i18n.Tr "repo.settings.transfer"}}
Expand Down