forked from ydb-platform/ydb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: add more details to PR comment about build and tests (ydb-platfor…
- Loading branch information
Showing
6 changed files
with
162 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import json | ||
import argparse | ||
from github import Github, Auth as GithubAuth | ||
from github.PullRequest import PullRequest | ||
from gh_status import update_pr_comment_text | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--rewrite", dest="rewrite", action="store_true") | ||
parser.add_argument("--color", dest="color", default="white") | ||
parser.add_argument("--fail", dest="fail", action="store_true") | ||
parser.add_argument("--ok", dest="ok", action="store_true") | ||
parser.add_argument("text", type=argparse.FileType("r"), nargs="?", default="-") | ||
|
||
args = parser.parse_args() | ||
color = args.color | ||
|
||
if args.ok: | ||
color = 'green' | ||
elif args.fail: | ||
color = 'red' | ||
|
||
build_preset = os.environ["BUILD_PRESET"] | ||
|
||
gh = Github(auth=GithubAuth.Token(os.environ["GITHUB_TOKEN"])) | ||
|
||
with open(os.environ["GITHUB_EVENT_PATH"]) as fp: | ||
event = json.load(fp) | ||
|
||
pr = gh.create_from_raw_data(PullRequest, event["pull_request"]) | ||
|
||
update_pr_comment_text(pr, build_preset, color, args.text.read().rstrip(), args.rewrite) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import datetime | ||
import platform | ||
from github.PullRequest import PullRequest | ||
|
||
|
||
def get_timestamp(): | ||
return datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC") | ||
|
||
|
||
def get_platform_name(): | ||
return f'{platform.system().lower()}-{platform.machine()}' | ||
|
||
|
||
def update_pr_comment_text(pr: PullRequest, build_preset: str, color: str, text: str, rewrite: bool): | ||
platform_name = get_platform_name() | ||
header = f"<!-- status pr={pr.number}, preset={platform_name}-{build_preset} -->" | ||
|
||
body = comment = None | ||
for c in pr.get_issue_comments(): | ||
if c.body.startswith(header): | ||
print(f"found comment id={c.id}") | ||
comment = c | ||
if not rewrite: | ||
body = [c.body] | ||
break | ||
|
||
if body is None: | ||
body = [header] | ||
|
||
indicator = f":{color}_circle:" | ||
body.append(f"{indicator} `{get_timestamp()}` {text}") | ||
|
||
body = "\n".join(body) | ||
|
||
if '{platform_name}' in body: | ||
# input can contain '{platform_name}' | ||
body = body.replace('{platform_name}', platform_name) | ||
|
||
if comment is None: | ||
print(f"post new comment") | ||
pr.create_issue_comment(body) | ||
else: | ||
print(f"edit comment") | ||
comment.edit(body) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters