-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Suggestions for issues #32327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggestions for issues #32327
Changes from 8 commits
e943ddc
1afcb06
41778d5
8957d4f
7371f26
5466516
ea1b18c
f50b4eb
546593f
bb3d550
573f257
462c5ed
5f783c7
99dc059
91742ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package repo | ||
Check failure on line 1 in routers/web/repo/issue_suggestions.go
|
||
|
||
import ( | ||
"net/http" | ||
|
||
"code.gitea.io/gitea/models/db" | ||
issues_model "code.gitea.io/gitea/models/issues" | ||
issue_indexer "code.gitea.io/gitea/modules/indexer/issues" | ||
"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") | ||
|
||
searchOpt := &issue_indexer.SearchOptions{ | ||
Paginator: &db.ListOptions{ | ||
Page: 0, | ||
PageSize: 5, | ||
}, | ||
Keyword: keyword, | ||
RepoIDs: []int64{ctx.Repo.Repository.ID}, | ||
lunny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
IsPull: nil, | ||
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) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
export type Issue = {id: number; title: string; state: 'open' | 'closed'; pull_request?: {draft: boolean; merged: boolean}}; | ||
|
||
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 | ||
} |
Uh oh!
There was an error while loading. Please reload this page.