Skip to content

Commit

Permalink
PTFE-1484 add capability to create checkruns (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
tcarmet authored Mar 1, 2024
1 parent 455fd59 commit 8fa6031
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
46 changes: 46 additions & 0 deletions bert_e/git_host/github/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,24 @@ def add_comment(self, msg: str):
url = self.data['comments_url']
return Comment.create(self.client, {'body': msg}, url=url)

def add_checkrun(
self, name: str, status: str, conclusion: str,
title: str, summary: str):
return CheckRun.create(
client=self.client,
data={
'name': name,
'head_sha': self.src_commit,
'status': status,
'conclusion': conclusion,
'output': {
'title': title,
'summary': summary,
},
},
owner=self.repo.owner, repo=self.repo.slug
)

def get_comments(self):
return Comment.list(self.client, url=self.data['comments_url'])

Expand Down Expand Up @@ -974,6 +992,34 @@ def delete(self) -> None:
self.client.delete(self.data['url'])


class CheckRun(base.AbstractGitHostObject):
GET_URL = '/repos/{owner}/{repo}/check-runs/{id}'
CREATE_URL = '/repos/{owner}/{repo}/check-runs'

SCHEMA = schema.CheckRun
CREATE_SCHEMA = schema.CreateCheckRun

@property
def name(self) -> str:
return self.data['name']

@property
def status(self) -> str:
return self.data['status']

@property
def conclusion(self) -> str:
return self.data['conclusion']

@property
def title(self) -> str:
return self.data['output']['title']

@property
def summary(self) -> str:
return self.data['output']['summary']


class Review(base.AbstractGitHostObject):
LIST_URL = '/repos/{owner}/{repo}/pulls/{number}/reviews'
CREATE_URL = LIST_URL
Expand Down
16 changes: 16 additions & 0 deletions bert_e/git_host/github/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,28 @@ class AggregateCheckSuites(GitHubSchema):
check_suites = fields.Nested(CheckSuite, many=True)


class Output(GitHubSchema):
title = fields.Str()
summary = fields.Str()
text = fields.Str()


class CheckRun(GitHubSchema):
id = fields.Integer()
head_sha = fields.Str()
status = fields.Str()
conclusion = fields.Str(allow_none=True)
output = fields.Nested(Output)
html_url = fields.Url()
name = fields.Str()


class CreateCheckRun(GitHubSchema):
name = fields.Str()
head_sha = fields.Str()
status = fields.Str()
conclusion = fields.Str(allow_none=True)
output = fields.Nested(Output)


class WorkflowRun(GitHubSchema):
Expand Down
8 changes: 8 additions & 0 deletions bert_e/tests/unit/test_github_app_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,11 @@ def test_github_auth_app(client_app):
pr = repository.get_pull_request(1)
assert pr.id == 1347
assert client_app.headers['Authorization'].startswith('Bearer ') is True


def test_github_check_run(client_app):
repository = client_app.get_repository('octo-org', 'Hello-World')
pr = repository.get_pull_request(1)
check_run = pr.add_checkrun(
'bert-e', 'completed', 'success', 'title', 'summary')
assert check_run.name == check_run.data['name']

0 comments on commit 8fa6031

Please sign in to comment.