Link to CHANGELOG.md on Releases page #3930
fregante posted onGitHub
- Visit https://github.com/nodeca/js-yaml/releases
- See nothing useful
- Navigate to https://github.com/nodeca/js-yaml/blob/master/CHANGELOG.md because thats there the changelog is kept
We can send a HEAD request to $default/CHANGELOG.md
and link to it if it exists when visiting a releases page, perhaps just if the page doesn't have releases.
The unfortunate part is that the HTTP request is case-sensitive, so with this method we can only check and link to that specific but common format.
Could we use the GraphQL Search API to find files case-insensitively?
Could we use the GraphQL Search API to find files case-insensitively?
I don't think you can search for files or code using the GraphQL API (supported search types are only "ISSUE", "USER" and "REPO"). But we could do something like this:
query {
repository(owner: "<owner>" name: "<name>") {
lowercase: object(expression: "HEAD:changelog.md") {
...on Blob {
oid
}
}
uppercase: object(expression: "HEAD:CHANGELOG.md") {
...on Blob {
oid
}
}
}
}
or query all the top-level files and check if there's a changelog among them:
query {
repository(owner: "<owner>" name: "<name>") {
object(expression: "HEAD:") {
...on Tree {
entries {
name
}
}
}
}
}
We can use does-file-exist
(I think that is the name of the function)
https://github.com/sindresorhus/refined-github/blob/main/source/github-helpers/does-file-exist.tsx
import * as pageDetect from 'github-url-detection';
import features from '.';
import GitHubURL from '../github-helpers/github-url';
import doesFileExist from '../github-helpers/does-file-exist';
import {buildRepoURL} from '../github-helpers';
async function init(): Promise<void> {
const baseUrl = new GitHubURL(buildRepoURL('blob', 'HEAD'));
const hasChangeLogFile = (await Promise.all([
doesFileExist(baseUrl.assign({filePath: 'changelog.md'})),
doesFileExist(baseUrl.assign({filePath: 'CHANGELOG.md'}))
])).filter(Boolean);
console.log(hasChangeLogFile);
}
void features.add(__filebasename, {
include: [
pageDetect.isSingleTag
],
init
});
I think the tree
check by @cheap-glitch works best. The only drawback is that it won't work on repos with hundreds of files on the top level. I'm disappointed at how limited the GQL API is. Proper filters would be been useful in a lot of cases.
import elementReady from 'element-ready';
import * as pageDetect from 'github-url-detection';
import features from '.';
import * as api from '../github-helpers/api';
import {buildRepoURL} from '../github-helpers';
async function init(): Promise<void | false> {
if (await elementReady('.markdown-body', {waitForChildren: false})) {
return false;
}
const {repository} = await api.v4(`
repository() {
object(expression: "HEAD:") {
...on Tree {
entries {
name
}
}
}
}
`);
const {name} = repository.object.entries.find((file: {name: string}) => /changelog\.md/i.exec(file.name)) ?? {};
if (!name) {
return;
}
const url = buildRepoURL('blob', 'HEAD', name);
console.log(url);
}
void features.add(__filebasename, {
include: [
pageDetect.isSingleTag
],
awaitDomReady: false,
init
});
Something like this?
Looks right, except that elementReady should never be used as a negative: That condition is equivalent to “on dom ready, continue”, because the promise will only resolve with undefined at dom ready
I know, I was testing something.
Also should we make a check on repo root and save it to so we don't have to do a check? (We do this by the releases tab)
do a check so we don’t have to do a check
I don’t know what you mean and I don’t know what the advantage is
To detect if they have a change log. Saves an API request, since we know it exists.
OMG I re read what I wrote.
Should we check the DOM on isRepoRoot
to see if they have a changelog. Then later on we do not have to check.
@yakov116 for the two examples you posted in your PR - after updating my extension, I can see the button for the CHANGELOG.rst
file at pyca, but not the CHANGELOG.md
one at nodeca. Any idea?
@tooomm I can't reproduce this on Firefox. What exact steps did you follow to see this bug? Does it go away if you clear the extension cache? (you can find a button to clear the cache at the bottom of the extension options)
🙈 After clearing the extension cache, the working one for pyca disappeared as well after refreshing the site. I tried all the updated links in the PR in the meantime. I don't see any <kbd> 📖 CHANGELOG</kbd> button at the top anymore.
No matter if I go to https://github.com/sphinx-doc/sphinx/releases, https://github.com/sphinx-doc/sphinx/tags or https://github.com/sphinx-doc/sphinx/releases/tag/v3.5.1
I'm also using Firefox, 64bit, 85.0.2 on Windows 10 and Refined GitHub 21.2.19.
Any console error?
After clearing the extension cache, the working one for pyca disappeared as well after refreshing the site.
I can't reproduce this no matter how I try. Could this be an issue with your personal token? Did you enable all the scopes?
No matter if I go to sphinx-doc/sphinx/releases, sphinx-doc/sphinx/tags or sphinx-doc/sphinx@v3.5.1 (release)
This is normal, the changelog file of this repo is named CHANGES
so it isn't supported yet. That's what the new, unreleased PR is about.
This is normal, the changelog file of this repo is named CHANGES so it isn't supported yet. That's what the new, unreleased PR is about.
My bad, mixed it up with the linked new PR above my comment which has those examples linked. I randomly picked one of those.
It works now at pyca again after trying several times. Still not at nodeca. After trying like 5+ more times... it appears now at e.g. https://github.com/nodeca/js-yaml/releases, too. 🤷
After clearing the extension cache, the working one for pyca disappeared as well after refreshing the site.
I can't reproduce this no matter how I try. Could this be an issue with your personal token? Did you enable all the scopes?
I've no personal token setup! How should I know - as a user - that I have to and which of the many features require it? Settings only tell me it's optional. And the linked GitHub search is not really user friendly. A detailed search there reveals that link-to-changelog-file.tsx
is listed though. Not intuitive at all to connect the dots here. That's a different issue I guess.
No clue why it starts working after many tries - even with no token setup?!
Related messages in web console are:
Content Security Policy: The page's settings blocked the loading of a resource at data: ("media-src").
ℹ️ Refined GitHub → convert-release-to-draft → Personal token required for this feature index.tsx:54:10
ℹ️ Refined GitHub → bugs-tab → Personal token required for this feature index.tsx:54:10
ℹ️ Refined GitHub → repo-wide-file-finder → Personal token required for this feature index.tsx:54:10
Nothing mentioned about "link to changelog".