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

Show confirmation dialog if release created with existing tag #33316

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

Conversation

jackHay22
Copy link
Contributor

When creating a new release, a user may accidentally select an old tag. The current warning against this is fairly subtle. This PR adds a more descriptive warning and a confirmation dialog.

Screenshots

Screen Shot 2025-01-17 at 1 14 21 PM Screen Shot 2025-01-17 at 1 13 59 PM Screen Shot 2025-01-17 at 1 17 27 PM

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jan 17, 2025
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jan 17, 2025
@github-actions github-actions bot added modifies/translation modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files modifies/frontend labels Jan 17, 2025
@jackHay22 jackHay22 changed the title Show confirmation dialog if release created with new tag Show confirmation dialog if release created with existing tag Jan 17, 2025
@techknowlogick techknowlogick added the topic/ui Change the appearance of the Gitea UI label Jan 17, 2025
@@ -38,6 +38,9 @@
</div>
</div>
</div>
<div id="tag-warning" class="gt-dib gt-hidden" data-commit-url-stub="{{.RepoLink}}/commit">
{{svg "octicon-alert-fill" 16}} Existing tag referencing <span class="gt-px-3">{{svg "octicon-git-commit" 16}} <a target="_blank" rel="noopener noreferrer" class="tag-warning-detail"></a></span>
</div>
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this warning is good enough.

We can make it more prominent, then the modals could (should) be removed.

The problem is that:

  • There are too many duplicate warnings when using the modal.
  • There are too many problems in the modal related code (so remove the modals, then we do not need to spend time on it)

@@ -330,9 +330,9 @@ func newReleaseCommon(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.release.new_release")
ctx.Data["PageIsReleaseList"] = true

tags, err := repo_model.GetTagNamesByRepoID(ctx, ctx.Repo.Repository.ID)
tags, err := repo_model.GetTagMappingsByRepoID(ctx, ctx.Repo.Repository.ID)
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not think it is right because GetTagNamesByRepoID does order by, but map is unordered,

Comment on lines +316 to +319
// CountReleasesByRepoID returns a number of releases matching FindReleaseOptions and RepoID.
func CountReleasesByRepoID(ctx context.Context, repoID int64, opts FindReleasesOptions) (int64, error) {
return db.GetEngine(ctx).Where(opts.ToConds()).Count(new(Release))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Dead code?

@@ -38,6 +38,9 @@
</div>
</div>
</div>
<div id="tag-warning" class="gt-dib gt-hidden" data-commit-url-stub="{{.RepoLink}}/commit">
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no such gt-xxx helpers.

Copy link
Member

Choose a reason for hiding this comment

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

Right, they are tw- nowadays

Copy link
Member

Choose a reason for hiding this comment

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

Should be tw-inline-block tw-hidden

@@ -38,6 +38,9 @@
</div>
</div>
</div>
<div id="tag-warning" class="gt-dib gt-hidden" data-commit-url-stub="{{.RepoLink}}/commit">
{{svg "octicon-alert-fill" 16}} Existing tag referencing <span class="gt-px-3">{{svg "octicon-git-commit" 16}} <a target="_blank" rel="noopener noreferrer" class="tag-warning-detail"></a></span>
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to translate.

@@ -21,24 +23,66 @@ function initTagNameEditor() {
const el = document.querySelector('#tag-name-editor');
if (!el) return;

const tagWarning = document.querySelector('#tag-warning');
const tagWarningDetailLinks = Array.from(document.querySelectorAll('.tag-warning-detail'));
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const tagWarningDetailLinks = Array.from(document.querySelectorAll('.tag-warning-detail'));
const tagWarningDetailLinks = document.querySelectorAll<HTMLAnchorElement>('.tag-warning-detail');

This avoids the as further below and array convertion is unnecessary as for-of can iterate NodeList just fine.

Comment on lines +75 to +79
for (const detail of tagWarningDetailLinks) {
const anchor = detail as HTMLAnchorElement;
anchor.href = `${tagURLStub}/${existingTags[value]}`;
anchor.textContent = existingTags[value].substring(0, 10);
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
for (const detail of tagWarningDetailLinks) {
const anchor = detail as HTMLAnchorElement;
anchor.href = `${tagURLStub}/${existingTags[value]}`;
anchor.textContent = existingTags[value].substring(0, 10);
}
for (const link of tagWarningDetailLinks) {
link.href = `${tagURLStub}/${encodeURIComponent(existingTags[value])}`;
link.textContent = existingTags[value].substring(0, 10);
}

Not totally sure whether encodeURIComponent is needed, but the other changes should be good.

Copy link
Contributor

Choose a reason for hiding this comment

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

Most of the JS code could be removed, see #33316 (comment)

I do not think it's worth to spend more time on JS code for this case.


const tagNameInput = document.querySelector<HTMLInputElement>('#tag-name');
const hideTargetInput = function(tagNameInput: HTMLInputElement) {
const value = tagNameInput.value;
const tagHelper = document.querySelector('#tag-helper');
if (existingTags.includes(value)) {
if (value in existingTags) {
Copy link
Member

@silverwind silverwind Jan 22, 2025

Choose a reason for hiding this comment

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

Is existingTags an array? Then .includes was definitely fine. in should only be used to check key existance in objects.

@wxiaoguang
Copy link
Contributor

@jackHay22 what do you think? Especially #33316 (review) , the new JS code is more complicated than it should be and quite fragile.

I prefer to only use a prominent warning message, do not introduce more modal/JS code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. modifies/frontend modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files modifies/translation size/L Denotes a PR that changes 100-499 lines, ignoring generated files. topic/ui Change the appearance of the Gitea UI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants