The expected text is missing from that page: https://github.com/fregante/webext-storage-cache/releases/tag/v2.3.1)
Sadly the count was quite difficult to get. Here was the previous attempt via API: https://github.com/sindresorhus/refined-github/pull/2771#discussion_r378109419
https://github.com/fregante/webext-storage-cache

What about something like this?
const getAheadByCount = cache.function(async (latestTag: string, defaultBranch: string): Promise<number> => {
let aheadCount = await fetchDom(`/${getRepoURL()}/releases/tag/${latestTag}`, '.release-header relative-time + a[href*="/compare/"]');
if (!aheadCount) {
aheadCount = await fetchDom(`/${getRepoURL()}/compare/${latestTag}...${defaultBranch}`, '#js-repo-pjax-container div.overall-summary > ul span');
}
// This text is "4 commits to master since this tag or 4 Commits"
return looseParseInt(aheadCount!.textContent!);
}, {
maxAge: 1 / 24, // One hour
staleWhileRevalidate: 2,
cacheKey: ([latestTag]) => `tag-ahead-by:${getRepoURL()}/${latestTag}`
});
Can't. Compare pages can be pretty heavy and slow as well though, just like the API.
This page takes a few seconds to load: https://github.com/sindresorhus/refined-github/compare/1.9.1...master
For the time being it would be good to just avoid that empty tooltip, for example by adding the tooltipped classes together with aria-label attribute, not before.
For the time being it would be good to just avoid that empty tooltip, for example by adding the
tooltippedclasses together witharia-labelattribute, not before.
Done: e422c8c
Could we make it a silent error?
I looked again into GraphQL but, while it has a before query, it appears to be completely ignored 🤷♂️
{
repository(owner: "sindresorhus", name: "refined-github") {
ref(qualifiedName: "master") {
target {
... on Commit {
id
history(first: 100, before: "e422c8c7fe3f531816d0e0a7867c09b9acc7b266 1") {
totalCount /* Also useless: it always includes ALL the commits */
edges {
node {
message
}
}
}
}
}
}
}
}
So instead I'm thinking we could:
shaLook for it in the latest 20 commits on defaultBranchRef
{
repository(owner: "sindresorhus", name: "refined-github") {
defaultBranchRef {
target {
... on Commit {
history(first: 20) {
edges {
node {
oid
}}}}}}}}
<sup>+</sup> in the latest-tag-buttonAfter all, the point of this information is to know whether we're on the latest commit. Anything above +20 (or missing/incorrect information) isn't particularly useful.
~TADA~ It was a nice try, but commits can be out of order.
const getAheadByCount = cache.function(async (latestTag: string, defaultBranch: string): Promise<number | undefined> => {
const tagPage = await fetchDom(
`/${getRepoURL()}/releases/tag/${latestTag}`,
'.release-header relative-time + a[href*="/compare/"], .release-header relative-time'
);
// This text is "4 commits to master since this tag"
return tagPage instanceof HTMLAnchorElement ?
Number(tagPage.textContent!.replace(/\D/g, '')) :
getCommitAheadCountFromApi(tagPage!.attributes.datetime.value, defaultBranch);
}, {
maxAge: 1 / 24, // One hour
staleWhileRevalidate: 2,
cacheKey: ([latestTag]) => `tag-ahead-by:${getRepoURL()}/${latestTag}`
});
const getCommitAheadCountFromApi = cache.function(async (date: string, defaultBranch: string): Promise<number> => {
const {repository} = await api.v4(`
repository(${getRepoGQL()}) {
ref(qualifiedName: "${defaultBranch}") {
target {
... on Commit {
history(first: 1, since: "${date}") {
totalCount
}
}
}
}
}
`);
return repository.ref.target.history.totalCount;
}, {
maxAge: 1 / 24, // One hour
staleWhileRevalidate: 2,
cacheKey: ([latestTag]) => `tag-ahead-by-api:${getRepoURL()}/${latestTag}`
});