Skip to content

WIP: Add Labels to Milestones #17265

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

Closed
wants to merge 7 commits into from

Conversation

techknowlogick
Copy link
Member

Fix #17244

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

cc: @chriseaton

@techknowlogick techknowlogick added type/feature Completely new functionality. Can only be merged if feature freeze is not active. topic/ui Change the appearance of the Gitea UI labels Oct 8, 2021
@techknowlogick techknowlogick added this to the 1.16.0 milestone Oct 8, 2021
@techknowlogick techknowlogick self-assigned this Oct 8, 2021
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) {
Copy link
Member

Choose a reason for hiding this comment

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

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.

if err != nil {
return err
}
defer committer.Close()
Copy link
Member

Choose a reason for hiding this comment

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

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

}

func (milestone *Milestone) loadLabels(e db.Engine) (err error) {
if milestone.Labels == nil {
Copy link
Member

Choose a reason for hiding this comment

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

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.

Comment on lines +266 to +313

sort.Sort(labelSorter(labels))
sort.Sort(labelSorter(milestone.Labels))

var toAdd, toRemove []*Label

addIndex, removeIndex := 0, 0
for addIndex < len(labels) && removeIndex < len(milestone.Labels) {
addLabel := labels[addIndex]
removeLabel := milestone.Labels[removeIndex]
if addLabel.ID == removeLabel.ID {
// Silently drop invalid labels
if removeLabel.RepoID != milestone.RepoID && removeLabel.OrgID != milestone.Repo.OwnerID {
toRemove = append(toRemove, removeLabel)
}

addIndex++
removeIndex++
} else if addLabel.ID < removeLabel.ID {
// Only add if the label is valid
if addLabel.RepoID == milestone.RepoID || addLabel.OrgID == milestone.Repo.OwnerID {
toAdd = append(toAdd, addLabel)
}
addIndex++
} else {
toRemove = append(toRemove, removeLabel)
removeIndex++
}
}
toAdd = append(toAdd, labels[addIndex:]...)
toRemove = append(toRemove, milestone.Labels[removeIndex:]...)

if len(toAdd) > 0 {
if err = milestone.addLabels(db.GetEngine(ctx), toAdd, doer); err != nil {
return fmt.Errorf("addLabels: %v", err)
}
}

for _, l := range toRemove {
if err = milestone.removeLabel(db.GetEngine(ctx), doer, l); err != nil {
return fmt.Errorf("removeLabel: %v", err)
}
}

milestone.Labels = nil
if err = milestone.loadLabels(db.GetEngine(ctx)); err != nil {
return err
}
Copy link
Member

Choose a reason for hiding this comment

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

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.

// "$ref": "#/responses/empty"
// "403":
// "$ref": "#/responses/forbidden"
// "422":
Copy link
Member

Choose a reason for hiding this comment

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

Where does it return that?
The http.StatusUnprocessableEntity?

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Oct 8, 2021

for _, label := range labels {
// Silently drop invalid labels.
if label.RepoID != m.Repo.ID && label.OrgID != m.Repo.OwnerID {
Copy link
Member

Choose a reason for hiding this comment

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

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

var labelIDs []int64
var err error
selectLabels := ctx.FormString("labels")
if len(selectLabels) > 0 && selectLabels != "0" {
Copy link
Member

Choose a reason for hiding this comment

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

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

@@ -0,0 +1,9 @@
<a
Copy link
Member

Choose a reason for hiding this comment

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

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">
Copy link
Member

Choose a reason for hiding this comment

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

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

@@ -393,8 +393,8 @@ function initSimpleMDEImagePaste(simplemde, dropzone, files) {
let autoSimpleMDE;

function initCommentForm() {
if ($('.comment.form').length === 0) {
return;
if ($('.comment.form').length === 0 && $('.select-label').length < 1) {
Copy link
Member

Choose a reason for hiding this comment

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

?

@@ -39,6 +39,40 @@
<label>{{.i18n.Tr "repo.milestones.desc"}}</label>
<textarea name="content">{{.content}}</textarea>
</div>
<div class="ui segment metas">
<input id="label_ids" name="label_ids" type="hidden" value="{{.label_ids}}">
Copy link
Member

Choose a reason for hiding this comment

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

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.

@techknowlogick techknowlogick marked this pull request as draft October 13, 2021 18:46
@lunny lunny removed this from the 1.16.0 milestone Nov 9, 2021
@TKDev7
Copy link

TKDev7 commented Dec 6, 2021

@techknowlogick Are you still working on this?

@bqv
Copy link

bqv commented Mar 2, 2022

@MrHBS are you?

@go-gitea go-gitea locked and limited conversation to collaborators May 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. topic/ui Change the appearance of the Gitea UI type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] Milestone Labels
7 participants