aboutsummaryrefslogtreecommitdiff
path: root/web_src/js/features/repo-issue.js
blob: 41c9dd118f2ff0c100a5e94c51dd6b012bfe8d0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
import $ from 'jquery';
import {htmlEscape} from 'escape-goat';
import {attachTribute} from './tribute.js';
import {createCommentEasyMDE, getAttachedEasyMDE} from './comp/EasyMDE.js';
import {initEasyMDEImagePaste} from './comp/ImagePaste.js';
import {initCompMarkupContentPreviewTab} from './comp/MarkupContentPreview.js';
import {initTooltip, showTemporaryTooltip} from '../modules/tippy.js';
import {hideElem, showElem, toggleElem} from '../utils/dom.js';

const {appSubUrl, csrfToken} = window.config;

export function initRepoIssueTimeTracking() {
  $(document).on('click', '.issue-add-time', () => {
    $('.issue-start-time-modal').modal({
      duration: 200,
      onApprove() {
        $('#add_time_manual_form').trigger('submit');
      },
    }).modal('show');
    $('.issue-start-time-modal input').on('keydown', (e) => {
      if ((e.keyCode || e.key) === 13) {
        $('#add_time_manual_form').trigger('submit');
      }
    });
  });
  $(document).on('click', '.issue-start-time, .issue-stop-time', () => {
    $('#toggle_stopwatch_form').trigger('submit');
  });
  $(document).on('click', '.issue-cancel-time', () => {
    $('#cancel_stopwatch_form').trigger('submit');
  });
  $(document).on('click', 'button.issue-delete-time', function () {
    const sel = `.issue-delete-time-modal[data-id="${$(this).data('id')}"]`;
    $(sel).modal({
      duration: 200,
      onApprove() {
        $(`${sel} form`).trigger('submit');
      },
    }).modal('show');
  });
}

function updateDeadline(deadlineString) {
  hideElem($('#deadline-err-invalid-date'));
  $('#deadline-loader').addClass('loading');

  let realDeadline = null;
  if (deadlineString !== '') {
    const newDate = Date.parse(deadlineString);

    if (Number.isNaN(newDate)) {
      $('#deadline-loader').removeClass('loading');
      showElem($('#deadline-err-invalid-date'));
      return false;
    }
    realDeadline = new Date(newDate);
  }

  $.ajax(`${$('#update-issue-deadline-form').attr('action')}`, {
    data: JSON.stringify({
      due_date: realDeadline,
    }),
    headers: {
      'X-Csrf-Token': csrfToken,
    },
    contentType: 'application/json',
    type: 'POST',
    success() {
      window.location.reload();
    },
    error() {
      $('#deadline-loader').removeClass('loading');
      showElem($('#deadline-err-invalid-date'));
    },
  });
}

export function initRepoIssueDue() {
  $(document).on('click', '.issue-due-edit', () => {
    $('#deadlineForm').fadeToggle(150);
  });
  $(document).on('click', '.issue-due-remove', () => {
    updateDeadline('');
  });
  $(document).on('submit', '.issue-due-form', () => {
    updateDeadline($('#deadlineDate').val());
    return false;
  });
}

export function initRepoIssueList() {
  const repolink = $('#repolink').val();
  const repoId = $('#repoId').val();
  const crossRepoSearch = $('#crossRepoSearch').val();
  const tp = $('#type').val();
  let issueSearchUrl = `${appSubUrl}/${repolink}/issues/search?q={query}&type=${tp}`;
  if (crossRepoSearch === 'true') {
    issueSearchUrl = `${appSubUrl}/issues/search?q={query}&priority_repo_id=${repoId}&type=${tp}`;
  }
  $('#new-dependency-drop-list')
    .dropdown({
      apiSettings: {
        url: issueSearchUrl,
        onResponse(response) {
          const filteredResponse = {success: true, results: []};
          const currIssueId = $('#new-dependency-drop-list').data('issue-id');
          // Parse the response from the api to work with our dropdown
          $.each(response, (_i, issue) => {
            // Don't list current issue in the dependency list.
            if (issue.id === currIssueId) {
              return;
            }
            filteredResponse.results.push({
              name: `#${issue.number} ${htmlEscape(issue.title)
              }<div class="text small dont-break-out">${htmlEscape(issue.repository.full_name)}</div>`,
              value: issue.id,
            });
          });
          return filteredResponse;
        },
        cache: false,
      },

      fullTextSearch: true,
    });

  function excludeLabel(item) {
    const href = $(item).attr('href');
    const id = $(item).data('label-id');

    const regStr = `labels=((?:-?[0-9]+%2c)*)(${id})((?:%2c-?[0-9]+)*)&`;
    const newStr = 'labels=$1-$2$3&';

    window.location = href.replace(new RegExp(regStr), newStr);
  }

  $('.menu a.label-filter-item').each(function () {
    $(this).on('click', function (e) {
      if (e.altKey) {
        e.preventDefault();
        excludeLabel(this);
      }
    });
  });

  $('.menu .ui.dropdown.label-filter').on('keydown', (e) => {
    if (e.altKey && e.keyCode === 13) {
      const selectedItems = $('.menu .ui.dropdown.label-filter .menu .item.selected');
      if (selectedItems.length > 0) {
        excludeLabel($(selectedItems[0]));
      }
    }
  });
}

export function initRepoIssueCommentDelete() {
  // Delete comment
  $(document).on('click', '.delete-comment', function () {
    const $this = $(this);
    if (window.confirm($this.data('locale'))) {
      $.post($this.data('url'), {
        _csrf: csrfToken,
      }).done(() => {
        const $conversationHolder = $this.closest('.conversation-holder');

        // Check if this was a pending comment.
        if ($conversationHolder.find('.pending-label').length) {
          const $counter = $('#review-box .review-comments-counter');
          let num = parseInt($counter.attr('data-pending-comment-number')) - 1 || 0;
          num = Math.max(num, 0);
          $counter.attr('data-pending-comment-number', num);
          $counter.text(num);
        }

        $(`#${$this.data('comment-id')}`).remove();
        if ($conversationHolder.length && !$conversationHolder.find('.comment').length) {
          const path = $conversationHolder.data('path');
          const side = $conversationHolder.data('side');
          const idx = $conversationHolder.data('idx');
          const lineType = $conversationHolder.closest('tr').data('line-type');
          if (lineType === 'same') {
            $(`[data-path="${path}"] a.add-code-comment[data-idx="${idx}"]`).removeClass('invisible');
          } else {
            $(`[data-path="${path}"] a.add-code-comment[data-side="${side}"][data-idx="${idx}"]`).removeClass('invisible');
          }
          $conversationHolder.remove();
        }
      });
    }
    return false;
  });
}

export function initRepoIssueDependencyDelete() {
  // Delete Issue dependency
  $(document).on('click', '.delete-dependency-button', (e) => {
    const id = e.currentTarget.getAttribute('data-id');
    const type = e.currentTarget.getAttribute('data-type');

    $('.remove-dependency').modal({
      closable: false,
      duration: 200,
      onApprove: () => {
        $('#removeDependencyID').val(id);
        $('#dependencyType').val(type);
        $('#removeDependencyForm').trigger('submit');
      },
    }).modal('show');
  });
}

export function initRepoIssueCodeCommentCancel() {
  // Cancel inline code comment
  $(document).on('click', '.cancel-code-comment', (e) => {
    const form = $(e.currentTarget).closest('form');
    if (form.length > 0 && form.hasClass('comment-form')) {
      form.addClass('gt-hidden');
      showElem(form.closest('.comment-code-cloud').find('button.comment-form-reply'));
    } else {
      form.closest('.comment-code-cloud').remove();
    }
  });
}

export function initRepoIssueStatusButton() {
  // Change status
  const $statusButton = $('#status-button');
  $('#comment-form textarea').on('keyup', function () {
    const easyMDE = getAttachedEasyMDE(this);
    const value = easyMDE?.value() || $(this).val();
    $statusButton.text($statusButton.data(value.length === 0 ? 'status' : 'status-and-comment'));
  });
  $statusButton.on('click', () => {
    $('#status').val($statusButton.data('status-val'));
    $('#comment-form').trigger('submit');
  });
}

export function initRepoPullRequestUpdate() {
  // Pull Request update button
  const $pullUpdateButton = $('.update-button > button');
  $pullUpdateButton.on('click', function (e) {
    e.preventDefault();
    const $this = $(this);
    const redirect = $this.data('redirect');
    $this.addClass('loading');
    $.post($this.data('do'), {
      _csrf: csrfToken
    }).done((data) => {
      if (data.redirect) {
        window.location.href = data.redirect;
      } else if (redirect) {
        window.location.href = redirect;
      } else {
        window.location.reload();
      }
    });
  });

  $('.update-button > .dropdown').dropdown({
    onChange(_text, _value, $choice) {
      const $url = $choice.data('do');
      if ($url) {
        $pullUpdateButton.find('.button-text').text($choice.text());
        $pullUpdateButton.data('do', $url);
      }
    }
  });
}

export function initRepoPullRequestMergeInstruction() {
  $('.show-instruction').on('click', () => {
    toggleElem($('.instruct-content'));
  });
}

export function initRepoPullRequestAllowMaintainerEdit() {
  const $checkbox = $('#allow-edits-from-maintainers');
  if (!$checkbox.length) return;

  const promptTip = $checkbox.attr('data-prompt-tip');
  const promptError = $checkbox.attr('data-prompt-error');

  initTooltip($checkbox[0], {content: promptTip});
  $checkbox.checkbox({
    'onChange': () => {
      const checked = $checkbox.checkbox('is checked');
      let url = $checkbox.attr('data-url');
      url += '/set_allow_maintainer_edit';
      $checkbox.checkbox('set disabled');
      $.ajax({url, type: 'POST',
        data: {_csrf: csrfToken, allow_maintainer_edit: checked},
        error: () => {
          showTemporaryTooltip($checkbox[0], promptError);
        },
        complete: () => {
          $checkbox.checkbox('set enabled');
        },
      });
    },
  });
}

export function initRepoIssueReferenceRepositorySearch() {
  $('.issue_reference_repository_search')
    .dropdown({
      apiSettings: {
        url: `${appSubUrl}/repo/search?q={query}&limit=20`,
        onResponse(response) {
          const filteredResponse = {success: true, results: []};
          $.each(response.data, (_r, repo) => {
            filteredResponse.results.push({
              name: htmlEscape(repo.full_name),
              value: repo.full_name
            });
          });
          return filteredResponse;
        },
        cache: false,
      },
      onChange(_value, _text, $choice) {
        const $form = $choice.closest('form');
        $form.attr('action', `${appSubUrl}/${_text}/issues/new`);
      },
      fullTextSearch: true
    });
}


export function initRepoIssueWipTitle() {
  $('.title_wip_desc > a').on('click', (e) => {
    e.preventDefault();

    const $issueTitle = $('#issue_title');
    $issueTitle.focus();
    const value = $issueTitle.val().trim().toUpperCase();

    const wipPrefixes = $('.title_wip_desc').data('wip-prefixes');
    for (const prefix of wipPrefixes) {
      if (value.startsWith(prefix.toUpperCase())) {
        return;
      }
    }

    $issueTitle.val(`${wipPrefixes[0]} ${$issueTitle.val()}`);
  });
}

export async function updateIssuesMeta(url, action, issueIds, elementId) {
  return $.ajax({
    type: 'POST',
    url,
    data: {
      _csrf: csrfToken,
      action,
      issue_ids: issueIds,
      id: elementId,
    },
  });
}

export function initRepoIssueComments() {
  if ($('.repository.view.issue .timeline').length === 0) return;

  $('.re-request-review').on('click', function (e) {
    e.preventDefault();
    const url = $(this).data('update-url');
    const issueId = $(this).data('issue-id');
    const id = $(this).data('id');
    const isChecked = $(this).hasClass('checked');

    updateIssuesMeta(
      url,
      isChecked ? 'detach' : 'attach',
      issueId,
      id,
    ).then(() => window.location.reload());
  });

  $('.dismiss-review-btn').on('click', function (e) {
    e.preventDefault();
    const $this = $(this);
    const $dismissReviewModal = $this.next();
    $dismissReviewModal.modal('show');
  });

  $(document).on('click', (event) => {
    const urlTarget = $(':target');
    if (urlTarget.length === 0) return;

    const urlTargetId = urlTarget.attr('id');
    if (!urlTargetId) return;
    if (!/^(issue|pull)(comment)?-\d+$/.test(urlTargetId)) return;

    const $target = $(event.target);

    if ($target.closest(`#${urlTargetId}`).length === 0) {
      const scrollPosition = $(window).scrollTop();
      window.location.hash = '';
      $(window).scrollTop(scrollPosition);
      window.history.pushState(null, null, ' ');
    }
  });
}


function assignMenuAttributes(menu) {
  const id = Math.floor(Math.random() * Math.floor(1000000));
  menu.attr('data-write', menu.attr('data-write') + id);
  menu.attr('data-preview', menu.attr('data-preview') + id);
  menu.find('.item').each(function () {
    const tab = $(this).attr('data-tab') + id;
    $(this).attr('data-tab', tab);
  });
  menu.parent().find("*[data-tab='write']").attr('data-tab', `write${id}`);
  menu.parent().find("*[data-tab='preview']").attr('data-tab', `preview${id}`);
  initCompMarkupContentPreviewTab(menu.parent('.form'));
  return id;
}

export async function handleReply($el) {
  hideElem($el);
  const form = $el.closest('.comment-code-cloud').find('.comment-form');
  form.removeClass('gt-hidden');
  const $textarea = form.find('textarea');
  let easyMDE = getAttachedEasyMDE($textarea);
  if (!easyMDE) {
    await attachTribute($textarea.get(), {mentions: true, emoji: true});
    easyMDE = await createCommentEasyMDE($textarea);
  }
  $textarea.focus();
  easyMDE.codemirror.focus();
  assignMenuAttributes(form.find('.menu'));
  return easyMDE;
}

export function initRepoPullRequestReview() {
  if (window.location.hash && window.location.hash.startsWith('#issuecomment-')) {
    const commentDiv = $(window.location.hash);
    if (commentDiv) {
      // get the name of the parent id
      const groupID = commentDiv.closest('div[id^="code-comments-"]').attr('id');
      if (groupID && groupID.startsWith('code-comments-')) {
        const id = groupID.slice(14);
        $(`#show-outdated-${id}`).addClass('gt-hidden');
        $(`#code-comments-${id}`).removeClass('gt-hidden');
        $(`#code-preview-${id}`).removeClass('gt-hidden');
        $(`#hide-outdated-${id}`).removeClass('gt-hidden');
        commentDiv[0].scrollIntoView();
      }
    }
  }

  $(document).on('click', '.show-outdated', function (e) {
    e.preventDefault();
    const id = $(this).data('comment');
    $(this).addClass('gt-hidden');
    $(`#code-comments-${id}`).removeClass('gt-hidden');
    $(`#code-preview-${id}`).removeClass('gt-hidden');
    $(`#hide-outdated-${id}`).removeClass('gt-hidden');
  });

  $(document).on('click', '.hide-outdated', function (e) {
    e.preventDefault();
    const id = $(this).data('comment');
    $(this).addClass('gt-hidden');
    $(`#code-comments-${id}`).addClass('gt-hidden');
    $(`#code-preview-${id}`).addClass('gt-hidden');
    $(`#show-outdated-${id}`).removeClass('gt-hidden');
  });

  $(document).on('click', 'button.comment-form-reply', async function (e) {
    e.preventDefault();
    await handleReply($(this));
  });

  const $reviewBox = $('.review-box-panel');
  if ($reviewBox.length === 1) {
    (async () => {
      // the editor's height is too large in some cases, and the panel cannot be scrolled with page now because there is `.repository .diff-detail-box.sticky { position: sticky; }`
      // the temporary solution is to make the editor's height smaller (about 4 lines). GitHub also only show 4 lines for default. We can improve the UI (including Dropzone area) in future
      // EasyMDE's options can not handle minHeight & maxHeight together correctly, we have to set max-height for .CodeMirror-scroll in CSS.
      const $reviewTextarea = $reviewBox.find('textarea');
      const easyMDE = await createCommentEasyMDE($reviewTextarea, {minHeight: '80px'});
      initEasyMDEImagePaste(easyMDE, $reviewBox.find('.dropzone'));
    })();
  }

  // The following part is only for diff views
  if ($('.repository.pull.diff').length === 0) {
    return;
  }

  $('.js-btn-review').on('click', function (e) {
    e.preventDefault();
    toggleElem($(this).parent().find('.review-box-panel'));
  }).parent().find('.review-box-panel .close').on('click', function (e) {
    e.preventDefault();
    hideElem($(this).closest('.review-box-panel'));
  });

  $(document).on('click', 'a.add-code-comment', async function (e) {
    if ($(e.target).hasClass('btn-add-single')) return; // https://github.com/go-gitea/gitea/issues/4745
    e.preventDefault();

    const isSplit = $(this).closest('.code-diff').hasClass('code-diff-split');
    const side = $(this).data('side');
    const idx = $(this).data('idx');
    const path = $(this).closest('[data-path]').data('path');
    const tr = $(this).closest('tr');
    const lineType = tr.data('line-type');

    let ntr = tr.next();
    if (!ntr.hasClass('add-comment')) {
      ntr = $(`
        <tr class="add-comment" data-line-type="${lineType}">
          ${isSplit ? `
            <td class="lines-num"></td>
            <td class="lines-escape"></td>
            <td class="lines-type-marker"></td>
            <td class="add-comment-left" colspan="4"></td>
            <td class="lines-num"></td>
            <td class="lines-escape"></td>
            <td class="lines-type-marker"></td>
            <td class="add-comment-right" colspan="4"></td>
          ` : `
            <td class="lines-num"></td>
            <td class="lines-num"></td>
            <td class="lines-escape"></td>
            <td class="add-comment-left add-comment-right" colspan="5"></td>
          `}
        </tr>`);
      tr.after(ntr);
    }

    const td = ntr.find(`.add-comment-${side}`);
    let commentCloud = td.find('.comment-code-cloud');
    if (commentCloud.length === 0 && !ntr.find('button[name="pending_review"]').length) {
      const data = await $.get($(this).closest('[data-new-comment-url]').data('new-comment-url'));
      td.html(data);
      commentCloud = td.find('.comment-code-cloud');
      assignMenuAttributes(commentCloud.find('.menu'));
      td.find("input[name='line']").val(idx);
      td.find("input[name='side']").val(side === 'left' ? 'previous' : 'proposed');
      td.find("input[name='path']").val(path);
      const $textarea = commentCloud.find('textarea');
      await attachTribute($textarea.get(), {mentions: true, emoji: true});
      const easyMDE = await createCommentEasyMDE($textarea);
      $textarea.focus();
      easyMDE.codemirror.focus();
    }
  });
}

export function initRepoIssueReferenceIssue() {
  // Reference issue
  $(document).on('click', '.reference-issue', function (event) {
    const $this = $(this);
    const content = $(`#${$this.data('target')}`).text();
    const poster = $this.data('poster-username');
    const reference = $this.data('reference');
    const $modal = $($this.data('modal'));
    $modal.find('textarea[name="content"]').val(`${content}\n\n_Originally posted by @${poster} in ${reference}_`);
    $modal.modal('show');

    event.preventDefault();
  });
}

export function initRepoIssueWipToggle() {
  // Toggle WIP
  $('.toggle-wip a, .toggle-wip button').on('click', async (e) => {
    e.preventDefault();
    const toggleWip = e.currentTarget.closest('.toggle-wip');
    const title = toggleWip.getAttribute('data-title');
    const wipPrefix = toggleWip.getAttribute('data-wip-prefix');
    const updateUrl = toggleWip.getAttribute('data-update-url');
    await $.post(updateUrl, {
      _csrf: csrfToken,
      title: title?.startsWith(wipPrefix) ? title.slice(wipPrefix.length).trim() : `${wipPrefix.trim()} ${title}`,
    });
    window.location.reload();
  });
}


export function initRepoIssueTitleEdit() {
  // Edit issue title
  const $issueTitle = $('#issue-title');
  const $editInput = $('#edit-title-input input');

  const editTitleToggle = function () {
    toggleElem($issueTitle);
    toggleElem($('.not-in-edit'));
    toggleElem($('#edit-title-input'));
    toggleElem($('#pull-desc'));
    toggleElem($('#pull-desc-edit'));
    toggleElem($('.in-edit'));
    $('#issue-title-wrapper').toggleClass('edit-active');
    $editInput.focus();
    return false;
  };

  $('#edit-title').on('click', editTitleToggle);
  $('#cancel-edit-title').on('click', editTitleToggle);
  $('#save-edit-title').on('click', editTitleToggle).on('click', function () {
    const pullrequest_targetbranch_change = function (update_url) {
      const targetBranch = $('#pull-target-branch').data('branch');
      const $branchTarget = $('#branch_target');
      if (targetBranch === $branchTarget.text()) {
        window.location.reload();
        return false;
      }
      $.post(update_url, {
        _csrf: csrfToken,
        target_branch: targetBranch
      }).done((data) => {
        $branchTarget.text(data.base_branch);
      }).always(() => {
        window.location.reload();
      });
    };

    const pullrequest_target_update_url = $(this).attr('data-target-update-url');
    if ($editInput.val().length === 0 || $editInput.val() === $issueTitle.text()) {
      $editInput.val($issueTitle.text());
      pullrequest_targetbranch_change(pullrequest_target_update_url);
    } else {
      $.post($(this).attr('data-update-url'), {
        _csrf: csrfToken,
        title: $editInput.val()
      }, (data) => {
        $editInput.val(data.title);
        $issueTitle.text(data.title);
        if (pullrequest_target_update_url) {
          pullrequest_targetbranch_change(pullrequest_target_update_url); // it will reload the window
        } else {
          window.location.reload();
        }
      });
    }
    return false;
  });
}

export function initRepoIssueBranchSelect() {
  const changeBranchSelect = function () {
    const selectionTextField = $('#pull-target-branch');

    const baseName = selectionTextField.data('basename');
    const branchNameNew = $(this).data('branch');
    const branchNameOld = selectionTextField.data('branch');

    // Replace branch name to keep translation from HTML template
    selectionTextField.html(selectionTextField.html().replace(
      `${baseName}:${branchNameOld}`,
      `${baseName}:${branchNameNew}`
    ));
    selectionTextField.data('branch', branchNameNew); // update branch name in setting
  };
  $('#branch-select > .item').on('click', changeBranchSelect);
}