@@ -804,10 +804,11 @@ func RetrieveRepoMetas(ctx *context.Context, repo *repo_model.Repository, isPull
804
804
return labels
805
805
}
806
806
807
- func setTemplateIfExists (ctx * context.Context , ctxDataKey string , possibleFiles []string ) map [string ]error {
807
+ // Tries to load and set an issue template. The first return value indicates if a template was loaded.
808
+ func setTemplateIfExists (ctx * context.Context , ctxDataKey string , possibleFiles []string ) (bool , map [string ]error ) {
808
809
commit , err := ctx .Repo .GitRepo .GetBranchCommit (ctx .Repo .Repository .DefaultBranch )
809
810
if err != nil {
810
- return nil
811
+ return false , nil
811
812
}
812
813
813
814
templateCandidates := make ([]string , 0 , 1 + len (possibleFiles ))
@@ -870,20 +871,15 @@ func setTemplateIfExists(ctx *context.Context, ctxDataKey string, possibleFiles
870
871
ctx .Data ["label_ids" ] = strings .Join (labelIDs , "," )
871
872
ctx .Data ["Reference" ] = template .Ref
872
873
ctx .Data ["RefEndName" ] = git .RefName (template .Ref ).ShortName ()
873
- return templateErrs
874
+ return true , templateErrs
874
875
}
875
- return templateErrs
876
+ return false , templateErrs
876
877
}
877
878
878
879
// NewIssue render creating issue page
879
880
func NewIssue (ctx * context.Context ) {
880
881
issueConfig , _ := issue_service .GetTemplateConfigFromDefaultBranch (ctx .Repo .Repository , ctx .Repo .GitRepo )
881
882
hasTemplates := issue_service .HasTemplatesOrContactLinks (ctx .Repo .Repository , ctx .Repo .GitRepo )
882
- if ! issueConfig .BlankIssuesEnabled && hasTemplates {
883
- // 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.
884
- ctx .Redirect (fmt .Sprintf ("%s/issues/new/choose?%s" , ctx .Repo .Repository .Link (), ctx .Req .URL .RawQuery ), http .StatusSeeOther )
885
- return
886
- }
887
883
888
884
ctx .Data ["Title" ] = ctx .Tr ("repo.issues.new" )
889
885
ctx .Data ["PageIsIssueList" ] = true
@@ -930,7 +926,8 @@ func NewIssue(ctx *context.Context) {
930
926
RetrieveRepoMetas (ctx , ctx .Repo .Repository , false )
931
927
932
928
_ , templateErrs := issue_service .GetTemplatesFromDefaultBranch (ctx .Repo .Repository , ctx .Repo .GitRepo )
933
- if errs := setTemplateIfExists (ctx , issueTemplateKey , IssueTemplateCandidates ); len (errs ) > 0 {
929
+ templateLoaded , errs := setTemplateIfExists (ctx , issueTemplateKey , IssueTemplateCandidates )
930
+ if len (errs ) > 0 {
934
931
for k , v := range errs {
935
932
templateErrs [k ] = v
936
933
}
@@ -945,6 +942,12 @@ func NewIssue(ctx *context.Context) {
945
942
946
943
ctx .Data ["HasIssuesOrPullsWritePermission" ] = ctx .Repo .CanWrite (unit .TypeIssues )
947
944
945
+ if ! issueConfig .BlankIssuesEnabled && hasTemplates && ! templateLoaded {
946
+ // 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.
947
+ ctx .Redirect (fmt .Sprintf ("%s/issues/new/choose?%s" , ctx .Repo .Repository .Link (), ctx .Req .URL .RawQuery ), http .StatusSeeOther )
948
+ return
949
+ }
950
+
948
951
ctx .HTML (http .StatusOK , tplIssueNew )
949
952
}
950
953
0 commit comments