Skip to content

Commit

Permalink
repokitteh: implement retest azp (envoyproxy#12402)
Browse files Browse the repository at this point in the history
Signed-off-by: Lizan Zhou <[email protected]>
  • Loading branch information
lizan authored Aug 7, 2020
1 parent f809fbd commit fdab03e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
49 changes: 49 additions & 0 deletions ci/repokitteh/modules/azure_pipelines.star
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
load("github.com/repokitteh/modules/lib/utils.star", "react")

_azp_context_prefix = "ci/azp: "

def _retry_azp(organization, project, build_id, token):
"""Makes an Azure Pipelines Build API request with retry"""

url = "https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}?retry=true&api-version=5.1".format(organization = organization, project = project, buildId = build_id)
return http(url = url, method = "PATCH", headers = {
"authorization": "Basic " + token,
"content-type": "application/json;odata=verbose",
})

def _get_azp_checks():
github_checks = github.check_list_runs()["check_runs"]

check_ids = []
checks = []
for check in github_checks:
if check["app"]["slug"] == "azure-pipelines" and check["external_id"] not in check_ids:
check_ids.append(check["external_id"])
checks.append(check)

return checks

def _retry(config, comment_id, command):
msgs = "Retrying Azure Pipelines, to retry CircleCI checks, use `/retest-circle`.\n"
checks = _get_azp_checks()

retried_checks = []
for check in checks:
name_with_link = "[{}]({})".format(check["name"], check["details_url"])
if check["status"] != "completed":
msgs += "Cannot retry non-completed check: {}, please wait.\n".format(name_with_link)
elif check["conclusion"] != "failure":
msgs += "Check {} didn't fail.\n".format(name_with_link)
else:
_, build_id, project = check["external_id"].split("|")
_retry_azp("cncf", project, build_id, config["token"])
retried_checks.append(name_with_link)

if len(retried_checks) == 0:
react(comment_id, msgs)
else:
react(comment_id, None)
msgs += "Retried failed jobs in: {}".format(", ".join(retried_checks))
github.issue_create_comment(msgs)

handlers.command(name = "retry-azp", func = _retry)
4 changes: 3 additions & 1 deletion repokitteh.star
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use("github.com/repokitteh/modules/assign.star")
use("github.com/repokitteh/modules/review.star")
use("github.com/repokitteh/modules/wait.star")
use("github.com/repokitteh/modules/circleci.star", secret_token=get_secret('circle_token'))
use("github.com/envoyproxy/envoy/ci/repokitteh/modules/azure_pipelines.star", secret_token=get_secret('azp_token'))
use(
"github.com/envoyproxy/envoy/ci/repokitteh/modules/ownerscheck.star",
paths=[
Expand All @@ -28,7 +29,8 @@ use(
],
)

alias('retest', 'retry-circle')
alias('retest-circle', 'retry-circle')
alias('retest', 'retry-azp')

def _backport():
github.issue_label('backport/review')
Expand Down

0 comments on commit fdab03e

Please sign in to comment.