def analyse_tag(release: dict, project_info: dict, invalid_version_strings: List[str]) -> Optional[ReleaseTag]: """ Heuristics to find the version number and according meta-data for a release not marked with githubs release-feature but tagged with git. Compared to analyse_release this needs an extra API-call which makes this function considerably slower. """ project_name = project_info["name"] tag_name = release.get("ref", "refs/tags/")[10:] match_name = extract_version(tag_name, project_name) if match_name is not None: release_type, version = match_name else: invalid_version_strings.append(tag_name) return None tag_type = release["object"]["type"] tag_url = release["object"]["url"] html_url = project_info["html_url"] + "/releases/tag/" + quote_plus( tag_name) return ReleaseTag( version=version, page=html_url, release_type=release_type, tag_type=tag_type, tag_url=tag_url, )
def analyse_release(release: dict, project_info: dict) -> Optional[Release]: """ Heuristics to find the version number and according meta-data for a release marked with githubs release-feature """ project_name = project_info["name"] match_tag_name = extract_version( release.get("tag_name") or "", project_name) match_name = extract_version(release.get("name") or "", project_name) if (match_tag_name is not None and match_name is not None and match_tag_name != match_name): logger.warning( "Conflicting versions {} and {} for {} and {} in {}".format( match_tag_name, match_name, release["tag_name"], release["name"], project_name, )) return None elif match_tag_name is not None: release_type, version = match_tag_name original_version = release["tag_name"] elif match_name is not None: release_type, version = match_name original_version = release["name"] else: return None # Often prereleases aren't marked as such, so we need manually catch those cases if not release["prerelease"] and release_type != "stable": logger.info("Diverting release type: " + original_version) release["prerelease"] = True elif release["prerelease"] and release_type == "stable": release_type = "unstable" # Convert github's timestamps to wikidata dates date = string_to_wddate(release["published_at"]) return Release(version=version, date=date, page=release["html_url"], release_type=release_type)
def analyse_release(release: dict, project_name: str) -> Optional[dict]: """ Heuristics to find the version number """ match_tag_name = extract_version(release["tag_name"] or "", project_name) match_name = extract_version(release["name"] or "", project_name) if (match_tag_name is not None and match_name is not None and match_tag_name != match_name): logger.warning("Conflicting versions {} and {}".format( match_tag_name, match_name)) return None elif match_tag_name is not None: release_type, version = match_tag_name original_version = release["tag_name"] elif match_name is not None: release_type, version = match_name original_version = release["name"] else: logger.warning("Invalid version strings '{}' and '{}'".format( release["tag_name"], release["name"])) return None # Often prereleases aren't marked as such, so we need manually catch those cases if not release["prerelease"] and release_type != "stable": logger.info("Diverting release type: " + original_version) release["prerelease"] = True elif release["prerelease"] and release_type == "stable": release_type = "unstable" # Convert github's timestamps to wikidata dates date = pywikibot.WbTime.fromTimestr(release["published_at"], calendarmodel=Settings.calendarmodel) date.hour = 0 date.minute = 0 date.second = 0 date.precision = pywikibot.WbTime.PRECISION["day"] return { "version": version, "date": date, "page": release["html_url"], "release_type": release_type, }
def test_not_supported_yet(): """ Not yet supported formats These asserts will all fail. Improve the versionhandler to support them if possible and then move them up to the corresponding test. """ assert extract_version("4.9.0 RC2") == ("rc", "4.9.0") assert extract_version("v3.0.5.RELEASE") == ("stable", "3.0.5") assert extract_version("3.0.5-RELEASE") == ("stable", "3.0.5") assert extract_version("3.0.5.Final") == ("stable", "3.0.5") assert extract_version("v3.0-dev") == ("dev", "3.0") assert extract_version("v3.0.5dev") == ("dev", "3.0.5") assert extract_version("v3-0-5") == ("stable", "3.0.5")
def analyse_tag(release: dict, project_info: dict) -> Optional[Release]: """ Heuristics to find the version number and according meta-data for a release not marked with githubs release-feature but tagged with git. Compared to analyse_release this needs an extra API-call which makes this function considerably slower. """ project_name = project_info["name"] tag_name = release.get("ref", "refs/tags/")[10:] match_name = extract_version(tag_name, project_name) if match_name is not None: release_type, version = match_name else: logger.warning("Invalid version string '{}'".format(tag_name)) return None tag_type = release["object"]["type"] tag_url = release["object"]["url"] tag_details = get_json_cached(tag_url) if tag_type == "tag": # For some weird reason the api might not always have a date if not tag_details["tagger"]["date"]: logger.warning("No tag date for {} {}".format(tag_name, tag_url)) return None date = string_to_wddate(tag_details["tagger"]["date"]) elif tag_type == "commit": if not tag_details["committer"]["date"]: logger.warning("No tag date for {} {}".format(tag_name, tag_url)) return None date = string_to_wddate(tag_details["committer"]["date"]) else: raise NotImplementedError("Unknown type of tag: %s" % tag_type) html_url = project_info["html_url"] + "/releases/tag/" + quote_plus( tag_name) return Release(version=version, date=date, page=html_url, release_type=release_type)
def test_invalid(): assert extract_version("foo") is None assert extract_version("foo1.3") is None assert extract_version("1.3bar") is None assert extract_version("1.3beta1.4") is None assert extract_version("1.3beta 1.4-stable") is None assert extract_version("foo1.3bar") is None assert extract_version("foo1.3bar", "foo") is None assert extract_version("1.3 foo 2.3") is None assert extract_version("1.2.3-1.3") is None assert extract_version("2016-10-12") is None assert extract_version("2.1.2017") is None assert extract_version("foo 2015 bar") is None assert extract_version("foo #871") is None assert extract_version("RC1") is None assert extract_version("1234567") is None assert extract_version("mame0199", "mame") is None
def test_stable(): assert extract_version("0.23") == ("stable", "0.23") assert extract_version("0.23.5") == ("stable", "0.23.5") assert extract_version("1.23.5.1.3.4") == ("stable", "1.23.5.1.3.4") assert extract_version("foo 1.23.5 bar") == ("stable", "1.23.5") assert extract_version("v123") == ("stable", "123") assert extract_version("123") == ("stable", "123") assert extract_version("1.23f") == ("stable", "1.23f") assert extract_version("1.2-1") == ("stable", "1.2-1") assert extract_version("1.2-12") == ("stable", "1.2-12") assert extract_version("v1.2-12") == ("stable", "1.2-12") assert extract_version("0.23.5-stable") == ("stable", "0.23.5") assert extract_version("program 1.2", "program") == ("stable", "1.2") assert extract_version("program-1.2", "program") == ("stable", "1.2") assert extract_version("Program-1.2", "program") == ("stable", "1.2") assert extract_version("program1.2", "program") == ("stable", "1.2") assert extract_version("version-1.2") == ("stable", "1.2") assert extract_version("version/1.2") == ("stable", "1.2") assert extract_version("releases/1.2") == ("stable", "1.2") assert extract_version("release-1.2") == ("stable", "1.2") assert extract_version("release/1.2") == ("stable", "1.2") assert extract_version("rel/1.2") == ("stable", "1.2") assert extract_version("REL-1.2") == ("stable", "1.2") assert extract_version("vers1.2") == ("stable", "1.2") assert extract_version("v.1.2") == ("stable", "1.2") assert extract_version("3_0_5") == ("stable", "3.0.5") assert extract_version("3-0-5") == ("stable", "3.0.5")
def test_unstable(): assert extract_version("1.4alpha") == ("alpha", "1.4alpha") assert extract_version("program 1.4alpha", "program") == ("alpha", "1.4alpha") assert extract_version("1.3beta") == ("beta", "1.3beta") assert extract_version("1.3pre") == ("unstable", "1.3pre") assert extract_version("1.3-preview1") == ("unstable", "1.3-preview1") assert extract_version("1.3rc") == ("rc", "1.3rc") assert extract_version("1.3rc1") == ("rc", "1.3rc1") assert extract_version("1.4Alpha") == ("alpha", "1.4Alpha") assert extract_version("1.4.beta") == ("beta", "1.4.beta") assert extract_version("1.4-beta") == ("beta", "1.4-beta") assert extract_version("1.4-beta1") == ("beta", "1.4-beta1") assert extract_version("1.4-beta.1") == ("beta", "1.4-beta.1") assert extract_version("1.4-beta-1") == ("beta", "1.4-beta-1") assert extract_version("1.3b1") == ("beta", "1.3b1") assert extract_version("Picard 2.0.0beta3") == ("beta", "2.0.0beta3") assert extract_version("v1.0.0-beta3") == ("beta", "1.0.0-beta3") assert extract_version("9.3.2_RC1") == ("rc", "9.3.2_RC1") assert extract_version("v2.1-rc1") == ("rc", "2.1-rc1") assert extract_version("v4.9.0-RC2") == ("rc", "4.9.0-RC2")
def test_invalid_version_str(version_str): assert extract_version(version_str) is None
def test_version_with_name(version, result): assert extract_version(*version) == result
def test_version_str(version_str, result): assert extract_version(version_str) == result
def test_invalid_version_with_name(version): assert extract_version(*version) is None
def test_stable(): assert extract_version("0.23") == ("stable", "0.23") assert extract_version("0.23.5") == ("stable", "0.23.5") assert extract_version("1.23.5.1.3.4") == ("stable", "1.23.5.1.3.4") assert extract_version("foo 1.23.5 bar") == ("stable", "1.23.5") assert extract_version("v123") == ("stable", "123") assert extract_version("123") == ("stable", "123") assert extract_version("1.23f") == ("stable", "1.23f") assert extract_version("1.2-1") == ("stable", "1.2-1") assert extract_version("1.2-12") == ("stable", "1.2-12") assert extract_version("v1.2-12") == ("stable", "1.2-12") assert extract_version("0.23.5-stable") == ("stable", "0.23.5") assert extract_version("program 1.2", "program") == ("stable", "1.2") assert extract_version("program-1.2", "program") == ("stable", "1.2") assert extract_version("Program-1.2", "program") == ("stable", "1.2")