From 4d367e307eed955faa811e1166217215bcb749d4 Mon Sep 17 00:00:00 2001 From: frantuma Date: Thu, 12 Oct 2023 21:11:41 +0200 Subject: [PATCH] python CI - encode request body --- CI/ghApiClient.py | 2 +- CI/test.py | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100755 CI/test.py diff --git a/CI/ghApiClient.py b/CI/ghApiClient.py index 60fbf230ee..fcec1eace8 100755 --- a/CI/ghApiClient.py +++ b/CI/ghApiClient.py @@ -39,7 +39,7 @@ def postUrl(name, body): request = urllib.request.Request(GH_BASE_URL + name) request.add_header("Authorization", GH_AUTH) request.add_header("Accept", "application/vnd.github.v3+json") - data = urllib.parse.urlencode(body).encode("utf-8") + data = body.encode('utf-8') content = urllib.request.urlopen(request, data).read() jcont = json.loads(content) return jcont diff --git a/CI/test.py b/CI/test.py new file mode 100755 index 0000000000..4c8d625973 --- /dev/null +++ b/CI/test.py @@ -0,0 +1,60 @@ +#!/usr/bin/python + +import sys +import json +from datetime import datetime +import ghApiClient + +def allPulls(releaseDate): + + result = "" + + baseurl = "https://api.github.com/repos/swagger-api/swagger-core/pulls/" + content = ghApiClient.readUrl('repos/swagger-api/swagger-core/pulls?state=closed&base=master&per_page=100') + for l in content: + stripped = l["url"][len(baseurl):] + mergedAt = l["merged_at"] + if mergedAt is not None: + if datetime.strptime(mergedAt, '%Y-%m-%dT%H:%M:%SZ') > releaseDate: + if not l['title'].startswith("bump snap"): + result += '\n' + result += "* " + l['title'] + " (#" + stripped + ")" + return result + + +def lastReleaseDate(tag): + content = ghApiClient.readUrl('repos/swagger-api/swagger-core/releases/tags/' + tag) + publishedAt = content["published_at"] + return datetime.strptime(publishedAt, '%Y-%m-%dT%H:%M:%SZ') + + +def addRelease(release_title, tag, content): + payload = "{\"tag_name\":\"" + tag + "\", " + payload += "\"name\":" + json.dumps(release_title) + ", " + payload += "\"body\":" + json.dumps(content) + ", " + payload += "\"draft\":" + "true" + ", " + payload += "\"prerelease\":" + "false" + ", " + payload += "\"target_commitish\":\"" + "master" + "\"}" + content = ghApiClient.postUrl('repos/swagger-api/swagger-core/releases', payload) + return content + +def getReleases(): + content = ghApiClient.readUrl('repos/swagger-api/swagger-core/releases') + return content + +# main +def main(last_release, release_title, tag): + baseurl = "https://api.github.com/repos/swagger-api/swagger-core/pulls/" + payload = "{\"tag_name\":\"" + tag + "\", " + payload += "\"name\":" + json.dumps(release_title) + ", " + payload += "\"body\":" + json.dumps(content) + ", " + payload += "\"draft\":" + "true" + ", " + payload += "\"prerelease\":" + "false" + ", " + payload += "\"target_commitish\":\"" + "master" + "\"}" + content = ghApiClient.postUrl('repos/swagger-api/swagger-core/releases', payload) + result = allPulls(lastReleaseDate('v' + last_release)) + addRelease (release_title, tag, result) + +# here start main +main(sys.argv[1], sys.argv[2], sys.argv[3]) +