@@ -830,10 +830,11 @@ func RetrieveRepoMetas(ctx *context.Context, repo *repo_model.Repository, isPull
830830 return labels
831831}
832832
833- func setTemplateIfExists (ctx * context.Context , ctxDataKey string , possibleFiles []string ) map [string ]error {
833+ // Tries to load and set an issue template. The first return value indicates if a template was loaded.
834+ func setTemplateIfExists (ctx * context.Context , ctxDataKey string , possibleFiles []string ) (bool , map [string ]error ) {
834835 commit , err := ctx .Repo .GitRepo .GetBranchCommit (ctx .Repo .Repository .DefaultBranch )
835836 if err != nil {
836- return nil
837+ return false , nil
837838 }
838839
839840 templateCandidates := make ([]string , 0 , 1 + len (possibleFiles ))
@@ -896,20 +897,15 @@ func setTemplateIfExists(ctx *context.Context, ctxDataKey string, possibleFiles
896897 ctx .Data ["label_ids" ] = strings .Join (labelIDs , "," )
897898 ctx .Data ["Reference" ] = template .Ref
898899 ctx .Data ["RefEndName" ] = git .RefName (template .Ref ).ShortName ()
899- return templateErrs
900+ return true , templateErrs
900901 }
901- return templateErrs
902+ return false , templateErrs
902903}
903904
904905// NewIssue render creating issue page
905906func NewIssue (ctx * context.Context ) {
906907 issueConfig , _ := issue_service .GetTemplateConfigFromDefaultBranch (ctx .Repo .Repository , ctx .Repo .GitRepo )
907908 hasTemplates := issue_service .HasTemplatesOrContactLinks (ctx .Repo .Repository , ctx .Repo .GitRepo )
908- if ! issueConfig .BlankIssuesEnabled && hasTemplates {
909- // The "issues/new" and "issues/new/choose" share the same query parameters "project" and "milestone", if blank issues are disabled, just redirect to the "issues/choose" page with these parameters.
910- ctx .Redirect (fmt .Sprintf ("%s/issues/new/choose?%s" , ctx .Repo .Repository .Link (), ctx .Req .URL .RawQuery ), http .StatusSeeOther )
911- return
912- }
913909
914910 ctx .Data ["Title" ] = ctx .Tr ("repo.issues.new" )
915911 ctx .Data ["PageIsIssueList" ] = true
@@ -963,7 +959,8 @@ func NewIssue(ctx *context.Context) {
963959 ctx .Data ["Tags" ] = tags
964960
965961 _ , templateErrs := issue_service .GetTemplatesFromDefaultBranch (ctx .Repo .Repository , ctx .Repo .GitRepo )
966- if errs := setTemplateIfExists (ctx , issueTemplateKey , IssueTemplateCandidates ); len (errs ) > 0 {
962+ templateLoaded , errs := setTemplateIfExists (ctx , issueTemplateKey , IssueTemplateCandidates )
963+ if len (errs ) > 0 {
967964 for k , v := range errs {
968965 templateErrs [k ] = v
969966 }
@@ -978,6 +975,12 @@ func NewIssue(ctx *context.Context) {
978975
979976 ctx .Data ["HasIssuesOrPullsWritePermission" ] = ctx .Repo .CanWrite (unit .TypeIssues )
980977
978+ if ! issueConfig .BlankIssuesEnabled && hasTemplates && ! templateLoaded {
979+ // The "issues/new" and "issues/new/choose" share the same query parameters "project" and "milestone", if blank issues are disabled, just redirect to the "issues/choose" page with these parameters.
980+ ctx .Redirect (fmt .Sprintf ("%s/issues/new/choose?%s" , ctx .Repo .Repository .Link (), ctx .Req .URL .RawQuery ), http .StatusSeeOther )
981+ return
982+ }
983+
981984 ctx .HTML (http .StatusOK , tplIssueNew )
982985}
983986
0 commit comments