Skip to content

feat: api endpoints for projects #28111

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

Open
wants to merge 51 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
4c0ec22
test: add 2 fixtures for project
dineshsalunke Nov 18, 2023
6092b81
refactor: add structs for project
dineshsalunke Nov 18, 2023
b6f9d05
feat: api for projects
dineshsalunke Nov 18, 2023
b6d45c6
Merge branch 'main' into feat/api-projects
dineshsalunke Nov 20, 2023
922cd13
Merge remote-tracking branch 'upstream/main' into feat/api-projects
dineshsalunke Nov 20, 2023
0b8d198
Merge branch 'feat/api-projects' of https://github.com/dineshsalunke/…
dineshsalunke Nov 20, 2023
e0ae281
Merge branch 'main' into feat/api-projects
GiteaBot Jan 15, 2024
a0f8dbd
chore: remove unnecessary go lines formatting
dineshsalunke Jan 16, 2024
ac39273
Merge branch 'feat/api-projects' of https://github.com/dineshsalunke/…
dineshsalunke Jan 16, 2024
df22b6d
chore: remove the goline formatting
dineshsalunke Jan 16, 2024
5bbbade
chore: remove unwanted indentation on the line
dineshsalunke Jan 16, 2024
c266568
Merge remote-tracking branch 'upstream/main' into feat/api-projects
dineshsalunke Jan 17, 2024
aa32ad7
refactor: update for db find method usage
dineshsalunke Jan 17, 2024
81c3d0c
fix: add missing swagger tags
dineshsalunke Jan 17, 2024
852c0df
chore: fix lint issues
dineshsalunke Jan 17, 2024
dbfecce
fix: return error when converting project to api project
dineshsalunke Jan 17, 2024
fec855e
chore: fix swagger documentation
dineshsalunke Jan 17, 2024
6238b9e
fix: ignore errors when loading data for converting project to response
dineshsalunke Jan 17, 2024
8819a0a
refactor: use the add token auth method for token in tests
dineshsalunke Jan 17, 2024
3b2943a
test: use the add token auth method for token
dineshsalunke Jan 17, 2024
cf17f34
Merge remote-tracking branch 'upstream/main' into feat/api-projects
dineshsalunke Jan 19, 2024
7eebc7c
Merge remote-tracking branch 'upstream/main' into feat/api-projects
dineshsalunke Jan 20, 2024
d2fd138
test: use the correct fields for the test case
dineshsalunke Jan 20, 2024
34566ea
Merge branch 'main' into feat/api-projects
denyskon Jan 21, 2024
897c67b
revert formatting changes
denyskon Jan 21, 2024
c7440bc
Merge branch 'main' into feat/api-projects
denyskon Jan 21, 2024
065001c
more reverts
denyskon Jan 21, 2024
24babd6
Merge branch 'feat/api-projects' of github.com:dineshsalunke/gitea in…
denyskon Jan 21, 2024
58e56cd
more formatting fixes
denyskon Jan 21, 2024
74043f7
fix project sort test
denyskon Jan 21, 2024
fac47d4
Merge remote-tracking branch 'upstream/main' into feat/api-projects
dineshsalunke Jan 22, 2024
4475c4f
actually fix test!
denyskon Jan 22, 2024
e751d6c
Merge branch 'feat/api-projects' of github.com:dineshsalunke/gitea in…
denyskon Jan 22, 2024
6a18cbe
Merge branch 'main' into feat/api-projects
denyskon Jan 25, 2024
927da10
chore: swagger doc typo corrections
dineshsalunke Jan 26, 2024
975d98d
chore: remove redundant comment
dineshsalunke Jan 26, 2024
d4ea5a5
fix: use the page field from parameters
dineshsalunke Jan 26, 2024
24a302a
Merge branch 'feat/api-projects' of https://github.com/dineshsalunke/…
dineshsalunke Jan 26, 2024
c5c41e3
Merge remote-tracking branch 'upstream/main' into feat/api-projects
dineshsalunke Jan 26, 2024
0a0837f
chore: update the swagger file
dineshsalunke Jan 26, 2024
23d9697
Merge branch 'main' into feat/api-projects
denyskon Jan 27, 2024
a2a01df
Merge branch 'main' into feat/api-projects
denyskon Feb 5, 2024
b931054
Merge remote-tracking branch 'upstream/main' into feat/api-projects
Sep 22, 2024
a7aabc5
refactor: add the missing parameter bodies for project
Sep 22, 2024
7383e7b
refactor: rename BoardType to TemplateType
Sep 22, 2024
016aa72
refactor: add creator property to the project
Sep 22, 2024
d067b1d
refactor: add BoardType to TemplateType property
Sep 22, 2024
eeca89e
refactor: handle errors when converting to APIProject
Sep 22, 2024
20e9c58
Merge remote-tracking branch 'upstream/main' into feat/api-projects
dineshsalunke Sep 23, 2024
185a594
refactor: update the context
dineshsalunke Sep 23, 2024
30027ac
refactor: update the board type enums
dineshsalunke Sep 23, 2024
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
9 changes: 9 additions & 0 deletions models/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ type Project struct {
RepoID int64 `xorm:"INDEX"`
Repo *repo_model.Repository `xorm:"-"`
CreatorID int64 `xorm:"NOT NULL"`
Creator *user_model.User `xorm:"-"`
IsClosed bool `xorm:"INDEX"`
TemplateType TemplateType `xorm:"'board_type'"` // TODO: rename the column to template_type
CardType CardType
Expand Down Expand Up @@ -118,6 +119,14 @@ func (p *Project) LoadOwner(ctx context.Context) (err error) {
return err
}

func (p *Project) LoadCreator(ctx context.Context) (err error) {
if p.Creator != nil {
return nil
}
p.Creator, err = user_model.GetUserByID(ctx, p.CreatorID)
return err
}

func (p *Project) LoadRepo(ctx context.Context) (err error) {
if p.RepoID == 0 || p.Repo != nil {
return nil
Expand Down
43 changes: 43 additions & 0 deletions modules/structs/project.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package structs

import "time"

// swagger:model
type NewProjectPayload struct {
// required:true
Title string `json:"title" binding:"Required"`
// required:true
BoardType uint8 `json:"board_type"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TemplateType to align with other places?

// required:true
CardType uint8 `json:"card_type"`
Description string `json:"description"`
}

// swagger:model
type UpdateProjectPayload struct {
// required:true
Title string `json:"title" binding:"Required"`
Description string `json:"description"`
}

// swagger:model
type Project struct {
ID int64 `json:"id"`
Title string `json:"title"`
Description string `json:"description"`
TemplateType uint8 `json:"board_type"`
IsClosed bool `json:"is_closed"`
// swagger:strfmt date-time
Created time.Time `json:"created_at"`
// swagger:strfmt date-time
Updated time.Time `json:"updated_at"`
// swagger:strfmt date-time
Closed time.Time `json:"closed_at"`

Repo *RepositoryMeta `json:"repository"`
Creator *User `json:"creator"`
Owner *User `json:"owner"`
}
10 changes: 10 additions & 0 deletions routers/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ import (
"code.gitea.io/gitea/routers/api/v1/notify"
"code.gitea.io/gitea/routers/api/v1/org"
"code.gitea.io/gitea/routers/api/v1/packages"
"code.gitea.io/gitea/routers/api/v1/projects"
"code.gitea.io/gitea/routers/api/v1/repo"
"code.gitea.io/gitea/routers/api/v1/settings"
"code.gitea.io/gitea/routers/api/v1/user"
Expand Down Expand Up @@ -1454,6 +1455,10 @@ func Routes() *web.Router {
Patch(reqToken(), reqRepoWriter(unit.TypeIssues, unit.TypePullRequests), bind(api.EditMilestoneOption{}), repo.EditMilestone).
Delete(reqToken(), reqRepoWriter(unit.TypeIssues, unit.TypePullRequests), repo.DeleteMilestone)
})
m.Group("/projects", func() {
m.Combo("").Get(projects.ListRepoProjects).
Post(bind(api.NewProjectPayload{}), projects.CreateRepoProject)
}, mustEnableIssues)
}, repoAssignment())
}, tokenRequiresScopes(auth_model.AccessTokenScopeCategoryIssue))

Expand Down Expand Up @@ -1598,6 +1603,11 @@ func Routes() *web.Router {
})
}, tokenRequiresScopes(auth_model.AccessTokenScopeCategoryAdmin), reqToken(), reqSiteAdmin())

m.Group("/projects", func() {
m.Combo("/{id}").Get(projects.GetProject).
Patch(bind(api.UpdateProjectPayload{}), projects.UpdateProject).
Delete(projects.DeleteProject)
}, tokenRequiresScopes(auth_model.AccessTokenScopeCategoryIssue), reqToken())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need a new token scope AccessTokenScopeCategoryProject.

m.Group("/topics", func() {
m.Get("/search", repo.TopicSearch)
}, tokenRequiresScopes(auth_model.AccessTokenScopeCategoryRepository))
Expand Down
Loading
Loading