2017-06-25 07:51:07 -07:00
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package integrations
|
|
|
|
|
|
|
|
import (
|
2018-09-12 19:33:48 -07:00
|
|
|
"fmt"
|
2017-06-25 07:51:07 -07:00
|
|
|
"net/http"
|
2020-01-11 23:35:11 -07:00
|
|
|
"net/url"
|
2017-06-25 07:51:07 -07:00
|
|
|
"testing"
|
2020-11-23 13:49:36 -07:00
|
|
|
"time"
|
2017-06-25 07:51:07 -07:00
|
|
|
|
|
|
|
"code.gitea.io/gitea/models"
|
2021-12-09 18:27:50 -07:00
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-16 01:53:21 -07:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2021-11-24 02:49:20 -07:00
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2019-05-11 03:21:34 -07:00
|
|
|
api "code.gitea.io/gitea/modules/structs"
|
2017-06-25 07:51:07 -07:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAPIListIssues(t *testing.T) {
|
2019-11-25 16:21:37 -07:00
|
|
|
defer prepareTestEnv(t)()
|
2017-06-25 07:51:07 -07:00
|
|
|
|
2021-12-09 18:27:50 -07:00
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
|
2021-11-24 02:49:20 -07:00
|
|
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
|
2017-06-25 07:51:07 -07:00
|
|
|
|
|
|
|
session := loginUser(t, owner.Name)
|
2018-09-10 09:15:52 -07:00
|
|
|
token := getTokenForLoggedInUser(t, session)
|
2021-06-16 15:33:37 -07:00
|
|
|
link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/issues", owner.Name, repo.Name))
|
|
|
|
|
|
|
|
link.RawQuery = url.Values{"token": {token}, "state": {"all"}}.Encode()
|
|
|
|
resp := session.MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK)
|
2017-06-25 07:51:07 -07:00
|
|
|
var apiIssues []*api.Issue
|
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
2021-11-16 01:53:21 -07:00
|
|
|
assert.Len(t, apiIssues, unittest.GetCount(t, &models.Issue{RepoID: repo.ID}))
|
2017-06-25 07:51:07 -07:00
|
|
|
for _, apiIssue := range apiIssues {
|
2021-11-16 01:53:21 -07:00
|
|
|
unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: apiIssue.ID, RepoID: repo.ID})
|
2017-06-25 07:51:07 -07:00
|
|
|
}
|
2020-04-29 21:15:39 -07:00
|
|
|
|
|
|
|
// test milestone filter
|
2021-06-16 15:33:37 -07:00
|
|
|
link.RawQuery = url.Values{"token": {token}, "state": {"all"}, "type": {"all"}, "milestones": {"ignore,milestone1,3,4"}}.Encode()
|
|
|
|
resp = session.MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK)
|
2020-04-29 21:15:39 -07:00
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
|
|
|
if assert.Len(t, apiIssues, 2) {
|
|
|
|
assert.EqualValues(t, 3, apiIssues[0].Milestone.ID)
|
|
|
|
assert.EqualValues(t, 1, apiIssues[1].Milestone.ID)
|
|
|
|
}
|
|
|
|
|
2021-06-16 15:33:37 -07:00
|
|
|
link.RawQuery = url.Values{"token": {token}, "state": {"all"}, "created_by": {"user2"}}.Encode()
|
|
|
|
resp = session.MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK)
|
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
|
|
|
if assert.Len(t, apiIssues, 1) {
|
|
|
|
assert.EqualValues(t, 5, apiIssues[0].ID)
|
|
|
|
}
|
|
|
|
|
|
|
|
link.RawQuery = url.Values{"token": {token}, "state": {"all"}, "assigned_by": {"user1"}}.Encode()
|
|
|
|
resp = session.MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK)
|
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
|
|
|
if assert.Len(t, apiIssues, 1) {
|
|
|
|
assert.EqualValues(t, 1, apiIssues[0].ID)
|
|
|
|
}
|
|
|
|
|
|
|
|
link.RawQuery = url.Values{"token": {token}, "state": {"all"}, "mentioned_by": {"user4"}}.Encode()
|
|
|
|
resp = session.MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK)
|
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
|
|
|
if assert.Len(t, apiIssues, 1) {
|
|
|
|
assert.EqualValues(t, 1, apiIssues[0].ID)
|
|
|
|
}
|
2017-06-25 07:51:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestAPICreateIssue(t *testing.T) {
|
2019-11-25 16:21:37 -07:00
|
|
|
defer prepareTestEnv(t)()
|
2017-06-25 07:51:07 -07:00
|
|
|
const body, title = "apiTestBody", "apiTestTitle"
|
|
|
|
|
2021-12-09 18:27:50 -07:00
|
|
|
repoBefore := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
|
2021-11-24 02:49:20 -07:00
|
|
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repoBefore.OwnerID}).(*user_model.User)
|
2017-06-25 07:51:07 -07:00
|
|
|
|
|
|
|
session := loginUser(t, owner.Name)
|
2018-09-10 09:15:52 -07:00
|
|
|
token := getTokenForLoggedInUser(t, session)
|
2020-02-20 00:46:46 -07:00
|
|
|
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues?state=all&token=%s", owner.Name, repoBefore.Name, token)
|
2017-06-25 07:51:07 -07:00
|
|
|
req := NewRequestWithJSON(t, "POST", urlStr, &api.CreateIssueOption{
|
|
|
|
Body: body,
|
|
|
|
Title: title,
|
|
|
|
Assignee: owner.Name,
|
|
|
|
})
|
2017-07-07 12:36:47 -07:00
|
|
|
resp := session.MakeRequest(t, req, http.StatusCreated)
|
2017-06-25 07:51:07 -07:00
|
|
|
var apiIssue api.Issue
|
|
|
|
DecodeJSON(t, resp, &apiIssue)
|
2021-06-06 22:27:09 -07:00
|
|
|
assert.Equal(t, body, apiIssue.Body)
|
|
|
|
assert.Equal(t, title, apiIssue.Title)
|
2017-06-25 07:51:07 -07:00
|
|
|
|
2021-11-16 01:53:21 -07:00
|
|
|
unittest.AssertExistsAndLoadBean(t, &models.Issue{
|
2020-02-20 00:46:46 -07:00
|
|
|
RepoID: repoBefore.ID,
|
2017-06-25 07:51:07 -07:00
|
|
|
AssigneeID: owner.ID,
|
|
|
|
Content: body,
|
|
|
|
Title: title,
|
|
|
|
})
|
2020-02-20 00:46:46 -07:00
|
|
|
|
2021-12-09 18:27:50 -07:00
|
|
|
repoAfter := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
|
2020-02-20 00:46:46 -07:00
|
|
|
assert.Equal(t, repoBefore.NumIssues+1, repoAfter.NumIssues)
|
|
|
|
assert.Equal(t, repoBefore.NumClosedIssues, repoAfter.NumClosedIssues)
|
2017-06-25 07:51:07 -07:00
|
|
|
}
|
2020-01-01 15:51:10 -07:00
|
|
|
|
|
|
|
func TestAPIEditIssue(t *testing.T) {
|
|
|
|
defer prepareTestEnv(t)()
|
|
|
|
|
2021-11-16 01:53:21 -07:00
|
|
|
issueBefore := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 10}).(*models.Issue)
|
2021-12-09 18:27:50 -07:00
|
|
|
repoBefore := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issueBefore.RepoID}).(*repo_model.Repository)
|
2021-11-24 02:49:20 -07:00
|
|
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repoBefore.OwnerID}).(*user_model.User)
|
2020-01-01 15:51:10 -07:00
|
|
|
assert.NoError(t, issueBefore.LoadAttributes())
|
|
|
|
assert.Equal(t, int64(1019307200), int64(issueBefore.DeadlineUnix))
|
|
|
|
assert.Equal(t, api.StateOpen, issueBefore.State())
|
|
|
|
|
|
|
|
session := loginUser(t, owner.Name)
|
|
|
|
token := getTokenForLoggedInUser(t, session)
|
|
|
|
|
|
|
|
// update values of issue
|
|
|
|
issueState := "closed"
|
|
|
|
removeDeadline := true
|
|
|
|
milestone := int64(4)
|
|
|
|
body := "new content!"
|
|
|
|
title := "new title from api set"
|
|
|
|
|
2020-02-20 00:46:46 -07:00
|
|
|
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d?token=%s", owner.Name, repoBefore.Name, issueBefore.Index, token)
|
2020-01-01 15:51:10 -07:00
|
|
|
req := NewRequestWithJSON(t, "PATCH", urlStr, api.EditIssueOption{
|
|
|
|
State: &issueState,
|
|
|
|
RemoveDeadline: &removeDeadline,
|
|
|
|
Milestone: &milestone,
|
|
|
|
Body: &body,
|
|
|
|
Title: title,
|
|
|
|
|
|
|
|
// ToDo change more
|
|
|
|
})
|
|
|
|
resp := session.MakeRequest(t, req, http.StatusCreated)
|
|
|
|
var apiIssue api.Issue
|
|
|
|
DecodeJSON(t, resp, &apiIssue)
|
|
|
|
|
2021-11-16 01:53:21 -07:00
|
|
|
issueAfter := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 10}).(*models.Issue)
|
2021-12-09 18:27:50 -07:00
|
|
|
repoAfter := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issueBefore.RepoID}).(*repo_model.Repository)
|
2020-01-01 15:51:10 -07:00
|
|
|
|
|
|
|
// check deleted user
|
|
|
|
assert.Equal(t, int64(500), issueAfter.PosterID)
|
|
|
|
assert.NoError(t, issueAfter.LoadAttributes())
|
|
|
|
assert.Equal(t, int64(-1), issueAfter.PosterID)
|
|
|
|
assert.Equal(t, int64(-1), issueBefore.PosterID)
|
|
|
|
assert.Equal(t, int64(-1), apiIssue.Poster.ID)
|
|
|
|
|
2020-02-20 00:46:46 -07:00
|
|
|
// check repo change
|
|
|
|
assert.Equal(t, repoBefore.NumClosedIssues+1, repoAfter.NumClosedIssues)
|
|
|
|
|
2020-01-01 15:51:10 -07:00
|
|
|
// API response
|
|
|
|
assert.Equal(t, api.StateClosed, apiIssue.State)
|
|
|
|
assert.Equal(t, milestone, apiIssue.Milestone.ID)
|
|
|
|
assert.Equal(t, body, apiIssue.Body)
|
|
|
|
assert.True(t, apiIssue.Deadline == nil)
|
|
|
|
assert.Equal(t, title, apiIssue.Title)
|
|
|
|
|
|
|
|
// in database
|
|
|
|
assert.Equal(t, api.StateClosed, issueAfter.State())
|
|
|
|
assert.Equal(t, milestone, issueAfter.MilestoneID)
|
|
|
|
assert.Equal(t, int64(0), int64(issueAfter.DeadlineUnix))
|
|
|
|
assert.Equal(t, body, issueAfter.Content)
|
|
|
|
assert.Equal(t, title, issueAfter.Title)
|
|
|
|
}
|
2020-01-11 23:35:11 -07:00
|
|
|
|
Add Organization Wide Labels (#10814)
* Add organization wide labels
Implement organization wide labels similar to organization wide
webhooks. This lets you create individual labels for organizations that can be used
for all repos under that organization (so being able to reuse the same
label across multiple repos).
This makes it possible for small organizations with many repos to use
labels effectively.
Fixes #7406
* Add migration
* remove comments
* fix tests
* Update options/locale/locale_en-US.ini
Removed unused translation string
* show org labels in issue search label filter
* Use more clear var name
* rename migration after merge from master
* comment typo
* update migration again after rebase with master
* check for orgID <=0 per guillep2k review
* fmt
* Apply suggestions from code review
Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com>
* remove unused code
* Make sure RepoID is 0 when searching orgID per code review
* more changes/code review requests
* More descriptive translation var per code review
* func description/delete comment when issue label deleted instead of hiding it
* remove comment
* only use issues in that repo when calculating number of open issues for org label on repo label page
* Add integration test for IssuesSearch API with labels
* remove unused function
* Update models/issue_label.go
Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com>
* Use subquery in GetLabelIDsInReposByNames
* Fix tests to use correct orgID
* fix more tests
* IssuesSearch api now uses new BuildLabelNamesIssueIDsCondition. Add a few more tests as well
* update comment for clarity
* Revert previous code change now that we can use the new BuildLabelNamesIssueIDsCondition
* Don't sort repos by date in IssuesSearch API
After much debugging I've found a strange issue where in some cases MySQL will return a different result than other enigines if a query is sorted by a null collumn. For example with our integration test data where we don't set updated_unix in repository fixtures:
SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 45
Returns different results for MySQL than other engines. However, the similar query:
SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 30
Returns the same results.
This causes integration tests to fail on MySQL in certain cases but would never show up in a real installation. Since this API call always returns issues based on the optionally provided repo_priority_id or the issueID itself, there is no change to results by changing the repo sorting method used to get ids earlier in the function.
* linter is back!
* code review
* remove now unused option
* Fix newline at end of files
* more unused code
* update to master
* check for matching ids before query
* Update models/issue_label.go
Co-Authored-By: 6543 <6543@obermui.de>
* Update models/issue_label.go
* update comments
* Update routers/org/setting.go
Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>
Co-authored-by: 6543 <6543@obermui.de>
2020-03-31 21:14:46 -07:00
|
|
|
func TestAPISearchIssues(t *testing.T) {
|
2020-01-11 23:35:11 -07:00
|
|
|
defer prepareTestEnv(t)()
|
|
|
|
|
|
|
|
session := loginUser(t, "user2")
|
|
|
|
token := getTokenForLoggedInUser(t, session)
|
|
|
|
|
|
|
|
link, _ := url.Parse("/api/v1/repos/issues/search")
|
|
|
|
req := NewRequest(t, "GET", link.String())
|
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
var apiIssues []*api.Issue
|
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
2020-10-20 11:18:25 -07:00
|
|
|
assert.Len(t, apiIssues, 10)
|
2020-01-11 23:35:11 -07:00
|
|
|
|
2020-11-23 13:49:36 -07:00
|
|
|
query := url.Values{"token": {token}}
|
2020-01-11 23:35:11 -07:00
|
|
|
link.RawQuery = query.Encode()
|
|
|
|
req = NewRequest(t, "GET", link.String())
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
2020-10-20 11:18:25 -07:00
|
|
|
assert.Len(t, apiIssues, 10)
|
2020-01-11 23:35:11 -07:00
|
|
|
|
2020-11-23 13:49:36 -07:00
|
|
|
since := "2000-01-01T00%3A50%3A01%2B00%3A00" // 946687801
|
|
|
|
before := time.Unix(999307200, 0).Format(time.RFC3339)
|
|
|
|
query.Add("since", since)
|
|
|
|
query.Add("before", before)
|
|
|
|
link.RawQuery = query.Encode()
|
|
|
|
req = NewRequest(t, "GET", link.String())
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
|
|
|
assert.Len(t, apiIssues, 8)
|
|
|
|
query.Del("since")
|
|
|
|
query.Del("before")
|
|
|
|
|
2020-01-11 23:35:11 -07:00
|
|
|
query.Add("state", "closed")
|
|
|
|
link.RawQuery = query.Encode()
|
|
|
|
req = NewRequest(t, "GET", link.String())
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
|
|
|
assert.Len(t, apiIssues, 2)
|
|
|
|
|
|
|
|
query.Set("state", "all")
|
|
|
|
link.RawQuery = query.Encode()
|
|
|
|
req = NewRequest(t, "GET", link.String())
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
2021-08-13 13:47:25 -07:00
|
|
|
assert.EqualValues(t, "15", resp.Header().Get("X-Total-Count"))
|
2022-01-20 10:46:10 -07:00
|
|
|
assert.Len(t, apiIssues, 10) // there are more but 10 is page item limit
|
2020-01-11 23:35:11 -07:00
|
|
|
|
2020-11-23 13:49:36 -07:00
|
|
|
query.Add("limit", "20")
|
2020-01-11 23:35:11 -07:00
|
|
|
link.RawQuery = query.Encode()
|
|
|
|
req = NewRequest(t, "GET", link.String())
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
2021-08-13 13:47:25 -07:00
|
|
|
assert.Len(t, apiIssues, 15)
|
2020-11-23 13:49:36 -07:00
|
|
|
|
|
|
|
query = url.Values{"assigned": {"true"}, "state": {"all"}}
|
|
|
|
link.RawQuery = query.Encode()
|
|
|
|
req = NewRequest(t, "GET", link.String())
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
|
|
|
assert.Len(t, apiIssues, 1)
|
2021-06-16 23:40:59 -07:00
|
|
|
|
|
|
|
query = url.Values{"milestones": {"milestone1"}, "state": {"all"}}
|
|
|
|
link.RawQuery = query.Encode()
|
|
|
|
req = NewRequest(t, "GET", link.String())
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
|
|
|
assert.Len(t, apiIssues, 1)
|
|
|
|
|
|
|
|
query = url.Values{"milestones": {"milestone1,milestone3"}, "state": {"all"}}
|
|
|
|
link.RawQuery = query.Encode()
|
|
|
|
req = NewRequest(t, "GET", link.String())
|
2021-08-13 13:47:25 -07:00
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
|
|
|
assert.Len(t, apiIssues, 2)
|
|
|
|
|
|
|
|
query = url.Values{"owner": {"user2"}} // user
|
|
|
|
link.RawQuery = query.Encode()
|
|
|
|
req = NewRequest(t, "GET", link.String())
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
|
|
|
assert.Len(t, apiIssues, 6)
|
|
|
|
|
|
|
|
query = url.Values{"owner": {"user3"}} // organization
|
|
|
|
link.RawQuery = query.Encode()
|
|
|
|
req = NewRequest(t, "GET", link.String())
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
|
|
|
assert.Len(t, apiIssues, 3)
|
|
|
|
|
|
|
|
query = url.Values{"owner": {"user3"}, "team": {"team1"}} // organization + team
|
|
|
|
link.RawQuery = query.Encode()
|
|
|
|
req = NewRequest(t, "GET", link.String())
|
2021-06-16 23:40:59 -07:00
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
|
|
|
assert.Len(t, apiIssues, 2)
|
2020-01-11 23:35:11 -07:00
|
|
|
}
|
Add Organization Wide Labels (#10814)
* Add organization wide labels
Implement organization wide labels similar to organization wide
webhooks. This lets you create individual labels for organizations that can be used
for all repos under that organization (so being able to reuse the same
label across multiple repos).
This makes it possible for small organizations with many repos to use
labels effectively.
Fixes #7406
* Add migration
* remove comments
* fix tests
* Update options/locale/locale_en-US.ini
Removed unused translation string
* show org labels in issue search label filter
* Use more clear var name
* rename migration after merge from master
* comment typo
* update migration again after rebase with master
* check for orgID <=0 per guillep2k review
* fmt
* Apply suggestions from code review
Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com>
* remove unused code
* Make sure RepoID is 0 when searching orgID per code review
* more changes/code review requests
* More descriptive translation var per code review
* func description/delete comment when issue label deleted instead of hiding it
* remove comment
* only use issues in that repo when calculating number of open issues for org label on repo label page
* Add integration test for IssuesSearch API with labels
* remove unused function
* Update models/issue_label.go
Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com>
* Use subquery in GetLabelIDsInReposByNames
* Fix tests to use correct orgID
* fix more tests
* IssuesSearch api now uses new BuildLabelNamesIssueIDsCondition. Add a few more tests as well
* update comment for clarity
* Revert previous code change now that we can use the new BuildLabelNamesIssueIDsCondition
* Don't sort repos by date in IssuesSearch API
After much debugging I've found a strange issue where in some cases MySQL will return a different result than other enigines if a query is sorted by a null collumn. For example with our integration test data where we don't set updated_unix in repository fixtures:
SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 45
Returns different results for MySQL than other engines. However, the similar query:
SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 30
Returns the same results.
This causes integration tests to fail on MySQL in certain cases but would never show up in a real installation. Since this API call always returns issues based on the optionally provided repo_priority_id or the issueID itself, there is no change to results by changing the repo sorting method used to get ids earlier in the function.
* linter is back!
* code review
* remove now unused option
* Fix newline at end of files
* more unused code
* update to master
* check for matching ids before query
* Update models/issue_label.go
Co-Authored-By: 6543 <6543@obermui.de>
* Update models/issue_label.go
* update comments
* Update routers/org/setting.go
Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>
Co-authored-by: 6543 <6543@obermui.de>
2020-03-31 21:14:46 -07:00
|
|
|
|
|
|
|
func TestAPISearchIssuesWithLabels(t *testing.T) {
|
|
|
|
defer prepareTestEnv(t)()
|
|
|
|
|
|
|
|
session := loginUser(t, "user1")
|
|
|
|
token := getTokenForLoggedInUser(t, session)
|
|
|
|
|
|
|
|
link, _ := url.Parse("/api/v1/repos/issues/search")
|
|
|
|
req := NewRequest(t, "GET", link.String())
|
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
var apiIssues []*api.Issue
|
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
|
|
|
|
2020-10-20 11:18:25 -07:00
|
|
|
assert.Len(t, apiIssues, 10)
|
Add Organization Wide Labels (#10814)
* Add organization wide labels
Implement organization wide labels similar to organization wide
webhooks. This lets you create individual labels for organizations that can be used
for all repos under that organization (so being able to reuse the same
label across multiple repos).
This makes it possible for small organizations with many repos to use
labels effectively.
Fixes #7406
* Add migration
* remove comments
* fix tests
* Update options/locale/locale_en-US.ini
Removed unused translation string
* show org labels in issue search label filter
* Use more clear var name
* rename migration after merge from master
* comment typo
* update migration again after rebase with master
* check for orgID <=0 per guillep2k review
* fmt
* Apply suggestions from code review
Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com>
* remove unused code
* Make sure RepoID is 0 when searching orgID per code review
* more changes/code review requests
* More descriptive translation var per code review
* func description/delete comment when issue label deleted instead of hiding it
* remove comment
* only use issues in that repo when calculating number of open issues for org label on repo label page
* Add integration test for IssuesSearch API with labels
* remove unused function
* Update models/issue_label.go
Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com>
* Use subquery in GetLabelIDsInReposByNames
* Fix tests to use correct orgID
* fix more tests
* IssuesSearch api now uses new BuildLabelNamesIssueIDsCondition. Add a few more tests as well
* update comment for clarity
* Revert previous code change now that we can use the new BuildLabelNamesIssueIDsCondition
* Don't sort repos by date in IssuesSearch API
After much debugging I've found a strange issue where in some cases MySQL will return a different result than other enigines if a query is sorted by a null collumn. For example with our integration test data where we don't set updated_unix in repository fixtures:
SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 45
Returns different results for MySQL than other engines. However, the similar query:
SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 30
Returns the same results.
This causes integration tests to fail on MySQL in certain cases but would never show up in a real installation. Since this API call always returns issues based on the optionally provided repo_priority_id or the issueID itself, there is no change to results by changing the repo sorting method used to get ids earlier in the function.
* linter is back!
* code review
* remove now unused option
* Fix newline at end of files
* more unused code
* update to master
* check for matching ids before query
* Update models/issue_label.go
Co-Authored-By: 6543 <6543@obermui.de>
* Update models/issue_label.go
* update comments
* Update routers/org/setting.go
Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>
Co-authored-by: 6543 <6543@obermui.de>
2020-03-31 21:14:46 -07:00
|
|
|
|
|
|
|
query := url.Values{}
|
|
|
|
query.Add("token", token)
|
|
|
|
link.RawQuery = query.Encode()
|
|
|
|
req = NewRequest(t, "GET", link.String())
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
2020-10-20 11:18:25 -07:00
|
|
|
assert.Len(t, apiIssues, 10)
|
Add Organization Wide Labels (#10814)
* Add organization wide labels
Implement organization wide labels similar to organization wide
webhooks. This lets you create individual labels for organizations that can be used
for all repos under that organization (so being able to reuse the same
label across multiple repos).
This makes it possible for small organizations with many repos to use
labels effectively.
Fixes #7406
* Add migration
* remove comments
* fix tests
* Update options/locale/locale_en-US.ini
Removed unused translation string
* show org labels in issue search label filter
* Use more clear var name
* rename migration after merge from master
* comment typo
* update migration again after rebase with master
* check for orgID <=0 per guillep2k review
* fmt
* Apply suggestions from code review
Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com>
* remove unused code
* Make sure RepoID is 0 when searching orgID per code review
* more changes/code review requests
* More descriptive translation var per code review
* func description/delete comment when issue label deleted instead of hiding it
* remove comment
* only use issues in that repo when calculating number of open issues for org label on repo label page
* Add integration test for IssuesSearch API with labels
* remove unused function
* Update models/issue_label.go
Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com>
* Use subquery in GetLabelIDsInReposByNames
* Fix tests to use correct orgID
* fix more tests
* IssuesSearch api now uses new BuildLabelNamesIssueIDsCondition. Add a few more tests as well
* update comment for clarity
* Revert previous code change now that we can use the new BuildLabelNamesIssueIDsCondition
* Don't sort repos by date in IssuesSearch API
After much debugging I've found a strange issue where in some cases MySQL will return a different result than other enigines if a query is sorted by a null collumn. For example with our integration test data where we don't set updated_unix in repository fixtures:
SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 45
Returns different results for MySQL than other engines. However, the similar query:
SELECT `id`, `owner_id`, `owner_name`, `lower_name`, `name`, `description`, `website`, `original_service_type`, `original_url`, `default_branch`, `num_watches`, `num_stars`, `num_forks`, `num_issues`, `num_closed_issues`, `num_pulls`, `num_closed_pulls`, `num_milestones`, `num_closed_milestones`, `is_private`, `is_empty`, `is_archived`, `is_mirror`, `status`, `is_fork`, `fork_id`, `is_template`, `template_id`, `size`, `is_fsck_enabled`, `close_issues_via_commit_in_any_branch`, `topics`, `avatar`, `created_unix`, `updated_unix` FROM `repository` ORDER BY updated_unix DESC LIMIT 15 OFFSET 30
Returns the same results.
This causes integration tests to fail on MySQL in certain cases but would never show up in a real installation. Since this API call always returns issues based on the optionally provided repo_priority_id or the issueID itself, there is no change to results by changing the repo sorting method used to get ids earlier in the function.
* linter is back!
* code review
* remove now unused option
* Fix newline at end of files
* more unused code
* update to master
* check for matching ids before query
* Update models/issue_label.go
Co-Authored-By: 6543 <6543@obermui.de>
* Update models/issue_label.go
* update comments
* Update routers/org/setting.go
Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>
Co-authored-by: 6543 <6543@obermui.de>
2020-03-31 21:14:46 -07:00
|
|
|
|
|
|
|
query.Add("labels", "label1")
|
|
|
|
link.RawQuery = query.Encode()
|
|
|
|
req = NewRequest(t, "GET", link.String())
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
|
|
|
assert.Len(t, apiIssues, 2)
|
|
|
|
|
|
|
|
// multiple labels
|
|
|
|
query.Set("labels", "label1,label2")
|
|
|
|
link.RawQuery = query.Encode()
|
|
|
|
req = NewRequest(t, "GET", link.String())
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
|
|
|
assert.Len(t, apiIssues, 2)
|
|
|
|
|
|
|
|
// an org label
|
|
|
|
query.Set("labels", "orglabel4")
|
|
|
|
link.RawQuery = query.Encode()
|
|
|
|
req = NewRequest(t, "GET", link.String())
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
|
|
|
assert.Len(t, apiIssues, 1)
|
|
|
|
|
|
|
|
// org and repo label
|
|
|
|
query.Set("labels", "label2,orglabel4")
|
|
|
|
query.Add("state", "all")
|
|
|
|
link.RawQuery = query.Encode()
|
|
|
|
req = NewRequest(t, "GET", link.String())
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
|
|
|
assert.Len(t, apiIssues, 2)
|
|
|
|
|
|
|
|
// org and repo label which share the same issue
|
|
|
|
query.Set("labels", "label1,orglabel4")
|
|
|
|
link.RawQuery = query.Encode()
|
|
|
|
req = NewRequest(t, "GET", link.String())
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
|
|
|
assert.Len(t, apiIssues, 2)
|
|
|
|
}
|