mirror of
https://github.com/go-gitea/gitea.git
synced 2025-12-15 21:45:35 +08:00
fix
This commit is contained in:
parent
7444449124
commit
e8b379a38d
@ -1294,6 +1294,7 @@ commit = Commit
|
||||
release = Release
|
||||
releases = Releases
|
||||
tag = Tag
|
||||
git_tag = Git Tag
|
||||
released_this = released this
|
||||
tagged_this = tagged this
|
||||
file.title = %s at %s
|
||||
@ -2755,12 +2756,12 @@ release.add_tag_msg = Use the title and content of release as tag message.
|
||||
release.add_tag = Create Tag Only
|
||||
release.releases_for = Releases for %s
|
||||
release.tags_for = Tags for %s
|
||||
release.notes = Release notes
|
||||
release.generate_notes = Generate release notes
|
||||
release.generate_notes_desc = Automatically add merged pull requests and a changelog link for this release.
|
||||
release.previous_tag = Previous tag
|
||||
release.previous_tag_auto = Auto
|
||||
release.generate_notes_tag_not_found = Tag "%s" does not exist in this repository.
|
||||
release.generate_notes_no_base_tag = No previous tag found to generate release notes.
|
||||
release.generate_notes_target_not_found = The release target "%s" cannot be found.
|
||||
release.generate_notes_missing_tag = Enter a tag name to generate release notes.
|
||||
|
||||
|
||||
@ -212,17 +212,18 @@ func findPreviousTagName(tags []*git.Tag, target string) (string, bool) {
|
||||
}
|
||||
|
||||
func parseSemanticVersion(tag string) *version.Version {
|
||||
tag = strings.TrimSpace(tag)
|
||||
tag = strings.TrimPrefix(tag, "v")
|
||||
tag = strings.TrimPrefix(tag, "V")
|
||||
v, err := version.NewVersion(tag)
|
||||
if err != nil {
|
||||
return nil
|
||||
if pos := strings.LastIndexByte(tag, '/'); pos >= 0 {
|
||||
tag = tag[pos+1:]
|
||||
}
|
||||
tag = strings.TrimLeft(tag, "vV")
|
||||
v, _ := version.NewVersion(tag)
|
||||
return v
|
||||
}
|
||||
|
||||
func findInitialCommit(commit *git.Commit) (*git.Commit, error) {
|
||||
// FIXME: this method is inefficient for large repos with long histories, and it doesn't seem right:
|
||||
// FIXME: "git diff aaaa...bbbb" doesn't include commits from "aaaa", so the changes in "root commit" won't appear in the tag release's diff.
|
||||
// No idea whether we should really make things so complicated.
|
||||
current := commit
|
||||
for current.ParentCount() > 0 {
|
||||
parent, err := current.Parent(0)
|
||||
|
||||
@ -12,21 +12,25 @@
|
||||
{{end}}
|
||||
</h2>
|
||||
{{template "base/alert" .}}
|
||||
<form class="ui form" action="{{.Link}}" method="post">
|
||||
|
||||
<form class="ui form" action="{{.Link}}" method="post" data-global-init="initReleaseEditForm"
|
||||
data-existing-tags="{{JsonUtils.EncodeToString .Tags}}"
|
||||
data-tag-helper="{{ctx.Locale.Tr "repo.release.tag_helper"}}"
|
||||
data-tag-helper-new="{{ctx.Locale.Tr "repo.release.tag_helper_new"}}"
|
||||
data-tag-helper-existing="{{ctx.Locale.Tr "repo.release.tag_helper_existing"}}"
|
||||
>
|
||||
{{.CsrfTokenHtml}}
|
||||
<div class="ui seven wide target">
|
||||
<div class="inline field {{if .Err_TagName}}error{{end}}">
|
||||
<label class="tw-block tw-mb-1"><b>{{ctx.Locale.Tr "repo.git_tag"}}</b></label>
|
||||
{{if .PageIsEditRelease}}
|
||||
<input id="tag-name" type="hidden" name="tag_name" value="{{.tag_name}}">
|
||||
<input type="hidden" name="tag_name" value="{{.tag_name}}">
|
||||
<input type="hidden" name="tag_target" value="{{.tag_target}}">
|
||||
<div class="inline field">
|
||||
<b>{{.tag_name}}</b><span class="at">@</span><strong>{{.tag_target}}</strong>
|
||||
</div>
|
||||
<span>{{.tag_name}} @ {{.tag_target}}</span>
|
||||
{{else}}
|
||||
<div class="inline field {{if .Err_TagName}}error{{end}}">
|
||||
<input id="tag-name" name="tag_name" value="{{.tag_name}}" aria-label="{{ctx.Locale.Tr "repo.release.tag_name"}}" placeholder="{{ctx.Locale.Tr "repo.release.tag_name"}}" autofocus required maxlength="255">
|
||||
<input id="tag-name-editor" type="hidden" data-existing-tags="{{JsonUtils.EncodeToString .Tags}}" data-tag-helper="{{ctx.Locale.Tr "repo.release.tag_helper"}}" data-tag-helper-new="{{ctx.Locale.Tr "repo.release.tag_helper_new"}}" data-tag-helper-existing="{{ctx.Locale.Tr "repo.release.tag_helper_existing"}}">
|
||||
<div id="tag-target-selector" class="tw-inline-block">
|
||||
<span class="at">@</span>
|
||||
<div class="flex-text-block tw-flex-wrap">
|
||||
<input type="text" class="tw-w-auto" name="tag_name" value="{{.tag_name}}" aria-label="{{ctx.Locale.Tr "repo.release.tag_name"}}" placeholder="{{ctx.Locale.Tr "repo.release.tag_name"}}" autofocus required maxlength="255">
|
||||
<div class="tag-target-selector tw-contents">
|
||||
<span>@</span>
|
||||
<div class="ui selection dropdown">
|
||||
<input type="hidden" name="tag_target" value="{{.tag_target}}">
|
||||
{{svg "octicon-git-branch"}}
|
||||
@ -42,120 +46,124 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<span id="tag-helper" class="help tw-mt-2 tw-pb-0">{{ctx.Locale.Tr "repo.release.tag_helper"}}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<span class="help tag-name-helper tw-pb-0">{{ctx.Locale.Tr "repo.release.tag_helper"}}</span>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
<div class="eleven wide tw-pt-0">
|
||||
<div class="field {{if .Err_Title}}error{{end}}">
|
||||
<input name="title" aria-label="{{ctx.Locale.Tr "repo.release.title"}}" placeholder="{{ctx.Locale.Tr "repo.release.title"}}" value="{{.title}}" autofocus maxlength="255">
|
||||
|
||||
<div class="field {{if .Err_Title}}error{{end}}">
|
||||
<label><b>{{ctx.Locale.Tr "repo.release.title"}}</b></label>
|
||||
<input name="title" aria-label="{{ctx.Locale.Tr "repo.release.title"}}" placeholder="{{ctx.Locale.Tr "repo.release.title"}}" value="{{.title}}" autofocus maxlength="255">
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label><b>{{ctx.Locale.Tr "repo.release.notes"}}</b></label>
|
||||
<button type="button" class="ui small compact button generate-release-notes"
|
||||
data-generate-url="{{.RepoLink}}/releases/generate-notes"
|
||||
data-tooltip-content="{{ctx.Locale.Tr "repo.release.generate_notes_desc"}}"
|
||||
data-text-missing-tag="{{ctx.Locale.Tr "repo.release.generate_notes_missing_tag"}}"
|
||||
>
|
||||
{{ctx.Locale.Tr "repo.release.generate_notes"}}
|
||||
</button>
|
||||
</div>
|
||||
<div class="field">
|
||||
{{template "shared/combomarkdowneditor" (dict
|
||||
"MarkdownPreviewInRepo" $.Repository
|
||||
"MarkdownPreviewMode" "comment"
|
||||
"TextareaName" "content"
|
||||
"TextareaContent" .content
|
||||
"TextareaPlaceholder" (ctx.Locale.Tr "repo.release.message")
|
||||
"DropzoneParentContainer" "form"
|
||||
)}}
|
||||
</div>
|
||||
|
||||
{{range .attachments}}
|
||||
<div class="field flex-text-block" id="attachment-{{.ID}}">
|
||||
<div class="flex-text-block tw-flex-1">
|
||||
<input name="attachment-edit-{{.UUID}}" class="tw-max-w-[48em]" required value="{{.Name}}">
|
||||
<input name="attachment-del-{{.UUID}}" type="hidden" value="false">
|
||||
<span class="text grey tw-flex-shrink-0">{{.Size | FileSize}}</span>
|
||||
<span data-tooltip-content="{{ctx.Locale.Tr "repo.release.download_count" (ctx.Locale.PrettyNumber .DownloadCount)}}">
|
||||
{{svg "octicon-info"}}
|
||||
</span>
|
||||
</div>
|
||||
<a class="ui mini compact red button" data-global-click="onReleaseEditAttachmentDelete" data-id="{{.ID}}" data-uuid="{{.UUID}}">
|
||||
{{ctx.Locale.Tr "remove"}}
|
||||
</a>
|
||||
</div>
|
||||
<div class="field flex-text-block">
|
||||
<label class="flex-text-inline"><b>{{ctx.Locale.Tr "repo.release.previous_tag"}}</b></label>
|
||||
<select name="previous_tag" class="ui selection dropdown tw-w-[16rem] max-lg:tw-w-full">
|
||||
<option value="">{{ctx.Locale.Tr "repo.release.previous_tag_auto"}}</option>
|
||||
{{range .Tags}}
|
||||
<option value="{{.}}">{{.}}</option>
|
||||
{{end}}
|
||||
</select>
|
||||
<button type="button"
|
||||
class="ui button"
|
||||
id="generate-release-notes"
|
||||
data-generate-url="{{.RepoLink}}/releases/generate-notes"
|
||||
data-missing-tag-message="{{ctx.Locale.Tr "repo.release.generate_notes_missing_tag"}}"
|
||||
data-tooltip-content="{{ctx.Locale.Tr "repo.release.generate_notes_desc"}}">
|
||||
{{ctx.Locale.Tr "repo.release.generate_notes"}}
|
||||
</button>
|
||||
</div>
|
||||
<span class="help tw-mt-2 tw-mb-4 tw-block">{{ctx.Locale.Tr "repo.release.generate_notes_desc"}}</span>
|
||||
{{end}}
|
||||
{{if .IsAttachmentEnabled}}
|
||||
<div class="field">
|
||||
{{template "shared/combomarkdowneditor" (dict
|
||||
"MarkdownPreviewInRepo" $.Repository
|
||||
"MarkdownPreviewMode" "comment"
|
||||
"TextareaName" "content"
|
||||
"TextareaContent" .content
|
||||
"TextareaPlaceholder" (ctx.Locale.Tr "repo.release.message")
|
||||
"DropzoneParentContainer" "form"
|
||||
)}}
|
||||
{{template "repo/upload" .}}
|
||||
</div>
|
||||
{{range .attachments}}
|
||||
<div class="field flex-text-block" id="attachment-{{.ID}}">
|
||||
<div class="flex-text-inline tw-flex-1">
|
||||
<input name="attachment-edit-{{.UUID}}" class="attachment_edit" required value="{{.Name}}">
|
||||
<input name="attachment-del-{{.UUID}}" type="hidden" value="false">
|
||||
<span class="ui text grey tw-whitespace-nowrap">{{.Size | FileSize}}</span>
|
||||
<span data-tooltip-content="{{ctx.Locale.Tr "repo.release.download_count" (ctx.Locale.PrettyNumber .DownloadCount)}}">
|
||||
{{svg "octicon-info"}}
|
||||
</span>
|
||||
</div>
|
||||
<a class="ui mini compact red button remove-rel-attach" data-id="{{.ID}}" data-uuid="{{.UUID}}">
|
||||
{{ctx.Locale.Tr "remove"}}
|
||||
</a>
|
||||
{{end}}
|
||||
|
||||
{{if not .PageIsEditRelease}}
|
||||
<div class="field">
|
||||
<div class="ui checkbox">
|
||||
<input type="checkbox" name="add_tag_msg">
|
||||
<label><strong>{{ctx.Locale.Tr "repo.release.add_tag_msg"}}</strong></label>
|
||||
</div>
|
||||
{{end}}
|
||||
{{if .IsAttachmentEnabled}}
|
||||
<div class="field">
|
||||
{{template "repo/upload" .}}
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
{{else}}
|
||||
<input type="hidden" name="add_tag_msg" value="false">
|
||||
{{end}}
|
||||
|
||||
<div class="field">
|
||||
<div class="ui checkbox">
|
||||
<input type="checkbox" name="prerelease" {{if .prerelease}}checked{{end}}>
|
||||
<label><strong>{{ctx.Locale.Tr "repo.release.prerelease_desc"}}</strong></label>
|
||||
</div>
|
||||
<div class="help tw-block tw-ml-[21px]">{{ctx.Locale.Tr "repo.release.prerelease_helper"}}</div>
|
||||
</div>
|
||||
<div class="divider"></div>
|
||||
<div class="ui">
|
||||
<div>
|
||||
{{if not .PageIsEditRelease}}
|
||||
<div class="tag-message field">
|
||||
<div class="ui checkbox">
|
||||
<input type="checkbox" name="add_tag_msg">
|
||||
<label><strong>{{ctx.Locale.Tr "repo.release.add_tag_msg"}}</strong></label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex-text-block tw-justify-end">
|
||||
{{if .PageIsEditRelease}}
|
||||
<a class="ui small button" href="{{.RepoLink}}/releases">
|
||||
{{ctx.Locale.Tr "repo.release.cancel"}}
|
||||
</a>
|
||||
<a class="ui small red button link-action"
|
||||
data-modal-confirm-header="{{ctx.Locale.Tr "repo.release.deletion"}}" data-modal-confirm-content="{{ctx.Locale.Tr "repo.release.deletion_desc"}}"
|
||||
data-url="{{$.RepoLink}}/releases/delete?id={{.ID}}">
|
||||
{{ctx.Locale.Tr "repo.release.delete_release"}}
|
||||
</a>
|
||||
{{if .IsDraft}}
|
||||
<button class="ui small button" type="submit" name="draft" value="1">{{ctx.Locale.Tr "repo.release.save_draft"}}</button>
|
||||
<button class="ui small primary button">{{ctx.Locale.Tr "repo.release.publish"}}</button>
|
||||
{{else}}
|
||||
<input type="hidden" name="add_tag_msg" value="false">
|
||||
<button class="ui small primary button">{{ctx.Locale.Tr "repo.release.edit_release"}}</button>
|
||||
{{end}}
|
||||
<div class="prerelease field">
|
||||
<div class="ui checkbox">
|
||||
<input type="checkbox" name="prerelease" {{if .prerelease}}checked{{end}}>
|
||||
<label><strong>{{ctx.Locale.Tr "repo.release.prerelease_desc"}}</strong></label>
|
||||
</div>
|
||||
</div>
|
||||
<span class="help">{{ctx.Locale.Tr "repo.release.prerelease_helper"}}</span>
|
||||
<div class="divider tw-mt-0"></div>
|
||||
<div class="flex-text-block tw-justify-end">
|
||||
{{if .PageIsEditRelease}}
|
||||
<a class="ui small button" href="{{.RepoLink}}/releases">
|
||||
{{ctx.Locale.Tr "repo.release.cancel"}}
|
||||
</a>
|
||||
<a class="ui small red button link-action" data-modal-confirm="#repo-release-delete-modal" data-url="{{$.RepoLink}}/releases/delete?id={{.ID}}">
|
||||
{{ctx.Locale.Tr "repo.release.delete_release"}}
|
||||
</a>
|
||||
{{if .IsDraft}}
|
||||
<button class="ui small button" type="submit" name="draft" value="1">{{ctx.Locale.Tr "repo.release.save_draft"}}</button>
|
||||
<button class="ui small primary button">{{ctx.Locale.Tr "repo.release.publish"}}</button>
|
||||
{{else}}
|
||||
<button class="ui small primary button">{{ctx.Locale.Tr "repo.release.edit_release"}}</button>
|
||||
{{end}}
|
||||
{{else}}
|
||||
{{if .ShowCreateTagOnlyButton}}
|
||||
<button class="ui small button" name="tag_only" value="1">{{ctx.Locale.Tr "repo.release.add_tag"}}</button>
|
||||
{{end}}
|
||||
<button class="ui small button" name="draft" value="1">{{ctx.Locale.Tr "repo.release.save_draft"}}</button>
|
||||
<button class="ui small primary button">{{ctx.Locale.Tr "repo.release.publish"}}</button>
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
{{else}}
|
||||
{{if .ShowCreateTagOnlyButton}}
|
||||
<button class="ui small button" name="tag_only" value="1">{{ctx.Locale.Tr "repo.release.add_tag"}}</button>
|
||||
{{end}}
|
||||
<button class="ui small button" name="draft" value="1">{{ctx.Locale.Tr "repo.release.save_draft"}}</button>
|
||||
<button class="ui small primary button">{{ctx.Locale.Tr "repo.release.publish"}}</button>
|
||||
{{end}}
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{if .PageIsEditRelease}}
|
||||
<div class="ui small modal" id="repo-release-delete-modal">
|
||||
<div class="header">{{svg "octicon-trash"}} {{ctx.Locale.Tr "repo.release.deletion"}}</div>
|
||||
<div class="content"><p>{{ctx.Locale.Tr "repo.release.deletion_desc"}}</p></div>
|
||||
{{template "base/modal_actions_confirm" .}}
|
||||
<div id="generate-release-notes-modal" class="ui mini modal">
|
||||
<div class="content ui form">
|
||||
<p>{{ctx.Locale.Tr "repo.release.generate_notes_desc"}}</p>
|
||||
<div class="field">
|
||||
<label>{{ctx.Locale.Tr "repo.release.previous_tag"}}</label>
|
||||
<select name="previous_tag" class="ui selection dropdown">
|
||||
<option value="">{{ctx.Locale.Tr "repo.release.previous_tag_auto"}}</option>
|
||||
{{/* FIXME: use existing "data-existing-tags" to fill the items to avoid bloating the page twice by plenty of tags */}}
|
||||
{{- range .Tags -}}
|
||||
<option value="{{.}}">{{.}}</option>
|
||||
{{- end -}}
|
||||
</select>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button class="ui primary ok button">{{ctx.Locale.Tr "repo.release.generate_notes"}}</button>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
|
||||
{{template "base/footer" .}}
|
||||
|
||||
@ -412,12 +412,6 @@ a.label,
|
||||
margin-right: .78rem; /* use the same margin as for <img> */
|
||||
}
|
||||
|
||||
.ui.selection.dropdown {
|
||||
/* Most elements (buttons, inputs, etc.) have 38px default height, so also make dropdown match. Fomantic UI default style makes it about 40px height */
|
||||
min-height: 38px;
|
||||
padding: 9px 45px 9px 15px;
|
||||
}
|
||||
|
||||
.ui.selection.dropdown .menu > .item {
|
||||
border-color: var(--color-secondary);
|
||||
}
|
||||
|
||||
@ -95,46 +95,3 @@
|
||||
font-size: 18px;
|
||||
font-weight: var(--font-weight-normal);
|
||||
}
|
||||
|
||||
.repository.new.release .target {
|
||||
min-width: 500px;
|
||||
}
|
||||
|
||||
.repository.new.release .target #tag-name {
|
||||
margin-top: -4px;
|
||||
}
|
||||
|
||||
.repository.new.release .target .at {
|
||||
margin-left: -5px;
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
.repository.new.release .target .selection.dropdown {
|
||||
padding-top: 10px;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
|
||||
.repository.new.release .prerelease.field {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
@media (max-width: 438px) {
|
||||
.repository.new.release .field button,
|
||||
.repository.new.release .field input {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 767.98px) {
|
||||
.repository.new.release .field button {
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
}
|
||||
|
||||
.repository.new.release .field .attachment_edit {
|
||||
max-width: 48em;
|
||||
}
|
||||
|
||||
.repository.new.release .markup {
|
||||
min-height: 240px;
|
||||
}
|
||||
|
||||
@ -410,7 +410,7 @@ export class ComboMarkdownEditor {
|
||||
}
|
||||
}
|
||||
|
||||
export function getComboMarkdownEditor(el: any) {
|
||||
export function getComboMarkdownEditor(el: any): ComboMarkdownEditor | null {
|
||||
if (!el) return null;
|
||||
if (el.length) el = el[0];
|
||||
return el._giteaComboMarkdownEditor;
|
||||
|
||||
@ -84,7 +84,7 @@ async function tryOnEditContent(e: Event) {
|
||||
showElem(editContentZone);
|
||||
hideElem(renderContent);
|
||||
|
||||
comboMarkdownEditor = getComboMarkdownEditor(editContentZone.querySelector('.combo-markdown-editor'));
|
||||
comboMarkdownEditor = getComboMarkdownEditor(editContentZone.querySelector('.combo-markdown-editor'))!;
|
||||
if (!comboMarkdownEditor) {
|
||||
editContentZone.innerHTML = document.querySelector('#issue-comment-editor-template')!.innerHTML;
|
||||
const form = editContentZone.querySelector('form')!;
|
||||
@ -139,7 +139,7 @@ async function tryOnQuoteReply(e: Event) {
|
||||
editor = await handleReply(replyBtn);
|
||||
} else {
|
||||
// for normal issue/comment page
|
||||
editor = getComboMarkdownEditor(document.querySelector('#comment-form .combo-markdown-editor'));
|
||||
editor = getComboMarkdownEditor(document.querySelector('#comment-form .combo-markdown-editor'))!;
|
||||
}
|
||||
|
||||
if (editor.value()) {
|
||||
|
||||
@ -1,48 +1,41 @@
|
||||
import {POST} from '../modules/fetch.ts';
|
||||
import {showErrorToast} from '../modules/toast.ts';
|
||||
import {hideToastsAll, showErrorToast} from '../modules/toast.ts';
|
||||
import {getComboMarkdownEditor} from './comp/ComboMarkdownEditor.ts';
|
||||
import {hideElem, showElem} from '../utils/dom.ts';
|
||||
import {fomanticQuery} from '../modules/fomantic/base.ts';
|
||||
import {registerGlobalEventFunc, registerGlobalInitFunc} from '../modules/observer.ts';
|
||||
|
||||
export function initRepoRelease() {
|
||||
document.addEventListener('click', (e: MouseEvent) => {
|
||||
const target = e.target;
|
||||
if (!(target instanceof HTMLElement) || !target.matches('.remove-rel-attach')) return;
|
||||
const uuid = target.getAttribute('data-uuid')!;
|
||||
const id = target.getAttribute('data-id')!;
|
||||
export function initRepoReleaseNew() {
|
||||
registerGlobalEventFunc('click', 'onReleaseEditAttachmentDelete', (el) => {
|
||||
const uuid = el.getAttribute('data-uuid')!;
|
||||
const id = el.getAttribute('data-id')!;
|
||||
document.querySelector<HTMLInputElement>(`input[name='attachment-del-${uuid}']`)!.value = 'true';
|
||||
hideElem(`#attachment-${id}`);
|
||||
});
|
||||
registerGlobalInitFunc('initReleaseEditForm', (elForm: HTMLFormElement) => {
|
||||
initTagNameEditor(elForm);
|
||||
initGenerateReleaseNotes(elForm);
|
||||
});
|
||||
}
|
||||
|
||||
export function initRepoReleaseNew() {
|
||||
if (!document.querySelector('.repository.new.release')) return; // FIXME: edit release page also uses this class
|
||||
function initTagNameEditor(elForm: HTMLFormElement) {
|
||||
const tagNameInput = elForm.querySelector<HTMLInputElement>('input[type=text][name=tag_name]');
|
||||
if (!tagNameInput) return; // only init if tag name input exists (the tag name is editable)
|
||||
|
||||
initTagNameEditor();
|
||||
initGenerateReleaseNotes();
|
||||
}
|
||||
const existingTags = JSON.parse(elForm.getAttribute('data-existing-tags')!);
|
||||
const defaultTagHelperText = elForm.getAttribute('data-tag-helper');
|
||||
const newTagHelperText = elForm.getAttribute('data-tag-helper-new');
|
||||
const existingTagHelperText = elForm.getAttribute('data-tag-helper-existing');
|
||||
|
||||
function initTagNameEditor() {
|
||||
const el = document.querySelector('#tag-name-editor');
|
||||
if (!el) return;
|
||||
|
||||
const existingTags = JSON.parse(el.getAttribute('data-existing-tags')!);
|
||||
if (!Array.isArray(existingTags)) return;
|
||||
|
||||
const defaultTagHelperText = el.getAttribute('data-tag-helper');
|
||||
const newTagHelperText = el.getAttribute('data-tag-helper-new');
|
||||
const existingTagHelperText = el.getAttribute('data-tag-helper-existing');
|
||||
|
||||
const tagNameInput = document.querySelector<HTMLInputElement>('#tag-name')!;
|
||||
const hideTargetInput = function(tagNameInput: HTMLInputElement) {
|
||||
const value = tagNameInput.value;
|
||||
const tagHelper = document.querySelector('#tag-helper')!;
|
||||
const tagHelper = elForm.querySelector('.tag-name-helper')!;
|
||||
if (existingTags.includes(value)) {
|
||||
// If the tag already exists, hide the target branch selector.
|
||||
hideElem('#tag-target-selector');
|
||||
hideElem(elForm.querySelectorAll('.tag-target-selector'));
|
||||
tagHelper.textContent = existingTagHelperText;
|
||||
} else {
|
||||
showElem('#tag-target-selector');
|
||||
showElem(elForm.querySelectorAll('.tag-target-selector'));
|
||||
tagHelper.textContent = value ? newTagHelperText : defaultTagHelperText;
|
||||
}
|
||||
};
|
||||
@ -52,31 +45,26 @@ function initTagNameEditor() {
|
||||
});
|
||||
}
|
||||
|
||||
function initGenerateReleaseNotes() {
|
||||
const button = document.querySelector<HTMLButtonElement>('#generate-release-notes');
|
||||
if (!button) return;
|
||||
function initGenerateReleaseNotes(elForm: HTMLFormElement) {
|
||||
const buttonShowModal = elForm.querySelector<HTMLButtonElement>('.button.generate-release-notes')!;
|
||||
const tagNameInput = elForm.querySelector<HTMLInputElement>('input[name=tag_name]')!;
|
||||
const targetInput = elForm.querySelector<HTMLInputElement>('input[name=tag_target]')!;
|
||||
|
||||
const tagNameInput = document.querySelector<HTMLInputElement>('#tag-name')!;
|
||||
const targetInput = document.querySelector<HTMLInputElement>("input[name='tag_target']")!;
|
||||
const previousTagSelect = document.querySelector<HTMLSelectElement>('[name=previous_tag]')!;
|
||||
const missingTagMessage = button.getAttribute('data-missing-tag-message')!;
|
||||
const generateUrl = button.getAttribute('data-generate-url')!;
|
||||
const textMissingTag = buttonShowModal.getAttribute('data-text-missing-tag')!;
|
||||
const generateUrl = buttonShowModal.getAttribute('data-generate-url')!;
|
||||
|
||||
button.addEventListener('click', async () => {
|
||||
const tagName = tagNameInput.value.trim();
|
||||
const elModal = document.querySelector('#generate-release-notes-modal')!;
|
||||
|
||||
if (!tagName) {
|
||||
showErrorToast(missingTagMessage);
|
||||
tagNameInput.focus();
|
||||
return;
|
||||
}
|
||||
const doSubmit = async (tagName: string) => {
|
||||
const elPreviousTag = elModal.querySelector<HTMLSelectElement>('[name=previous_tag]')!;
|
||||
const comboEditor = getComboMarkdownEditor(elForm.querySelector<HTMLElement>('.combo-markdown-editor'))!;
|
||||
|
||||
const form = new URLSearchParams();
|
||||
form.set('tag_name', tagName);
|
||||
form.set('tag_target', targetInput.value);
|
||||
form.set('previous_tag', previousTagSelect.value);
|
||||
form.set('previous_tag', elPreviousTag.value);
|
||||
|
||||
button.classList.add('loading', 'disabled');
|
||||
elModal.classList.add('loading', 'disabled');
|
||||
try {
|
||||
const resp = await POST(generateUrl, {data: form});
|
||||
const data = await resp.json();
|
||||
@ -84,19 +72,36 @@ function initGenerateReleaseNotes() {
|
||||
showErrorToast(data.errorMessage || resp.statusText);
|
||||
return;
|
||||
}
|
||||
|
||||
fomanticQuery(previousTagSelect).dropdown('set selected', data.previous_tag);
|
||||
applyGeneratedReleaseNotes(data.content);
|
||||
const oldValue = comboEditor.value().trim();
|
||||
if (oldValue) {
|
||||
// Don't overwrite existing content. Maybe in the future we can let users decide: overwrite or append or copy-to-clipboard
|
||||
// GitHub just disables the button if the content is not empty
|
||||
comboEditor.value(`${oldValue}\n\n${data.content}`);
|
||||
} else {
|
||||
comboEditor.value(data.content);
|
||||
}
|
||||
} finally {
|
||||
button.classList.remove('loading', 'disabled');
|
||||
elModal.classList.remove('loading', 'disabled');
|
||||
fomanticQuery(elModal).modal('hide');
|
||||
comboEditor.focus();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function applyGeneratedReleaseNotes(content: string) {
|
||||
const editorContainer = document.querySelector<HTMLElement>('.combo-markdown-editor');
|
||||
if (!editorContainer) return;
|
||||
const doShowModal = () => {
|
||||
hideToastsAll();
|
||||
const tagName = tagNameInput.value.trim();
|
||||
if (!tagName) {
|
||||
showErrorToast(textMissingTag, {duration: 3000});
|
||||
tagNameInput.focus();
|
||||
return;
|
||||
}
|
||||
fomanticQuery(elModal).modal({
|
||||
onApprove: () => {
|
||||
doSubmit(tagName); // don't await, need to return false to keep the modal
|
||||
return false;
|
||||
},
|
||||
}).modal('show');
|
||||
};
|
||||
|
||||
const comboEditor = getComboMarkdownEditor(editorContainer);
|
||||
comboEditor.value(content);
|
||||
buttonShowModal.addEventListener('click', doShowModal);
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ import {initRepoMigrationStatusChecker} from './features/repo-migrate.ts';
|
||||
import {initRepoDiffView} from './features/repo-diff.ts';
|
||||
import {initOrgTeam} from './features/org-team.ts';
|
||||
import {initUserAuthWebAuthn, initUserAuthWebAuthnRegister} from './features/user-auth-webauthn.ts';
|
||||
import {initRepoRelease, initRepoReleaseNew} from './features/repo-release.ts';
|
||||
import {initRepoReleaseNew} from './features/repo-release.ts';
|
||||
import {initRepoEditor} from './features/repo-editor.ts';
|
||||
import {initCompSearchUserBox} from './features/comp/SearchUserBox.ts';
|
||||
import {initInstall} from './features/install.ts';
|
||||
@ -133,7 +133,6 @@ const initPerformanceTracer = callInitFunctions([
|
||||
initRepoProject,
|
||||
initRepoPullRequestAllowMaintainerEdit,
|
||||
initRepoPullRequestReview,
|
||||
initRepoRelease,
|
||||
initRepoReleaseNew,
|
||||
initRepoTopicBar,
|
||||
initRepoViewFileTree,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user