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

Use js to show status of gh issues and PR #1896

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/community/topics/kitchen-sink.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ 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:

- [issue closed](https://github.com/pydata/pydata-sphinx-theme/issues/1882)
- [issue open](https://github.com/pydata/pydata-sphinx-theme/issues/1895)
- [pull open](https://github.com/pydata/pydata-sphinx-theme/issues/1888)
- [pull merged](https://github.com/pydata/pydata-sphinx-theme/issues/1893)
- [pull closed](https://github.com/pydata/pydata-sphinx-theme/issues/1853)
79 changes: 79 additions & 0 deletions src/pydata_sphinx_theme/theme/pydata_sphinx_theme/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,85 @@

</style>
</noscript>
<script type="module">
import { Octokit, App } from "https://esm.sh/octokit";
const octokit = new Octokit();
const anchorTags = document.querySelectorAll('a');

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

// Filter <a> tags that match the pattern
const githubIssueLinks = Array.prototype.filter.call(anchorTags, function(element) {
return regex.test(element.href);
});
Comment on lines +38 to +40
Copy link
Collaborator

Choose a reason for hiding this comment

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

The way you've written it is not wrong, but here is a bit more modern way to write the same thing:

Suggested change
const githubIssueLinks = Array.prototype.filter.call(anchorTags, function(element) {
return regex.test(element.href);
});
const githubIssueLinks = Array.prototype.filter.call(anchorTags, ({ href }) => regex.test(href));


githubIssueLinks.map(async (atag) => {
const match = atag.href.match(regex);
if (match) {
const [fullUrl, username, repo,pr, issueNumber] = match;
console.log("Username:", username);
console.log("Repository:", repo);
console.log("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'
}
});
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(pull_issue, state);
atag.classList.add(`pst-gh-${pull_issue}`)
atag.classList.add(`pst-gh-${state}`)
}
})

</script>
<style>
.pst-gh-open {
}
.pst-gh-closed {
}
.pst-gh-merged {
}
.pst-gh-open::before {
color: var(--pst-color-success);
}
.pst-gh-closed::before {
color: var(--pst-color-danger);
}

.pst-gh-merged::before {
color: var(--pst-color-accent);
}


.pst-gh-issue:before {
font-family: "Font Awesome 5 Free"; /* Ensure correct font family */
font-weight: 900; /* Adjust font weight if necessary */
content: "\f05a"; /* Unicode for the (i) icon */
margin-right: 5px; /* Optional: Adjust spacing between icon and text */
text-decoration: none;
}

.pst-gh-pull:before {
font-family: "Font Awesome 5 Free"; /* Ensure correct font family */
font-weight: 900; /* Adjust font weight if necessary */
content: "\f126"; /* Unicode for the pull-request icon */
margin-right: 5px; /* Optional: Adjust spacing between icon and text */
text-decoration: none;
}
</style>
{{ _webpack.head_pre_assets() }}
{{- css() }}
{{ _webpack.head_js_preload() }}
Expand Down
Loading