WIP: Add Labels to Milestones #17265

Draft
techknowlogick wants to merge 7 commits from techknowlogick/milestone-labels into main
Contributor

Fix #17244

Marked as WIP as I haven't completed the UI yet, but the API and the structs/migrations are complete.

cc: @chriseaton

Fix #17244 Marked as WIP as I haven't completed the UI yet, but the API and the structs/migrations are complete. cc: @chriseaton
delvh reviewed 2021-10-08 09:01:12 +00:00
Contributor

What do you mean by UNIQUE(s)?
Shouldn't it be UNIQUE(milestoneid_labelid) or something similar?

What do you mean by `UNIQUE(s)`? Shouldn't it be `UNIQUE(milestoneid_labelid)` or something similar?
Contributor

Why are those lines necessary?
That goes far beyond deleting the relation and rather seems like a copy-paste error, doesn't it?

Why are those lines necessary? That goes far beyond deleting the relation and rather seems like a copy-paste error, doesn't it? ```suggestion ```
Contributor
	if err = milestone.loadLabels(e); err != nil {
```suggestion if err = milestone.loadLabels(e); err != nil { ```
Contributor
// ReplaceLabels removes all current labels and adds the given labels to the milestone.
```suggestion // ReplaceLabels removes all current labels and adds the given labels to the milestone. ```
Contributor
```suggestion ```
@ -0,0 +71,4 @@
}
// Do NOT add invalid labels
if milestone.RepoID != label.RepoID && milestone.Repo.OwnerID != label.OrgID {
Contributor

I can understand the first condition, but why the second condition?
And why is it combined with an &&?

I can understand the first condition, but why the second condition? And why is it combined with an `&&`?
@ -0,0 +92,4 @@
for _, label := range labels {
// Don't add already present labels and invalid labels
if hasMilestoneLabel(e, milestone.ID, label.ID) ||
(label.RepoID != milestone.RepoID && label.OrgID != milestone.Repo.OwnerID) {
Contributor

I have the feeling that this check should be extracted into its own function as you use it more than once.
And I'm still confused by it.
It could be called i.e. isMilestoneLabelPairValid or something like that.

I have the feeling that this check should be extracted into its own function as you use it more than once. And I'm still confused by it. It could be called i.e. `isMilestoneLabelPairValid` or something like that.
@ -0,0 +110,4 @@
if err != nil {
return err
}
defer committer.Close()
Contributor

Shouldn't the ctx be closed as well, or does the committer suffice?

Shouldn't the `ctx` be closed as well, or does the committer suffice?
@ -0,0 +157,4 @@
}
func (milestone *Milestone) loadLabels(e db.Engine) (err error) {
if milestone.Labels == nil {
Contributor

Only this line differs between this method and getLabels:
if len(milestone.Labels) > 0 {
Which one should be taken then?
Afterwards, the other method can be deleted.

Only this line differs between this method and `getLabels`: `if len(milestone.Labels) > 0 {` Which one should be taken then? Afterwards, the other method can be deleted.
@ -0,0 +213,4 @@
if err != nil {
return err
}
defer committer.Close()
Contributor

See above regarding ctx.

See above regarding `ctx`.
@ -0,0 +293,4 @@
milestone.Labels = nil
if err = milestone.loadLabels(db.GetEngine(ctx)); err != nil {
return err
}
Contributor

That seems overly complicated for what you are trying to achieve.
I thought you wanted to clear all labels and set only the ones given as a parameter?
That can be achieved much more clearly: Drop all labels and then add all given labels to the milestone.
I refuse to review this method in the current implementation.

That seems overly complicated for what you are trying to achieve. I thought you wanted to clear all labels and set only the ones given as a parameter? That can be achieved much more clearly: Drop all labels and then add all given labels to the milestone. I refuse to review this method in the current implementation.
Contributor
	// summary: Drop all previous milestone labels and replace them with new labels
```suggestion // summary: Drop all previous milestone labels and replace them with new labels ```
@ -0,0 +143,4 @@
// "$ref": "#/responses/empty"
// "403":
// "$ref": "#/responses/forbidden"
// "422":
Contributor

Where does it return that?
The http.StatusUnprocessableEntity?

Where does it return that? The `http.StatusUnprocessableEntity`?
delvh reviewed 2021-10-08 09:18:18 +00:00
@ -100,0 +116,4 @@
return fmt.Errorf("addLabel [id: %d]: %v", label.ID, err)
}
}
}
Contributor

As mentioned: Make that a method! I've seen it at list four times now.

As mentioned: Make that a method! I've seen it at list four times now.
@ -119,0 +128,4 @@
}
}
labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID, "", db.ListOptions{})
Contributor

Why can't it be 0? Is such a label name prohibited?

Why can't it be `0`? Is such a label name prohibited?
@ -0,0 +1,9 @@
<a
Contributor

Is there a reason why you don't just use the template that is used for issue labels?
Because if there is not, then I'd recommend for maintainability purposes to use only the existing one.

Is there a reason why you don't just use the template that is used for issue labels? Because if there is not, then I'd recommend for maintainability purposes to use only the existing one.
@ -0,0 +1,11 @@
<div class="ui labels list">
Contributor

Again, isn't there an issue equivalent you can use?
If yes, then please use that to improve future maintainability.

Again, isn't there an `issue` equivalent you can use? If yes, then please use that to improve future maintainability.
@ -40,2 +40,4 @@
<textarea name="content">{{.content}}</textarea>
</div>
<div class="ui segment metas">
<input id="label_ids" name="label_ids" type="hidden" value="{{.label_ids}}">
Contributor

Can't you reuse the template that is used for issues here as well? (If it isn't a template yet make it!)
Again, I don't see a reason why we should impact future maintainability if not necessary.

Can't you reuse the template that is used for issues here as well? (If it isn't a template yet **make it**!) Again, I don't see a reason why we should impact future maintainability if not necessary.
@ -396,7 +396,7 @@ function initSimpleMDEImagePaste(simplemde, dropzone, files) {
let autoSimpleMDE;
Contributor

?

?
techknowlogick reviewed 2021-10-13 19:43:30 +00:00
@ -0,0 +71,4 @@
}
// Do NOT add invalid labels
if milestone.RepoID != label.RepoID && milestone.Repo.OwnerID != label.OrgID {
Author
Contributor

Because org labels should be allow too, so if the label doesn't belong to the repo OR the org THEN skip adding

Because org labels should be allow too, so if the label doesn't belong to the repo OR the org THEN skip adding
This repo is archived. You cannot comment on pull requests.
No reviewers
No Milestone
No project
No Assignees
2 Participants
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: lunny/gitea#17265
No description provided.