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

feat(platform): getIssue #10453

Merged
merged 4 commits into from
Jun 16, 2021
Merged

feat(platform): getIssue #10453

merged 4 commits into from
Jun 16, 2021

Conversation

rarkins
Copy link
Collaborator

@rarkins rarkins commented Jun 16, 2021

Changes:

Adds optional getIssue() function to platform with useCache exposed. Only needed for platforms which support interactive checkboxes.

Context:

This will be used for upcoming Dashboard race condition fix.

Documentation (please check one with an [x])

  • I have updated the documentation, or
  • No documentation update is required

How I've tested my work (please tick one)

I have verified these changes via:

  • Code inspection only, or
  • Newly added/modified unit tests, or
  • No unit tests but ran on a real repository, or
  • Both unit tests + ran on a real repository

@rarkins rarkins requested a review from viceice June 16, 2021 07:18
Copy link
Member

@viceice viceice left a comment

Choose a reason for hiding this comment

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

What about other platforms like gitea ?

@rarkins
Copy link
Collaborator Author

rarkins commented Jun 16, 2021

Does gitea have checkbox support now?

@viceice
Copy link
Member

viceice commented Jun 16, 2021

Does gitea have checkbox support now?

Yes, will be official supported in v1.15.0, PR merged.

I've a custom javascript to support clickable checkboxes for older versions:

/* eslint-env browser,es2020,greasemonkey */
/* global $,config */
(function () {
  'use strict';
  const prefix = '[VO] ';
  console.log(`${prefix}starting`);
  const cbRe = /^\s*- \[( |x)\] (.+)$/gm;

  try {
    const { owner, repo, type, id } = location.pathname?.match(/(?<owner>[^/]+)\/(?<repo>[^/]+)\/(?<type>pulls|issues)\/(?<id>\d+)/)?.groups ?? {};

    if (!owner) {
      console.log(`${prefix}issue / pr not found`);
      return;
    }

    if ($('#edit-title').length === 0) {
      console.log(`${prefix}no rights`);
      return;
    }

    /**
     *
     * @param {number} idx
     */
    async function process(idx) {
      /**
       * @type {{body:string}}
       */
      let { body } = await fetch(`/api/v1/repos/${owner}/${repo}/issues/${id}`).then((response) => response.json());
      const m = [...body.matchAll(cbRe)];

      if (!m[idx]) {
        console.log(`${prefix}not found: ${idx}`);
        return;
      }
      const line = m[idx];
      console.log(`${prefix}match:`, line[0]);
      body = body.replace(
        line[0],
        line[0].replace(/\[( |x)\]/, (_, val) => (val == ' ' ? '[x]' : '[ ]'))
      );

      body = JSON.stringify({ body });

      const headers = {
        'content-type': 'application/json',
        'X-Csrf-Token': config.csrf,
      };
      const resp = await fetch(`/api/v1/repos/${owner}/${repo}/issues/${id}`, {
        method: 'PATCH',
        headers,
        body,
      });

      if (!resp.ok) {
        return;
      }

      location.reload();
    }

    console.log(`${prefix}${owner}/${repo}/${type}#${id}`);

    $(document).on('click', '.timeline-item.comment.first .render-content .task-list-item > input', (e) => {
      if ($(e.target).closest('a').length > 0) return true;

      // disable checkboxes
      $('.timeline-item.comment.first .render-content .task-list-item > input').prop('disabled', true);

      const idx = $('.timeline-item.comment.first .render-content .task-list-item').index($(e.target).closest('.task-list-item'));
      console.log(`${prefix}click:`, idx);
      process(idx).catch((e) => console.error(`${prefix}unexpected error`, e));
    });

    // enable checkboxes
    $('.timeline-item.comment.first .render-content .task-list-item > input').prop('disabled', false);
  } catch (e) {
    console.error(`${prefix}unexpected error`, e);
  }
})();

😏

@rarkins
Copy link
Collaborator Author

rarkins commented Jun 16, 2021

Added gitea but code inspection only. @viceice please double check it

Copy link
Member

@viceice viceice left a comment

Choose a reason for hiding this comment

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

Added same implementation to gitea like github

@rarkins rarkins merged commit 4a99883 into main Jun 16, 2021
@rarkins rarkins deleted the feat/platform-get-issue branch June 16, 2021 13:53
@renovate-release
Copy link
Collaborator

🎉 This PR is included in version 25.43.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants