@@ -48,7 +48,9 @@ type IssuesOptions struct { //nolint
4848 UpdatedBeforeUnix int64
4949 // prioritize issues from this repo
5050 PriorityRepoID int64
51- IsArchived optional.Option [bool ]
51+ // if this issue index (not ID) exists and matches the filters, *and* priorityrepo sort is used, show it first
52+ PriorityIssueIndex int64
53+ IsArchived optional.Option [bool ]
5254
5355 // If combined with AllPublic, then private as well as public issues
5456 // that matches the criteria will be returned, if AllPublic is false
@@ -60,7 +62,7 @@ type IssuesOptions struct { //nolint
6062
6163// applySorts sort an issues-related session based on the provided
6264// sortType string
63- func applySorts (sess * xorm.Session , sortType string , priorityRepoID int64 ) {
65+ func applySorts (sess * xorm.Session , sortType string , priorityRepoID , priorityIssueIndex int64 ) {
6466 switch sortType {
6567 case "oldest" :
6668 sess .Asc ("issue.created_unix" ).Asc ("issue.id" )
@@ -97,8 +99,11 @@ func applySorts(sess *xorm.Session, sortType string, priorityRepoID int64) {
9799 case "priorityrepo" :
98100 sess .OrderBy ("CASE " +
99101 "WHEN issue.repo_id = ? THEN 1 " +
100- "ELSE 2 END ASC" , priorityRepoID ).
101- Desc ("issue.created_unix" ).
102+ "ELSE 2 END ASC" , priorityRepoID )
103+ if priorityIssueIndex != 0 {
104+ sess .OrderBy ("issue.index = ? DESC" , priorityIssueIndex )
105+ }
106+ sess .Desc ("issue.created_unix" ).
102107 Desc ("issue.id" )
103108 case "project-column-sorting" :
104109 sess .Asc ("project_issue.sorting" ).Desc ("issue.created_unix" ).Desc ("issue.id" )
@@ -470,7 +475,7 @@ func Issues(ctx context.Context, opts *IssuesOptions) (IssueList, error) {
470475 Join ("INNER" , "repository" , "`issue`.repo_id = `repository`.id" )
471476 applyLimit (sess , opts )
472477 applyConditions (sess , opts )
473- applySorts (sess , opts .SortType , opts .PriorityRepoID )
478+ applySorts (sess , opts .SortType , opts .PriorityRepoID , opts . PriorityIssueIndex )
474479
475480 issues := IssueList {}
476481 if err := sess .Find (& issues ); err != nil {
@@ -494,7 +499,7 @@ func IssueIDs(ctx context.Context, opts *IssuesOptions, otherConds ...builder.Co
494499 }
495500
496501 applyLimit (sess , opts )
497- applySorts (sess , opts .SortType , opts .PriorityRepoID )
502+ applySorts (sess , opts .SortType , opts .PriorityRepoID , opts . PriorityIssueIndex )
498503
499504 var res []int64
500505 total , err := sess .Select ("`issue`.id" ).Table (& Issue {}).FindAndCount (& res )
0 commit comments