pydata / pydata-sphinx-theme

A clean, three-column Sphinx theme with Bootstrap for the PyData community
https://pydata-sphinx-theme.readthedocs.io
BSD 3-Clause "New" or "Revised" License
557 stars 300 forks source link

url shortening, use GitHub octokit.js to show issue/pull status. #1895

Open Carreau opened 1 week ago

Carreau commented 1 week ago

currently we are shortening github/gitlab url at build time,

It should be possible to use ocktokit js to run all all link on a page matching a specific pattern and mark the issue/PRs as closed/opened/merged, for example, the following fetch a open|close issue of IPython and a closed|opened|merged PR.

<script type="module">
import { Octokit, App } from "https://esm.sh/octokit";
const octokit = new Octokit();

for(var ni of [14454,14453,14464,14462,14460]){

    const res = await octokit.request('GET /repos/ipython/ipython/issues/'+ni, {
      //owner: 'OWNER',
      //repo: 'REPO',
      //issue_number: 'ISSUE_NUMBER',
      headers: {
        'X-GitHub-Api-Version': '2022-11-28'
      }
    })

    //console.info('res', ni, res.data)
    if (res.data.pull_request != undefined){
        console.info('is pull', res.data.pull_request.merged_at != null ? 'merged': res.data.state ); 
    } else {
        console.info('is issue',res.data.state);

    }
}

mixed with something like :

var anchorTags = document.querySelectorAll('a');

// Regular expression to match the desired GitHub issue URL pattern
var regex = /^https:\/\/github\.com\/[^\/]+\/[^\/]+\/issues\/\d+$/;

// Filter <a> tags that match the pattern
var githubIssueLinks = Array.prototype.filter.call(anchorTags, function(element) {
    return regex.test(element.href);
});

We should be able to find all links to Pulls/issues, and then I suggest adding a given class to the a (pst-github-[issue|pr|unknown]-[open|close|merged|unknonw]) that can be later targeted by css to either add a :before icon or change the styling.