-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
base: main
Are you sure you want to change the base?
Conversation
@@ -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> |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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,
// 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)) | ||
} |
There was a problem hiding this comment.
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"> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
for (const detail of tagWarningDetailLinks) { | ||
const anchor = detail as HTMLAnchorElement; | ||
anchor.href = `${tagURLStub}/${existingTags[value]}`; | ||
anchor.textContent = existingTags[value].substring(0, 10); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
@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. |
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