@@ -830,10 +830,11 @@ func RetrieveRepoMetas(ctx *context.Context, repo *repo_model.Repository, isPull
830
830
return labels
831
831
}
832
832
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 ) {
834
835
commit , err := ctx .Repo .GitRepo .GetBranchCommit (ctx .Repo .Repository .DefaultBranch )
835
836
if err != nil {
836
- return nil
837
+ return false , nil
837
838
}
838
839
839
840
templateCandidates := make ([]string , 0 , 1 + len (possibleFiles ))
@@ -896,20 +897,15 @@ func setTemplateIfExists(ctx *context.Context, ctxDataKey string, possibleFiles
896
897
ctx .Data ["label_ids" ] = strings .Join (labelIDs , "," )
897
898
ctx .Data ["Reference" ] = template .Ref
898
899
ctx .Data ["RefEndName" ] = git .RefName (template .Ref ).ShortName ()
899
- return templateErrs
900
+ return true , templateErrs
900
901
}
901
- return templateErrs
902
+ return false , templateErrs
902
903
}
903
904
904
905
// NewIssue render creating issue page
905
906
func NewIssue (ctx * context.Context ) {
906
907
issueConfig , _ := issue_service .GetTemplateConfigFromDefaultBranch (ctx .Repo .Repository , ctx .Repo .GitRepo )
907
908
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
- }
913
909
914
910
ctx .Data ["Title" ] = ctx .Tr ("repo.issues.new" )
915
911
ctx .Data ["PageIsIssueList" ] = true
@@ -963,7 +959,8 @@ func NewIssue(ctx *context.Context) {
963
959
ctx .Data ["Tags" ] = tags
964
960
965
961
_ , 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 {
967
964
for k , v := range errs {
968
965
templateErrs [k ] = v
969
966
}
@@ -978,6 +975,12 @@ func NewIssue(ctx *context.Context) {
978
975
979
976
ctx .Data ["HasIssuesOrPullsWritePermission" ] = ctx .Repo .CanWrite (unit .TypeIssues )
980
977
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
+
981
984
ctx .HTML (http .StatusOK , tplIssueNew )
982
985
}
983
986
0 commit comments