This is an automated email from the ASF dual-hosted git repository. yjc pushed a commit to branch manage-github-workflow in repository https://gitbox.apache.org/repos/asf/incubator-superset.git
commit f289e65137b40acc4498b66d1e2fa15c2aa8b5b0 Author: Jesse Yang <[email protected]> AuthorDate: Fri Dec 4 20:05:00 2020 -0800 Fix branch cancel --- scripts/cancel_github_workflows.py | 23 +++++++++++++---------- setup.cfg | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/scripts/cancel_github_workflows.py b/scripts/cancel_github_workflows.py index e46d6ca..8539f37 100755 --- a/scripts/cancel_github_workflows.py +++ b/scripts/cancel_github_workflows.py @@ -3,14 +3,14 @@ Manually GitHub workflow runs """ import os -from typing import List, Iterable, Union, Optional +from dateutil import parser +from typing import Iterable, List, Optional, Union -import requests import click +import requests from click.exceptions import ClickException from typing_extensions import Literal - github_token = os.environ.get("GITHUB_TOKEN") @@ -43,7 +43,7 @@ def get_runs_by_branch( branch: str, user: Optional[str] = None, statuses: Iterable[str] = ("queued", "in_progress"), - events: Iterable[str] = ("pull_request",), + events: Iterable[str] = ("pull_request", "push"), ): """Get workflow runs associated with the given branch""" return [ @@ -52,7 +52,7 @@ def get_runs_by_branch( for status in statuses for item in list_runs(repo, {"event": event, "status": status})["workflow_runs"] if item["head_branch"] == branch - and (user is None or user == item["head_repository"]["owner"]["login"]) + and (user is None or (user == item["head_repository"]["owner"]["login"])) ] @@ -61,9 +61,9 @@ def print_commit(commit): indented_message = " \n".join(commit["message"].split("\n")) print( f""" -HEAD {commit["id"]} +HEAD {commit["id"]} Author: {commit["author"]["name"]} <{commit["author"]["email"]}> -Date: {commit["timestamp"]} +Date: {parser.parse(commit["timestamp"]).astimezone(tz=None).strftime("%a, %d %b %Y %H:%M:%S")} {indented_message} """ @@ -79,7 +79,7 @@ Date: {commit["timestamp"]} @click.option( "--event", type=click.Choice(["pull_request", "push", "issue"]), - default=["pull_request"], + default=["pull_request", "push"], multiple=True, help="One of more pull_request, push or issue", ) @@ -88,7 +88,7 @@ Date: {commit["timestamp"]} ) @click.option( "--keep-running/--no-keep-running", - default=False, + default=True, help="Whether to skip cancelling running workflows", ) @click.argument("branch_or_pull") @@ -140,7 +140,9 @@ def cancel_github_workflows( # Find the head commit SHA of the last created workflow run runs = [x for x in runs if x["head_commit"]["id"] != last_sha] if not runs: - print("Only the latest runs are in queue. Use --no-keep-last to force cancelling them.\n") + print( + "Only the latest runs are in queue. Use --no-keep-last to force cancelling them.\n" + ) return last_sha = None @@ -154,6 +156,7 @@ def cancel_github_workflows( print(f"[Cancled] {entry['name']}") print("") + if __name__ == "__main__": # pylint: disable=no-value-for-parameter cancel_github_workflows() diff --git a/setup.cfg b/setup.cfg index 44f7e0d..ec59008 100644 --- a/setup.cfg +++ b/setup.cfg @@ -30,7 +30,7 @@ combine_as_imports = true include_trailing_comma = true line_length = 88 known_first_party = superset -known_third_party =alembic,apispec,backoff,bleach,cachelib,celery,click,colorama,contextlib2,croniter,cryptography,dateutil,flask,flask_appbuilder,flask_babel,flask_caching,flask_compress,flask_login,flask_migrate,flask_sqlalchemy,flask_talisman,flask_testing,flask_wtf,freezegun,geohash,geopy,humanize,isodate,jinja2,markdown,markupsafe,marshmallow,msgpack,numpy,pandas,parameterized,parsedatetime,pathlib2,polyline,prison,pyarrow,pyhive,pytest,pytz,retry,selenium,setuptools,simplejson,slac [...] +known_third_party =alembic,apispec,backoff,bleach,cachelib,celery,click,colorama,contextlib2,croniter,cryptography,dateutil,flask,flask_appbuilder,flask_babel,flask_caching,flask_compress,flask_login,flask_migrate,flask_sqlalchemy,flask_talisman,flask_testing,flask_wtf,freezegun,geohash,geopy,humanize,isodate,jinja2,markdown,markupsafe,marshmallow,msgpack,numpy,pandas,parameterized,parsedatetime,pathlib2,polyline,prison,pyarrow,pyhive,pytest,pytz,requests,retry,selenium,setuptools,simple [...] multi_line_output = 3 order_by_type = false
