mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 19:11:25 +01:00
fix(issue): show merged pull requests as merged in issue lists and search
issue list --kind all, milestone issue list and search pr reported a merged pull request as closed. Their state is now merged, in tables and in JSON, which also tells issues and pull requests apart by kind. Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
3 files changed
+31
-3
No files matched your search
@@ -39,16 +39,25 @@ const (
|
|||||||
KindPull = "pull"
|
KindPull = "pull"
|
||||||
)
|
)
|
||||||
|
|
||||||
// discussionFrom converts an issue or a pull request listed among issues.
|
// discussionFrom converts an issue or a pull request listed among issues; the state of a merged
|
||||||
|
// pull request is "merged" rather than "closed".
|
||||||
func discussionFrom(issue *gitea.Issue) Issue {
|
func discussionFrom(issue *gitea.Issue) Issue {
|
||||||
item := issueFrom(issue)
|
item := issueFrom(issue)
|
||||||
item.Kind = KindIssue
|
item.Kind, item.State = KindIssue, discussionState(issue)
|
||||||
if issue.PullRequest != nil {
|
if issue.PullRequest != nil {
|
||||||
item.Kind = KindPull
|
item.Kind = KindPull
|
||||||
}
|
}
|
||||||
return item
|
return item
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// discussionState is the state of an issue, or "merged" for a merged pull request.
|
||||||
|
func discussionState(issue *gitea.Issue) string {
|
||||||
|
if issue.PullRequest != nil && issue.PullRequest.HasMerged {
|
||||||
|
return "merged"
|
||||||
|
}
|
||||||
|
return string(issue.State)
|
||||||
|
}
|
||||||
|
|
||||||
// IssueMilestone identifies the milestone associated with an issue or pull request.
|
// IssueMilestone identifies the milestone associated with an issue or pull request.
|
||||||
type IssueMilestone struct {
|
type IssueMilestone struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
|
|||||||
@@ -77,6 +77,25 @@ func TestIssueDependenciesMapReferencesAndTreatMissingSupportAsNone(t *testing.T
|
|||||||
require.Equal(t, IssueDependencies{}, dependencies)
|
require.Equal(t, IssueDependencies{}, dependencies)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDiscussionsTellPullRequestsAndMergesApart(t *testing.T) {
|
||||||
|
list := `[{"number":1,"state":"open"},{"number":2,"state":"closed","pull_request":{"merged":false}},` +
|
||||||
|
`{"number":3,"state":"closed","pull_request":{"merged":true}},{"number":4,"state":"open","pull_request":{"merged":false}}]`
|
||||||
|
client := newTestClient(t, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
|
_, _ = w.Write([]byte(list))
|
||||||
|
}))
|
||||||
|
want := []struct{ kind, state string }{{KindIssue, "open"}, {KindPull, "closed"}, {KindPull, "merged"}, {KindPull, "open"}}
|
||||||
|
issues, _, err := (Issues{Client: client, Repository: "alice/project"}).List(context.Background(), ListOptions{Kind: "all", State: "all", Limit: 30, Page: 1})
|
||||||
|
require.NoError(t, err)
|
||||||
|
found, err := (Issues{Client: client, Repository: "alice/project"}).Search(context.Background(), DiscussionSearchOptions{State: "all", Limit: 30, Page: 1})
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Len(t, issues, len(want))
|
||||||
|
for i, item := range want {
|
||||||
|
require.Equal(t, item.kind, issues[i].Kind, issues[i].Number)
|
||||||
|
require.Equal(t, item.state, issues[i].State, issues[i].Number)
|
||||||
|
require.Equal(t, item.state, found[i].State, found[i].Number)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestIssueTemplatesAcceptCheckboxOptionObjects(t *testing.T) {
|
func TestIssueTemplatesAcceptCheckboxOptionObjects(t *testing.T) {
|
||||||
body := `[{"name":"Form","body":[{"type":"checkboxes","attributes":{"options":[{"label":"I searched","required":true}]}}]}]`
|
body := `[{"name":"Form","body":[{"type":"checkboxes","attributes":{"options":[{"label":"I searched","required":true}]}}]}]`
|
||||||
client := newTestClient(t, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
client := newTestClient(t, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ func (s Issues) Search(ctx context.Context, opts DiscussionSearchOptions) ([]Sea
|
|||||||
repository = issue.Repository.FullName
|
repository = issue.Repository.FullName
|
||||||
}
|
}
|
||||||
return SearchItem{
|
return SearchItem{
|
||||||
ID: issue.ID, Number: issue.Index, Title: issue.Title, Body: issue.Body, URL: issue.HTMLURL, State: string(issue.State),
|
ID: issue.ID, Number: issue.Index, Title: issue.Title, Body: issue.Body, URL: issue.HTMLURL, State: discussionState(issue),
|
||||||
Type: resultType, Repository: repository, CreatedAt: timestamp(issue.Created), UpdatedAt: timestamp(issue.Updated),
|
Type: resultType, Repository: repository, CreatedAt: timestamp(issue.Created), UpdatedAt: timestamp(issue.Updated),
|
||||||
}
|
}
|
||||||
}), nil
|
}), nil
|
||||||
|
|||||||
Reference in new issue
Block a user