Skip to content

Commit

Permalink
Partial WIP
Browse files Browse the repository at this point in the history
fix trainling s not matching, and catching 403 due to exhausted
requests.
  • Loading branch information
Carreau committed Sep 30, 2024
1 parent 918800e commit a5197e7
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 33 deletions.
10 changes: 5 additions & 5 deletions docs/community/topics/kitchen-sink.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ The source files for these pages are stored [in the `sphinx-themes.org` reposito
To update the kitchen sink source files, there is a helper Python script that will loop through the known kitchen sink files and copy over the latest text.
To use it, run the following from the root of the repository:

- This links to a [closed issue](https://github.com/pydata/pydata-sphinx-theme/issues/1882) on GitHub
- That to an [opened issue](https://github.com/pydata/pydata-sphinx-theme/issues/1895)
- Pull Requests can also be [open](https://github.com/pydata/pydata-sphinx-theme/issues/1888)
- But also [merged](https://github.com/pydata/pydata-sphinx-theme/issues/1893)
- Or simply [closed](https://github.com/pydata/pydata-sphinx-theme/issues/1853)
- This links to a [closed issue](https://github.com/pydata/pydata-sphinx-theme/issue/1882) on GitHub
- That to an [opened issue](https://github.com/pydata/pydata-sphinx-theme/issue/1895)
- Pull Requests can also be [open](https://github.com/pydata/pydata-sphinx-theme/issue/1888)
- But also [merged](https://github.com/pydata/pydata-sphinx-theme/issue/1893)
- Or simply [closed](https://github.com/pydata/pydata-sphinx-theme/issue/1853)
79 changes: 51 additions & 28 deletions src/pydata_sphinx_theme/theme/pydata_sphinx_theme/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,45 +23,68 @@
<script type="module">
import { Octokit, App } from "https://esm.sh/octokit";
const octokit = new Octokit();
window.octokit = octokit;
const anchorTags = document.querySelectorAll('a');

// Regular expression to match the desired GitHub issue URL pattern
const regex = /^https:\/\/github\.com\/([^\/]+)\/([^\/]+)\/(pulls|issues)\/(\d+)$/;
// the s in pulls/issues is technically wrong but we find it sometimes.
const regex = /^https:\/\/github\.com\/([^\/]+)\/([^\/]+)\/(pull|issue)s?\/(\d+)$/;

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

githubIssueLinks.map(async (atag) => {
const match = atag.href.match(regex);
if (match) {
const [fullUrl, username, repo,pr, issueNumber] = match;
console.log("[PST] Username:", username);
console.log("[PST] Repository:", repo);
console.log("[PST] Issue Number:", issueNumber);
const res = await octokit.request(`GET /repos/${username}/${repo}/issues/${issueNumber}`, {
//owner: 'OWNER',
//repo: 'REPO',
//issue_number: 'ISSUE_NUMBER',
headers: {
'X-GitHub-Api-Version': '2022-11-28'
// we can sometime be throttled, or just refused connection,
// just do one request on root, and if not 200, just do nothing.
const root_res = await octokit.request('GET /');
if (root_res.status == 200) {

githubIssueLinks.map(async (atag) => {
const match = atag.href.match(regex);
if (match) {
const [fullUrl, username, repo,pr, issueNumber] = match;
console.log("[PST] Username:", username);
console.log("[PST] Repository:", repo);
console.log("[PST] Issue Number:", issueNumber);
try {
// `issues` redirect pull requests as well
const tpl = `GET /repos/${username}/${repo}/issues/${issueNumber}`;
const res = await octokit.request(tpl, {
//owner: 'OWNER',
//repo: 'REPO',
//issue_number: 'ISSUE_NUMBER',
headers: {
'X-GitHub-Api-Version': '2024-09-30'
}
});
} catch (e){
console.debug('[PST] Error reaching github')
console.error(e);
return
}
console.debug('[PST] DEBUG: 1')
let pull_issue = 'unset';
console.debug('[PST] DEBUG: 2')
let state = 'unset';
console.debug('[PST] DEBUG: 3')
if (res.data.pull_request !== undefined){
console.debug('[PST] DEBUG: 4')
pull_issue = 'pull';
state = res.data.pull_request.merged_at != null ? 'merged': res.data.state ;
console.debug('[PST] DEBUG: 4b')
} else {
console.debug('[PST] DEBUG: 5')
pull_issue = 'issue';
state = res.data.state;
console.debug('[PST] DEBUG: 5b')
}
});
let pull_issue = 'unset';
let state = 'unset';
if (res.data.pull_request !== undefined){
pull_issue = 'pull';
state = res.data.pull_request.merged_at != null ? 'merged': res.data.state ;
} else {
pull_issue = 'issue';
state = res.data.state;
console.log('[PST] adding classes to', pull_issue, state);
atag.classList.add(`pst-gh-${pull_issue}`)
atag.classList.add(`pst-gh-${state}`)
}
console.log(pull_issue, state);
atag.classList.add(`pst-gh-${pull_issue}`)
atag.classList.add(`pst-gh-${state}`)
}
})
})
}

</script>
<style>
Expand Down

0 comments on commit a5197e7

Please sign in to comment.