Skip to content
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

Generalize list header for API #16551

Merged
merged 65 commits into from
Aug 12, 2021
Merged
Changes from 1 commit
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
041d023
Add info about list endpoints to CONTRIBUTING.md
6543 Jul 26, 2021
0b2f858
Let List Notifications return X-Total-Count header
6543 Jul 26, 2021
b1f875f
ListAccessTokens too
6543 Jul 26, 2021
c1f2c9c
ListCronTasks
6543 Jul 26, 2021
29657d9
ListForks
6543 Jul 26, 2021
28662da
ListStargazers
6543 Jul 26, 2021
cab3f66
Add only TODOs
6543 Jul 26, 2021
b933671
nit
6543 Jul 26, 2021
e22371a
models: webhook: introduce ListWebhooksByOpts
6543 Jul 26, 2021
6897dee
ListHooks
6543 Jul 26, 2021
5a9a23c
ListLabels
6543 Jul 26, 2021
0b89620
Org#ListMembers
6543 Jul 26, 2021
c6102e7
GetTeamMembers
6543 Jul 26, 2021
bf5accc
OrgListTeams
6543 Jul 26, 2021
516354d
fix
6543 Jul 26, 2021
55e0021
ListUserTeams
6543 Jul 26, 2021
d04f6c5
ListCollaborators
6543 Jul 26, 2021
0b4984e
fix bug
6543 Jul 26, 2021
99dbf98
Repo#ListHooks
6543 Jul 26, 2021
6c243ac
ListIssueComments, ListRepoIssueComments
6543 Jul 26, 2021
251fe3d
Fix models/issue_stopwatch.go
6543 Jul 26, 2021
a4577d8
GetStopwatches
6543 Jul 26, 2021
badb37e
TrackedTimes
6543 Jul 26, 2021
c45c9d0
refactor models.ListDeployKeys
6543 Jul 26, 2021
6c8ec0a
Repo#ListDeployKeys
6543 Jul 26, 2021
3216180
Update models/issue_stopwatch.go
6543 Jul 26, 2021
aff32b3
Merge branch 'master' into api-generalize-list-header
6543 Jul 26, 2021
5a39632
CONTRIBUTING: mention Access-Control-Expose-Headers
6543 Jul 26, 2021
27398cf
fix CountComments
6543 Jul 26, 2021
7ae321d
Repo#ListLabels
6543 Jul 26, 2021
2696598
ListMilestones
6543 Jul 26, 2021
faf8817
ListPullReviews
6543 Jul 26, 2021
5eacdb7
fix getLatestCommitStatus
6543 Jul 26, 2021
e32426a
todo ...
6543 Jul 26, 2021
a57a8d1
ListSubscribers
6543 Jul 26, 2021
69ae323
no pagination supportet here
6543 Jul 26, 2021
9334a42
ListTags
6543 Jul 26, 2021
0d4632d
ListOauth2Applications
6543 Jul 26, 2021
02ada65
ListTopics
6543 Jul 26, 2021
02d19a7
TopicSearch
6543 Jul 27, 2021
0193622
Followers and Following
6543 Jul 27, 2021
b132c7a
listGPGKeys
6543 Jul 27, 2021
dceacf9
listPublicKeys
6543 Jul 27, 2021
fae949e
GetMyStarredRepos
6543 Jul 27, 2021
6505d16
getWatchedRepos
6543 Jul 27, 2021
dd766da
Merge branch 'main' into api-generalize-list-header
6543 Jul 27, 2021
2f5545f
fix CountTrackedTimes
6543 Jul 27, 2021
b26aa31
Merge branch 'master' into api-generalize-list-header
6543 Jul 27, 2021
c706d0f
Fix APIRepoTopic
6543 Jul 27, 2021
0ed695b
Add TestAPITopicSearch
6543 Jul 27, 2021
4435617
refert back routers/api/v1/org/member.go
6543 Jul 27, 2021
3861004
Just use count topics instead of getting the topics from the db
zeripath Jul 28, 2021
89158d2
Merge branch 'master' into api-generalize-list-header
6543 Jul 29, 2021
8958bbf
oops
zeripath Jul 29, 2021
db237b7
Merge branch 'main' into api-generalize-list-header
6543 Jul 29, 2021
bd82612
Merge branch 'main' into api-generalize-list-header
6543 Aug 9, 2021
7aae98c
introduce helper func and use them for SetLinkHeader related func
6543 Aug 9, 2021
8fa7079
use SetTotalCountHeader everywhere
6543 Aug 10, 2021
af4086d
update docs
6543 Aug 10, 2021
cc15aa6
Merge branch 'main' into api-generalize-list-header
6543 Aug 10, 2021
fb5934d
Merge branch 'main' into api-generalize-list-header
6543 Aug 11, 2021
f9453ea
Merge branch 'main' into api-generalize-list-header
6543 Aug 11, 2021
261109e
Merge branch 'main' into api-generalize-list-header
6543 Aug 12, 2021
926e468
Merge branch 'main' into api-generalize-list-header
6543 Aug 12, 2021
d499354
Merge branch 'main' into api-generalize-list-header
6543 Aug 12, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor models.ListDeployKeys
6543 committed Jul 26, 2021

Verified

This commit was signed with the committer’s verified signature. The key has expired.
6543 6543
commit c45c9d0a0396878b61696d08a806b9252ec6d2a7
2 changes: 1 addition & 1 deletion models/repo.go
Original file line number Diff line number Diff line change
@@ -1453,7 +1453,7 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
}

// Delete Deploy Keys
deployKeys, err := listDeployKeys(sess, repo.ID, ListOptions{})
deployKeys, err := listDeployKeys(sess, &ListDeployKeysOptions{RepoID: repoID})
if err != nil {
return fmt.Errorf("listDeployKeys: %v", err)
}
55 changes: 31 additions & 24 deletions models/ssh_key_deploy.go
Original file line number Diff line number Diff line change
@@ -264,36 +264,43 @@ func deleteDeployKey(sess Engine, doer *User, id int64) error {
return nil
}

// ListDeployKeys returns all deploy keys by given repository ID.
func ListDeployKeys(repoID int64, listOptions ListOptions) ([]*DeployKey, error) {
return listDeployKeys(x, repoID, listOptions)
// ListDeployKeysOptions are options for ListDeployKeys
type ListDeployKeysOptions struct {
ListOptions
RepoID int64
KeyID int64
Fingerprint string
}

func (opt ListDeployKeysOptions) toCond() builder.Cond {
cond := builder.NewCond()
if opt.RepoID != 0 {
cond = cond.And(builder.Eq{"repo_id": opt.RepoID})
}
if opt.KeyID != 0 {
cond = cond.And(builder.Eq{"key_id": opt.KeyID})
}
if opt.Fingerprint != "" {
cond = cond.And(builder.Eq{"fingerprint": opt.Fingerprint})
}
return cond
}

// ListDeployKeys returns a list of deploy keys matching the provided arguments.
func ListDeployKeys(opts *ListDeployKeysOptions) ([]*DeployKey, error) {
return listDeployKeys(x, opts)
}

func listDeployKeys(e Engine, repoID int64, listOptions ListOptions) ([]*DeployKey, error) {
sess := e.Where("repo_id = ?", repoID)
if listOptions.Page != 0 {
sess = listOptions.setSessionPagination(sess)
func listDeployKeys(e Engine, opts *ListDeployKeysOptions) ([]*DeployKey, error) {
sess := e.Where(opts.toCond())

keys := make([]*DeployKey, 0, listOptions.PageSize)
if opts.Page != 0 {
sess = opts.setSessionPagination(sess)

keys := make([]*DeployKey, 0, opts.PageSize)
return keys, sess.Find(&keys)
}

keys := make([]*DeployKey, 0, 5)
return keys, sess.Find(&keys)
}

// SearchDeployKeys returns a list of deploy keys matching the provided arguments.
func SearchDeployKeys(repoID, keyID int64, fingerprint string) ([]*DeployKey, error) {
keys := make([]*DeployKey, 0, 5)
cond := builder.NewCond()
if repoID != 0 {
cond = cond.And(builder.Eq{"repo_id": repoID})
}
if keyID != 0 {
cond = cond.And(builder.Eq{"key_id": keyID})
}
if fingerprint != "" {
cond = cond.And(builder.Eq{"fingerprint": fingerprint})
}
return keys, x.Where(cond).Find(&keys)
}
19 changes: 8 additions & 11 deletions routers/api/v1/repo/key.go
Original file line number Diff line number Diff line change
@@ -75,26 +75,23 @@ func ListDeployKeys(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/DeployKeyList"

var keys []*models.DeployKey
var err error

fingerprint := ctx.Query("fingerprint")
keyID := ctx.QueryInt64("key_id")
if fingerprint != "" || keyID != 0 {
keys, err = models.SearchDeployKeys(ctx.Repo.Repository.ID, keyID, fingerprint)
} else {
keys, err = models.ListDeployKeys(ctx.Repo.Repository.ID, utils.GetListOptions(ctx))
opts := &models.ListDeployKeysOptions{
ListOptions: utils.GetListOptions(ctx),
RepoID: ctx.Repo.Repository.ID,
KeyID: ctx.QueryInt64("key_id"),
Fingerprint: ctx.Query("fingerprint"),
}

keys, err := models.ListDeployKeys(opts)
if err != nil {
ctx.Error(http.StatusInternalServerError, "ListDeployKeys", err)
ctx.InternalServerError(err)
return
}

apiLink := composeDeployKeysAPILink(ctx.Repo.Owner.Name + "/" + ctx.Repo.Repository.Name)
apiKeys := make([]*api.DeployKey, len(keys))
for i := range keys {
if err = keys[i].GetContent(); err != nil {
if err := keys[i].GetContent(); err != nil {
ctx.Error(http.StatusInternalServerError, "GetContent", err)
return
}
4 changes: 2 additions & 2 deletions routers/web/repo/setting.go
Original file line number Diff line number Diff line change
@@ -1002,7 +1002,7 @@ func DeployKeys(ctx *context.Context) {
ctx.Data["PageIsSettingsKeys"] = true
ctx.Data["DisableSSH"] = setting.SSH.Disabled

keys, err := models.ListDeployKeys(ctx.Repo.Repository.ID, models.ListOptions{})
keys, err := models.ListDeployKeys(&models.ListDeployKeysOptions{RepoID: ctx.Repo.Repository.ID})
if err != nil {
ctx.ServerError("ListDeployKeys", err)
return
@@ -1018,7 +1018,7 @@ func DeployKeysPost(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.settings.deploy_keys")
ctx.Data["PageIsSettingsKeys"] = true

keys, err := models.ListDeployKeys(ctx.Repo.Repository.ID, models.ListOptions{})
keys, err := models.ListDeployKeys(&models.ListDeployKeysOptions{RepoID: ctx.Repo.Repository.ID})
if err != nil {
ctx.ServerError("ListDeployKeys", err)
return