I am relatively new to the github api and I am struggling to get the latest tag of a given repo.
Q: Why I need that ?
A:
GitHub doesn't have an API to retrieve the latest tag, as it has for retrieving the latest release. That might be because tags could be arbitrary strings, not necessarily semvers, but it's not really an excuse, since tags have timestamps, and GitHub does sort tags lexicographically when returning them via its Tags API.
Anyway, to get the latest tag, you need to call that API, then sort the tags according to semver rules. Since these rules are non-trivial (see point 11 at that link), it's better to use the semver library (ported for the browser).
const gitHubPath = 'dandv/local-iso-dt'; // example repo
const url = 'https://api.github.com/repos/' + gitHubPath + '/tags';
$.get(url).done(data => {
const versions = data.sort((v1, v2) => semver.compare(v2.name, v1.name));
$('#result').html(versions[0].name);
});
Latest tag: