Find(&labels)
}
-// GetLabelsByRepoID returns all labels that belong to given repository by ID.
-func GetLabelsByRepoID(repoID int64, sortType string) ([]*Label, error) {
+func getLabelsByRepoID(e Engine, repoID int64, sortType string) ([]*Label, error) {
labels := make([]*Label, 0, 10)
- sess := x.Where("repo_id = ?", repoID)
+ sess := e.Where("repo_id = ?", repoID)
switch sortType {
case "reversealphabetically":
return labels, sess.Find(&labels)
}
+// GetLabelsByRepoID returns all labels that belong to given repository by ID.
+func GetLabelsByRepoID(repoID int64, sortType string) ([]*Label, error) {
+ return getLabelsByRepoID(x, repoID, sortType)
+}
+
func getLabelsByIssueID(e Engine, issueID int64) ([]*Label, error) {
var labels []*Label
return labels, e.Where("issue_label.issue_id = ?", issueID).
Status RepositoryStatus
}
-// GenerateRepoOptions contains the template units to generate
-type GenerateRepoOptions struct {
- Name string
- Description string
- Private bool
- GitContent bool
- Topics bool
- GitHooks bool
- Webhooks bool
-}
-
-// IsValid checks whether at least one option is chosen for generation
-func (gro GenerateRepoOptions) IsValid() bool {
- return gro.GitContent || gro.Topics || gro.GitHooks || gro.Webhooks // or other items as they are added
-}
-
func getRepoInitFile(tp, name string) ([]byte, error) {
cleanedName := strings.TrimLeft(path.Clean("/"+name), "/")
relPath := path.Join("options", tp, cleanedName)
return nil, nil
}
+func updateRepositoryCols(e Engine, repo *Repository, cols ...string) error {
+ _, err := e.ID(repo.ID).Cols(cols...).Update(repo)
+ return err
+}
+
// UpdateRepositoryCols updates repository's columns
func UpdateRepositoryCols(repo *Repository, cols ...string) error {
- _, err := x.ID(repo.ID).Cols(cols...).Update(repo)
- return err
+ return updateRepositoryCols(x, repo, cols...)
}
"fmt"
"os"
"path/filepath"
+ "strconv"
"strings"
"time"
"github.com/unknwon/com"
)
+// GenerateRepoOptions contains the template units to generate
+type GenerateRepoOptions struct {
+ Name string
+ Description string
+ Private bool
+ GitContent bool
+ Topics bool
+ GitHooks bool
+ Webhooks bool
+ Avatar bool
+ IssueLabels bool
+}
+
+// IsValid checks whether at least one option is chosen for generation
+func (gro GenerateRepoOptions) IsValid() bool {
+ return gro.GitContent || gro.Topics || gro.GitHooks || gro.Webhooks || gro.Avatar || gro.IssueLabels // or other items as they are added
+}
+
// generateRepository initializes repository from template
func generateRepository(e Engine, repo, templateRepo *Repository) (err error) {
tmpDir := filepath.Join(os.TempDir(), "gitea-"+repo.Name+"-"+com.ToStr(time.Now().Nanosecond()))
}
return nil
}
+
+// GenerateAvatar generates the avatar from a template repository
+func GenerateAvatar(ctx DBContext, templateRepo, generateRepo *Repository) error {
+ generateRepo.Avatar = strings.Replace(templateRepo.Avatar, strconv.FormatInt(templateRepo.ID, 10), strconv.FormatInt(generateRepo.ID, 10), 1)
+ if err := com.Copy(templateRepo.CustomAvatarPath(), generateRepo.CustomAvatarPath()); err != nil {
+ return err
+ }
+
+ return updateRepositoryCols(ctx.e, generateRepo, "avatar")
+}
+
+// GenerateIssueLabels generates issue labels from a template repository
+func GenerateIssueLabels(ctx DBContext, templateRepo, generateRepo *Repository) error {
+ templateLabels, err := getLabelsByRepoID(ctx.e, templateRepo.ID, "")
+ if err != nil {
+ return err
+ }
+
+ for _, templateLabel := range templateLabels {
+ generateLabel := &Label{
+ RepoID: generateRepo.ID,
+ Name: templateLabel.Name,
+ Description: templateLabel.Description,
+ Color: templateLabel.Color,
+ }
+ if err := newLabel(ctx.e, generateLabel); err != nil {
+ return err
+ }
+ }
+ return nil
+}
Topics bool
GitHooks bool
Webhooks bool
+ Avatar bool
+ Labels bool
}
// Validate validates the fields
template.git_hooks_tooltip = You are currently unable to modify or remove git hooks once added. Select this only if you trust the template repository.
template.webhooks = Webhooks
template.topics = Topics
+template.avatar = Avatar
+template.issue_labels = Issue Labels
template.one_item = Must select at least one template item
template.invalid = Must select a template repository
Topics: form.Topics,
GitHooks: form.GitHooks,
Webhooks: form.Webhooks,
+ Avatar: form.Avatar,
+ IssueLabels: form.Labels,
}
if !opts.IsValid() {
}
}
+ // Avatar
+ if opts.Avatar && len(templateRepo.Avatar) > 0 {
+ if err = models.GenerateAvatar(ctx, templateRepo, generateRepo); err != nil {
+ return err
+ }
+ }
+
+ // Issue Labels
+ if opts.IssueLabels {
+ if err = models.GenerateIssueLabels(ctx, templateRepo, generateRepo); err != nil {
+ return err
+ }
+ }
+
return nil
}); err != nil {
if generateRepo != nil {
<label>{{.i18n.Tr "repo.template.topics"}}</label>
</div>
</div>
+ <div class="inline field">
+ <label></label>
+ <div class="ui checkbox">
+ <input class="hidden" name="avatar" type="checkbox" tabindex="0" {{if .avatar}}checked{{end}}>
+ <label>{{.i18n.Tr "repo.template.avatar"}}</label>
+ </div>
+ <div class="ui checkbox">
+ <input class="hidden" name="labels" type="checkbox" tabindex="0" {{if .labels}}checked{{end}}>
+ <label>{{.i18n.Tr "repo.template.issue_labels"}}</label>
+ </div>
+ </div>
</div>
<div id="non_template">