Skip to content

Commit

Permalink
refactor tag fetches
Browse files Browse the repository at this point in the history
  • Loading branch information
silverwind committed Mar 18, 2024
1 parent 350ed7f commit 53b628c
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions updates.js
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,16 @@ async function getLastestCommit(user, repo) {
return {hash, commit};
}

// TODO: refactor this mess
// return list of tags sorted old to new
// TODO: newDate support, semver matching
async function getTags(user, repo) {
const res = await fetchGitHub(`${githubApiUrl}/repos/${user}/${repo}/git/refs/tags`);
if (!res || !res.ok) return;
const data = await res.json();
const tags = data.map(entry => entry.ref.replace(/^refs\/tags\//, ""));
return tags;
}

async function checkUrlDep([key, dep], {useGreatest} = {}) {
const stripped = dep.old.replace(stripRe, "");
const [_, user, repo, oldRef] = partsRe.exec(stripped) || [];
Expand All @@ -553,11 +562,8 @@ async function checkUrlDep([key, dep], {useGreatest} = {}) {
const newRange = dep.old.replace(oldRef, newRef);
return {key, newRange, user, repo, oldRef, newRef, newDate};
}
} else { // TODO: newDate support
const res = await fetch(`${githubApiUrl}/repos/${user}/${repo}/git/refs/tags`);
if (!res || !res.ok) return;
const data = await res.json();
const tags = data.map(entry => entry.ref.replace(/^refs\/tags\//, ""));
} else {
const tags = await getTags(user, repo);
const oldRefBare = oldRef.replace(/^v/, "");
if (!valid(oldRefBare)) return;

Expand Down

0 comments on commit 53b628c

Please sign in to comment.