-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes #16872
- Loading branch information
Showing
9 changed files
with
202 additions
and
48 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright 2024 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package repo | ||
|
||
import ( | ||
"net/http" | ||
|
||
"code.gitea.io/gitea/models/db" | ||
issues_model "code.gitea.io/gitea/models/issues" | ||
"code.gitea.io/gitea/models/unit" | ||
issue_indexer "code.gitea.io/gitea/modules/indexer/issues" | ||
"code.gitea.io/gitea/modules/optional" | ||
"code.gitea.io/gitea/services/context" | ||
) | ||
|
||
type issueSuggestion struct { | ||
ID int64 `json:"id"` | ||
Title string `json:"title"` | ||
State string `json:"state"` | ||
PullRequest *struct { | ||
Merged bool `json:"merged"` | ||
Draft bool `json:"draft"` | ||
} `json:"pull_request,omitempty"` | ||
} | ||
|
||
// IssueSuggestions returns a list of issue suggestions | ||
func IssueSuggestions(ctx *context.Context) { | ||
keyword := ctx.Req.FormValue("q") | ||
|
||
canReadIssues := ctx.Repo.CanRead(unit.TypeIssues) | ||
canReadPulls := ctx.Repo.CanRead(unit.TypePullRequests) | ||
|
||
var isPull optional.Option[bool] | ||
if canReadPulls && !canReadIssues { | ||
isPull = optional.Some(true) | ||
} else if canReadIssues && !canReadPulls { | ||
isPull = optional.Some(false) | ||
} | ||
|
||
searchOpt := &issue_indexer.SearchOptions{ | ||
Paginator: &db.ListOptions{ | ||
Page: 0, | ||
PageSize: 5, | ||
}, | ||
Keyword: keyword, | ||
RepoIDs: []int64{ctx.Repo.Repository.ID}, | ||
IsPull: isPull, | ||
IsClosed: nil, | ||
SortBy: issue_indexer.SortByUpdatedDesc, | ||
} | ||
|
||
ids, _, err := issue_indexer.SearchIssues(ctx, searchOpt) | ||
if err != nil { | ||
ctx.ServerError("SearchIssues", err) | ||
return | ||
} | ||
issues, err := issues_model.GetIssuesByIDs(ctx, ids, true) | ||
if err != nil { | ||
ctx.ServerError("FindIssuesByIDs", err) | ||
return | ||
} | ||
|
||
suggestions := make([]*issueSuggestion, 0, len(issues)) | ||
|
||
for _, issue := range issues { | ||
suggestion := &issueSuggestion{ | ||
ID: issue.ID, | ||
Title: issue.Title, | ||
State: string(issue.State()), | ||
} | ||
|
||
if issue.IsPull { | ||
if err := issue.LoadPullRequest(ctx); err != nil { | ||
ctx.ServerError("LoadPullRequest", err) | ||
return | ||
} | ||
if issue.PullRequest != nil { | ||
suggestion.PullRequest = &struct { | ||
Merged bool `json:"merged"` | ||
Draft bool `json:"draft"` | ||
}{ | ||
Merged: issue.PullRequest.HasMerged, | ||
Draft: issue.PullRequest.IsWorkInProgress(ctx), | ||
} | ||
} | ||
} | ||
|
||
suggestions = append(suggestions, suggestion) | ||
} | ||
|
||
ctx.JSON(http.StatusOK, suggestions) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import type {Issue} from '../types.ts'; | ||
|
||
export function getIssueIcon(issue: Issue) { | ||
if (issue.pull_request) { | ||
if (issue.state === 'open') { | ||
if (issue.pull_request.draft === true) { | ||
return 'octicon-git-pull-request-draft'; // WIP PR | ||
} | ||
return 'octicon-git-pull-request'; // Open PR | ||
} else if (issue.pull_request.merged === true) { | ||
return 'octicon-git-merge'; // Merged PR | ||
} | ||
return 'octicon-git-pull-request'; // Closed PR | ||
} else if (issue.state === 'open') { | ||
return 'octicon-issue-opened'; // Open Issue | ||
} | ||
return 'octicon-issue-closed'; // Closed Issue | ||
} | ||
|
||
export function getIssueColor(issue: Issue) { | ||
if (issue.pull_request) { | ||
if (issue.pull_request.draft === true) { | ||
return 'grey'; // WIP PR | ||
} else if (issue.pull_request.merged === true) { | ||
return 'purple'; // Merged PR | ||
} | ||
} | ||
if (issue.state === 'open') { | ||
return 'green'; // Open Issue | ||
} | ||
return 'red'; // Closed Issue | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters