Skip to content

Commit

Permalink
Parse the st version range from the release body
Browse files Browse the repository at this point in the history
  • Loading branch information
rwols committed Sep 23, 2020
1 parent 4c73cea commit 352f986
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions auto-update-repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,27 @@
"""

from typing import Dict, Any
import argparse
import functools
import json
import os
import pathlib
import sys


def st_version_range_from_release_body(body: str) -> str:
"""
Retrieves the `"sublime_text"` value from the text in the release. If your
release text contains a line that starts with "Sublime-Text-Version-Range"
then it's assumed that that's what we need to extract. Otherwise, this
function defaults to returning the most recent minimal version range.
"""
prefix = "Sublime-Text-Version-Range: "
for line in body.splitlines():
if line.startswith(prefix):
return line[len(prefix):]
return ">=3154"


def extract_platform_from_asset_name(name: str) -> str:
"""
The release asset must be of the form
Expand Down Expand Up @@ -117,15 +130,14 @@ def set_workflow_output(**kwargs: str) -> None:


def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("--sublime-text-version-range", default=">=3154")
args = parser.parse_args()
source = json.load(sys.stdin)
release = source["release"]
tag_name = release["tag_name"]
date = translate_date(release["published_at"])
body = release["body"]
st_version_range = st_version_range_from_release_body(body)
f = functools.partial(translate_release_asset,
args.sublime_text_version_range, tag_name, date)
st_version_range, tag_name, date)
payload = {
"releases": [f(asset) for asset in release["assets"]],
"name": source["repository"]["name"],
Expand All @@ -148,10 +160,10 @@ def main() -> None:
fp.write("\n")
commit_title = "Update {}".format(name) if found else "Add {}".format(name)
set_workflow_output(
commit_message="{}\n\n{}".format(commit_title, release["body"]),
commit_message="{}\n\n{}".format(commit_title, body),
pr_title=commit_title,
pr_body="## Repo link\n{}\n\n## Release body\n{}".format(
payload["details"], release["body"])
payload["details"], body)
)


Expand Down

0 comments on commit 352f986

Please sign in to comment.