def update_issue_from_webhook(webhook: GitHubWebhook) -> None: github_issue = GitHubIssueModel(**webhook.issue.dict()) github_issue.state = get_state_from_issue(webhook.issue) if not webhook.issue: raise ValueError("Webhook does not contain an issue") try: lumina.database.operations.update_submission_github_issue( webhook.issue.number, github_issue) except ResultNotFound: log.exception("Could not update issue as not found in db")
def _make_submission(id: int, **kwargs) -> SubmissionModel: """Make a SubmissionModel with default values overridable by kwargs.""" return SubmissionModel( pk="fred_bloggs", sk=table.get_submission_sk(id), url=f"https://github.com/newtheatre/history-project/issues/{id}", target_id="00_01/romeo_and_juliet", target_name="Romeo and Juliet", target_type="show", message="The part of Romeo was played by a hamster.", created_at=dates.now(), submitter=SubmitterModel( id="fred_bloggs", name="Fred Bloggs", verified=True, ), github_issue=GitHubIssueModel( number=id, state="open", title="Romeo and Juliet", created_at=dates.now(), updated_at=dates.now(), closed_at=None, comments=0, ), ).copy(update=kwargs)
def test_make_issue_model(): issue = submissions.create_generic_submission_issue( submission_request=GenericSubmissionRequest( target_type="show", target_id="11_12/faust_is_dead", target_name="Faust is Dead", target_url= "https://history.newtheatre.org.uk/years/11_12/faust_is_dead/", subject="Test submission", message="This is a test submission.", submitter=None, ), member=MemberModel( pk="fred_bloggs", name="Fred Bloggs", email="*****@*****.**", year_of_graduation=2020, ), ) issue_model = submissions.make_issue_model(issue) assert issue_model == GitHubIssueModel( number=8, state=GitHubIssueState.OPEN, title="Test submission", created_at="2022-01-26T20:45:07", updated_at="2022-01-26T20:45:07", closed_at=None, comments=0, )
def test_issue_closed(self): with mock.patch( "lumina.database.operations.update_submission_github_issue", return_value=None, ) as mock_update_issue: webhooks.handle_webhook(ISSUE_CLOSED_HOOK) assert mock_update_issue.call_count == 1 assert mock_update_issue.call_args[0][1] == GitHubIssueModel( **ISSUE_CLOSED_HOOK.issue.dict())
def update_submission_github_issue(id: int, issue: GitHubIssueModel) -> SubmissionModel: submission = get_submission(id) get_member_table().update_item( Key={ MEMBER_PARTITION_KEY: submission.pk, MEMBER_SORT_KEY: get_submission_sk(id), }, UpdateExpression="set github_issue = :v", ExpressionAttributeValues={":v": issue.ddict()}, ) return get_submission(id)
def make_issue_model(issue: Issue) -> GitHubIssueModel: return GitHubIssueModel( number=issue.number, state=GitHubIssueState( issue.state ), # Does not handle completed state but only used for new issues title=issue.title, created_at=issue.created_at, updated_at=issue.updated_at, closed_at=issue.closed_at, comments=issue.comments, )
url="https://github.com/newtheatre/history-project/issues/2", target_id="00_01/a_show", target_type="show", target_name="A Show", created_at="2020-01-01T00:00:00Z", message="This is a message", submitter=SubmitterModel( id="fred_bloggs", verified=True, name="Fred Bloggs", ), github_issue=GitHubIssueModel( number=1, state=GitHubIssueState.OPEN, title="A title", created_at="2020-01-01T00:00:00Z", updated_at="2020-01-01T00:00:00Z", closed_at=None, comments=1, ), ) DUMMY_SUBMISSION_OLDER = SubmissionModel( pk="fred_bloggs", sk="submission/1", url="https://github.com/newtheatre/history-project/issues/1", target_id="00_01/a_show", target_type="show", target_name="A Show", created_at="2019-01-01T00:00:00Z", message="This is a message",