The Wayback Machine - https://web.archive.org/web/20220507124428/https://github.com/go-gitea/gitea/pull/17935
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

Add API to manage issue dependencies #17935

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open

Conversation

Copy link
Contributor

@qwerty287 qwerty287 commented Dec 8, 2021

Adds API endpoints to manage issue/PR dependencies

  • GET /repos/{owner}/{repo}/issues/{index}/blocks List issues that are blocked by this issue
  • POST /repos/{owner}/{repo}/issues/{index}/blocks Block the issue given in the body by the issue in path
  • DELETE /repos/{owner}/{repo}/issues/{index}/blocks Unblock the issue given in the body by the issue in path
  • GET /repos/{owner}/{repo}/issues/{index}/dependencies List an issue's dependencies
  • POST /repos/{owner}/{repo}/issues/{index}/dependencies Create a new issue dependencies
  • DELETE /repos/{owner}/{repo}/issues/{index}/dependencies Remove an issue dependency

Closes #15393

@lunny lunny added the kind/api label Dec 10, 2021
@lunny lunny added this to the 1.17.0 milestone Dec 10, 2021
@codecov-commenter
Copy link

@codecov-commenter codecov-commenter commented Jan 7, 2022

Codecov Report

Merging #17935 (6d983bd) into main (d242511) will decrease coverage by 0.14%.
The diff coverage is 1.90%.

@@            Coverage Diff             @@
##             main   #17935      +/-   ##
==========================================
- Coverage   47.51%   47.36%   -0.15%     
==========================================
  Files         944      944              
  Lines      131549   131969     +420     
==========================================
+ Hits        62500    62510      +10     
- Misses      61541    61950     +409     
- Partials     7508     7509       +1     
Impacted Files Coverage Δ
modules/structs/issue.go 0.00% <ø> (ø)
routers/api/v1/repo/issue.go 36.05% <0.00%> (-18.57%) ⬇️
routers/api/v1/api.go 76.64% <100.00%> (+0.20%) ⬆️
modules/queue/queue_channel.go 76.85% <0.00%> (-4.63%) ⬇️
modules/charset/charset.go 69.74% <0.00%> (-4.21%) ⬇️
modules/git/utils.go 66.29% <0.00%> (-3.38%) ⬇️
modules/queue/workerpool.go 52.59% <0.00%> (-1.04%) ⬇️
modules/git/batch_reader.go 55.65% <0.00%> (+1.30%) ⬆️
models/unit/unit.go 47.82% <0.00%> (+1.73%) ⬆️
modules/git/repo_base_nogogit.go 76.47% <0.00%> (+1.96%) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5ae875a...6d983bd. Read the comment docs.

issue, err := models.GetIssueWithAttrsByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
if models.IsErrIssueNotExist(err) {
ctx.NotFound("IsErrIssueNotExist", err)
} else {
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
}
return
}

deps, err := issue.BlockedByDependencies()
if err != nil {
ctx.Error(http.StatusInternalServerError, "BlockedByDependencies", err)
return
}

page := ctx.FormInt("page")
if page <= 1 {
page = 1
}
limit := ctx.FormInt("limit")
if limit <= 1 {
limit = setting.API.DefaultPagingNum
}

skip := (page - 1) * limit
max := page * limit

var issues []*models.Issue
for i, depMeta := range deps {
if i < skip || i >= max {
continue
}
depMeta.Issue.Repo = &depMeta.Repository
issues = append(issues, &depMeta.Issue)
}

Copy link
Contributor

@zeripath zeripath Jan 8, 2022

Choose a reason for hiding this comment

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

Usually when you're writing paging code you're attempting to reduce the load on the server and the DB by not getting everything out of the db at once. Here you're collecting almost all of the information then simply throwing it away. Is there not a way of just getting the right dependencies out?

I'd also argue that it seems like the issue is only used to get the blocking dependencies before being thrown away - in which case it seems like it's not really needed so perhaps we could just get the blocking issues out directly. In particular GetIssueWithAttrsByIndex is loading all of the comments and attachments of the base issue to simply then throw them out! BlockedByDependencies does not need the attributes to be loaded so you don't need that.

In some ways these APIs are unlikely to be called much so the fact that they're not very efficient is not really relevant but it's a point that we should be considering.

routers/api/v1/repo/issue.go Outdated Show resolved Hide resolved
routers/api/v1/repo/issue.go Outdated Show resolved Hide resolved
routers/api/v1/repo/issue.go Outdated Show resolved Hide resolved
routers/api/v1/repo/issue.go Outdated Show resolved Hide resolved
routers/api/v1/repo/issue.go Outdated Show resolved Hide resolved
Copy link
Contributor

@zeripath zeripath left a comment

There is a serious security problem in this code. Not only can I use these endpoints to check if any repository exists but I can read any issue on any repository using this.

}

form := web.GetForm(ctx).(*api.IssueMeta)
repo, err := repo_model.GetRepositoryByOwnerAndName(form.Owner, form.Name)
Copy link
Contributor

@zeripath zeripath Jan 8, 2022

Choose a reason for hiding this comment

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

We probably need to think a bit about permissions here.

When can I add an issue from another repository as a blocker to my issue?

What permissions do I need to have and in which repository?

At present this code can be used to determine not only if a repository exists - but if an issue exists in that repository and then render it out to me!

repo, err := repo_model.GetRepositoryByOwnerAndName(form.Owner, form.Name)
if err != nil {
if repo_model.IsErrRepoNotExist(err) {
ctx.NotFound("IsErrRepoNotExist", err)
} else {
ctx.Error(http.StatusInternalServerError, "GetRepositoryByOwnerAndName", err)
}
return
}
Copy link
Contributor

@zeripath zeripath Jan 8, 2022

Choose a reason for hiding this comment

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

We really need to consider permissions here.

return
}

ctx.JSON(http.StatusCreated, convert.ToAPIIssue(dep))
Copy link
Contributor

@zeripath zeripath Jan 8, 2022

Choose a reason for hiding this comment

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

You really need to check if I have permission to read this issue!! Using this endpoint I could read any issue from any repository on the server!

issues = append(issues, &depMeta.Issue)
}

ctx.JSON(http.StatusOK, convert.ToAPIIssueList(issues))
Copy link
Contributor

@zeripath zeripath Jan 8, 2022

Choose a reason for hiding this comment

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

Need to check if I have permission to read these issues!!

issues = append(issues, &depMeta.Issue)
}

ctx.JSON(http.StatusOK, convert.ToAPIIssueList(issues))
Copy link
Contributor

@zeripath zeripath Jan 8, 2022

Choose a reason for hiding this comment

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

Need to check if I have permission to read these issues!!

return
}

ctx.JSON(http.StatusOK, convert.ToAPIIssue(dep))
Copy link
Contributor

@zeripath zeripath Jan 8, 2022

Choose a reason for hiding this comment

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

Need to check if I have permission to read these issues!!

Copy link
Contributor Author

@qwerty287 qwerty287 Jan 9, 2022

Choose a reason for hiding this comment

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

@zeripath Thanks, I understood it 😄

@qwerty287
Copy link
Author

@qwerty287 qwerty287 commented Jan 12, 2022

@zeripath I added permission checks in dde1c05. Could you please review it?

@qwerty287 qwerty287 requested a review from zeripath Mar 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

6 participants