From 8a3ced17d84275d7da95bf0fd13e9f5cb2b73355 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Mon, 10 Jan 2022 10:07:26 +0100 Subject: [PATCH 1/3] Add: New GitHub API for supporting actions Add new GitHub Actions core API for IO. --- pontos/github/actions/__init__.py | 16 +++ pontos/github/actions/core.py | 225 ++++++++++++++++++++++++++++++ tests/github/actions/__init__.py | 16 +++ tests/github/actions/test_core.py | 111 +++++++++++++++ 4 files changed, 368 insertions(+) create mode 100644 pontos/github/actions/__init__.py create mode 100644 pontos/github/actions/core.py create mode 100644 tests/github/actions/__init__.py create mode 100644 tests/github/actions/test_core.py diff --git a/pontos/github/actions/__init__.py b/pontos/github/actions/__init__.py new file mode 100644 index 000000000..9bb9516b6 --- /dev/null +++ b/pontos/github/actions/__init__.py @@ -0,0 +1,16 @@ +# Copyright (C) 2022 Greenbone Networks GmbH +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . diff --git a/pontos/github/actions/core.py b/pontos/github/actions/core.py new file mode 100644 index 000000000..3bd607ffe --- /dev/null +++ b/pontos/github/actions/core.py @@ -0,0 +1,225 @@ +# Copyright (C) 2021 Greenbone Networks GmbH +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import contextlib +import os + +from typing import Optional + + +def _to_options( + name: str = None, + line: str = None, + end_line: str = None, + column: str = None, + end_column: str = None, + title: str = None, +): + options = [] + if name: + options.append(f"file={name}") + if line: + options.append(f"line={line}") + if end_line: + options.append(f"endLine={end_line}") + if column: + options.append(f"col={column}") + if end_column: + options.append(f"endColumn={end_column}") + if title: + options.append(f"title={title}") + return ",".join(options) + + +def _message( + message_type: str, + message: str, + *, + name: str = None, + line: str = None, + end_line: str = None, + column: str = None, + end_column: str = None, + title: str = None, +): + options = _to_options(name, line, end_line, column, end_column, title) + print(f"::{message_type} {options}::{message}") + + +class Console: + """ + Class for printing messages to the action console + """ + + @classmethod + @contextlib.contextmanager + def group(cls, title: str): + """ + ContextManager to display a foldable group + + Args: + title: Title of the group + """ + cls.start_group(title) + yield + cls.end_group() + + @staticmethod + def start_group(title: str): + """ + Start a new folable group + + Args: + title: Title of the group + """ + print(f"::group::{title}") + + @staticmethod + def end_group(): + """ + End the last group + """ + print("::endgroup::") + + @staticmethod + def warning( + message: str, + *, + name: str = None, + line: str = None, + end_line: str = None, + column: str = None, + end_column: str = None, + title: str = None, + ): + """ + Print a warning message + + This message will also be shown at the action summary + """ + _message( + "warning", + message, + name=name, + line=line, + end_line=end_line, + column=column, + end_column=end_column, + title=title, + ) + + @staticmethod + def error( + message: str, + *, + name: str = None, + line: str = None, + end_line: str = None, + column: str = None, + end_column: str = None, + title: str = None, + ): + """ + Print an error message + + This message will also be shown at the action summary + """ + _message( + "error", + message, + name=name, + line=line, + end_line=end_line, + column=column, + end_column=end_column, + title=title, + ) + + @staticmethod + def notice( + message: str, + *, + name: str = None, + line: str = None, + end_line: str = None, + column: str = None, + end_column: str = None, + title: str = None, + ): + """ + Print a warning message + + This message will also be shown at the action summary + """ + _message( + "notice", + message, + name=name, + line=line, + end_line=end_line, + column=column, + end_column=end_column, + title=title, + ) + + @staticmethod + def log( + message: str, + ): + """ + Print a message to the console + """ + print(message) + + @staticmethod + def debug(message: str): + # pylint: disable=line-too-long + """ + Print a debug message to the console + + These messages are only shown if the secret ACTIONS_STEP_DEBUG is set to true. + See https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/enabling-debug-logging#enabling-step-debug-logging + """ + print(f"::debug::{message}") + + +class ActionIO: + @staticmethod + def output(name: str, value: str): + """ + Set action output + + An action output can be consumed by another job + + Args: + name: Name of the output variable + value: Value of the output variable + """ + print(f"::set-output name={name}::{value}") + + @staticmethod + def input(name: str, default: Optional[str] = None) -> str: + """ + Get the value of an action input + + Args: + name: Name of the input variable + default: Use as default if the is no value for the variable + """ + return os.environ.get( + f"INPUT_{name.replace(' ', '_').upper()}", default + ) diff --git a/tests/github/actions/__init__.py b/tests/github/actions/__init__.py new file mode 100644 index 000000000..9bb9516b6 --- /dev/null +++ b/tests/github/actions/__init__.py @@ -0,0 +1,16 @@ +# Copyright (C) 2022 Greenbone Networks GmbH +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . diff --git a/tests/github/actions/test_core.py b/tests/github/actions/test_core.py new file mode 100644 index 000000000..ed34362ff --- /dev/null +++ b/tests/github/actions/test_core.py @@ -0,0 +1,111 @@ +# Copyright (C) 2021 Greenbone Networks GmbH +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import unittest + +from unittest.mock import MagicMock, patch + +from pontos.github.actions.core import ActionIO, Console + + +@patch("builtins.print") +class ConsoleTestCase(unittest.TestCase): + def test_start_group(self, print_mock): + Console.start_group("Foo") + print_mock.assert_called_once_with("::group::Foo") + + def test_end_group(self, print_mock): + Console.end_group() + print_mock.assert_called_once_with("::endgroup::") + + def test_group(self, print_mock): + with Console.group("Foo"): + print_mock.assert_called_once_with("::group::Foo") + + print_mock.assert_called_with("::endgroup::") + + def test_warning(self, print_mock): + Console.warning( + "foo", + name="bar", + line="123", + end_line="234", + column="1", + end_column="2", + title="Foo Bar", + ) + print_mock.assert_called_once_with( + "::warning file=bar,line=123,endLine=234,col=1,endColumn=2,title=Foo Bar::foo" # pylint: disable=line-too-long + ) + + def test_error(self, print_mock): + Console.error( + "foo", + name="bar", + line="123", + end_line="234", + column="1", + end_column="2", + title="Foo Bar", + ) + print_mock.assert_called_once_with( + "::error file=bar,line=123,endLine=234,col=1,endColumn=2,title=Foo Bar::foo" # pylint: disable=line-too-long + ) + + def test_notice(self, print_mock): + Console.notice( + "foo", + name="bar", + line="123", + end_line="234", + column="1", + end_column="2", + title="Foo Bar", + ) + print_mock.assert_called_once_with( + "::notice file=bar,line=123,endLine=234,col=1,endColumn=2,title=Foo Bar::foo" # pylint: disable=line-too-long + ) + + def test_log(self, print_mock): + Console.log("foo") + + print_mock.assert_called_once_with("foo") + + def test_debug(self, print_mock): + Console.debug("foo") + + print_mock.assert_called_once_with("::debug::foo") + + +class ActionIOTestCase(unittest.TestCase): + @patch.dict( + 'os.environ', {"INPUT_FOO": "1234", "INPUT_FOO_BAR": "2345"}, clear=True + ) + def test_input(self): + self.assertEqual(ActionIO.input("foo"), "1234") + self.assertEqual(ActionIO.input("FOO"), "1234") + self.assertEqual(ActionIO.input("FoO"), "1234") + + self.assertEqual(ActionIO.input("foo bar"), "2345") + self.assertEqual(ActionIO.input("FOO_BAR"), "2345") + self.assertEqual(ActionIO.input("FoO BaR"), "2345") + + @patch("builtins.print") + def test_output(self, print_mock: MagicMock): + ActionIO.output("foo", "bar") + + print_mock.assert_called_once_with("::set-output name=foo::bar") From 22c57ec3883129cbe6a5090461a55ff7fde21ee1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Mon, 10 Jan 2022 10:09:47 +0100 Subject: [PATCH 2/3] Add convenient class for getting GitHub action env variables --- pontos/github/actions/env.py | 79 +++++++++++++++++++++++++++++ tests/github/actions/test_env.py | 87 ++++++++++++++++++++++++++++++++ 2 files changed, 166 insertions(+) create mode 100644 pontos/github/actions/env.py create mode 100644 tests/github/actions/test_env.py diff --git a/pontos/github/actions/env.py b/pontos/github/actions/env.py new file mode 100644 index 000000000..b1ea6974f --- /dev/null +++ b/pontos/github/actions/env.py @@ -0,0 +1,79 @@ +# Copyright (C) 2021 Greenbone Networks GmbH +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import os + +from pathlib import Path +from typing import Optional + + +class GitHubEnvironment: + """ + Class to handle values from the GitHub Environment + + https://docs.github.com/en/actions/learn-github-actions/environment-variables + """ + + @property + def workspace(self) -> Optional[Path]: + workspace = os.environ.get("GITHUB_WORKSPACE") + return Path(workspace) if workspace else None + + @property + def repository(self) -> Optional[str]: + return os.environ.get("GITHUB_REPOSITORY") + + @property + def sha(self) -> Optional[str]: + return os.environ.get("GITHUB_SHA") + + @property + def ref(self) -> Optional[str]: + return os.environ.get("GITHUB_REF") + + @property + def ref_name(self) -> Optional[str]: + return os.environ.get("GITHUB_REF_NAME") + + @property + def event_path(self) -> Optional[Path]: + event_path = os.environ.get("GITHUB_EVENT_PATH") + return Path(event_path) if event_path else None + + @property + def head_ref(self) -> Optional[str]: + return os.environ.get("GITHUB_HEAD_REF") + + @property + def base_ref(self) -> Optional[str]: + return os.environ.get("GITHUB_BASE_REF") + + @property + def api_url(self) -> Optional[str]: + return os.environ.get("GITHUB_API_URL") + + @property + def actor(self) -> Optional[str]: + return os.environ.get("GITHUB_ACTOR") + + @property + def run_id(self) -> Optional[str]: + return os.environ.get("GITHUB_RUN_ID") + + @property + def action_id(self) -> Optional[str]: + return os.environ.get("GITHUB_ACTION") diff --git a/tests/github/actions/test_env.py b/tests/github/actions/test_env.py new file mode 100644 index 000000000..228f511c2 --- /dev/null +++ b/tests/github/actions/test_env.py @@ -0,0 +1,87 @@ +# Copyright (C) 2022 Greenbone Networks GmbH +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import unittest + +from pathlib import Path +from unittest.mock import patch + +from pontos.github.actions.env import GitHubEnvironment + + +class GitHubEnvironmentTestCase(unittest.TestCase): + @patch.dict('os.environ', {"GITHUB_WORKSPACE": "/foo/bar"}, clear=True) + def test_workspace(self): + env = GitHubEnvironment() + self.assertEqual(env.workspace, Path("/foo/bar")) + + @patch.dict('os.environ', {"GITHUB_REPOSITORY": "foo/bar"}, clear=True) + def test_repository(self): + env = GitHubEnvironment() + self.assertEqual(env.repository, "foo/bar") + + @patch.dict('os.environ', {"GITHUB_SHA": "123456"}, clear=True) + def test_sha(self): + env = GitHubEnvironment() + self.assertEqual(env.sha, "123456") + + @patch.dict('os.environ', {"GITHUB_REF": "ref/branches/main"}, clear=True) + def test_ref(self): + env = GitHubEnvironment() + self.assertEqual(env.ref, "ref/branches/main") + + @patch.dict('os.environ', {"GITHUB_REF_NAME": "main"}, clear=True) + def test_ref_name(self): + env = GitHubEnvironment() + self.assertEqual(env.ref_name, "main") + + @patch.dict('os.environ', {"GITHUB_EVENT_PATH": "/foo/bar"}, clear=True) + def test_event_path(self): + env = GitHubEnvironment() + self.assertEqual(env.event_path, Path("/foo/bar")) + + @patch.dict('os.environ', {"GITHUB_HEAD_REF": "foo"}, clear=True) + def test_head_ref(self): + env = GitHubEnvironment() + self.assertEqual(env.head_ref, "foo") + + @patch.dict('os.environ', {"GITHUB_BASE_REF": "main"}, clear=True) + def test_base_ref(self): + env = GitHubEnvironment() + self.assertEqual(env.base_ref, "main") + + @patch.dict( + 'os.environ', {"GITHUB_API_URL": "https://api.github.com"}, clear=True + ) + def test_api_url(self): + env = GitHubEnvironment() + self.assertEqual(env.api_url, "https://api.github.com") + + @patch.dict('os.environ', {"GITHUB_ACTOR": "greenbonebot"}, clear=True) + def test_actor(self): + env = GitHubEnvironment() + self.assertEqual(env.actor, "greenbonebot") + + @patch.dict('os.environ', {"GITHUB_RUN_ID": "12345"}, clear=True) + def test_run_id(self): + env = GitHubEnvironment() + self.assertEqual(env.run_id, "12345") + + @patch.dict('os.environ', {"GITHUB_ACTION": "54321"}, clear=True) + def test_action_id(self): + env = GitHubEnvironment() + self.assertEqual(env.action_id, "54321") From fc4499de37f1740d30dcee7ac71a5c0252618a27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Mon, 10 Jan 2022 10:10:23 +0100 Subject: [PATCH 3/3] Add classes for handling GitHub actions event data Every action run gets a file where the JSON event data is stored. The actual data of the event is documented in the webhooks. See https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads --- pontos/github/actions/event.py | 104 ++++ .../actions/test-pull-request-event.json | 509 ++++++++++++++++++ tests/github/actions/test_event.py | 60 +++ 3 files changed, 673 insertions(+) create mode 100644 pontos/github/actions/event.py create mode 100644 tests/github/actions/test-pull-request-event.json create mode 100644 tests/github/actions/test_event.py diff --git a/pontos/github/actions/event.py b/pontos/github/actions/event.py new file mode 100644 index 000000000..9528acbf3 --- /dev/null +++ b/pontos/github/actions/event.py @@ -0,0 +1,104 @@ +# Copyright (C) 2021 Greenbone Networks GmbH +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import json + +from dataclasses import dataclass +from enum import Enum +from pathlib import Path +from typing import Dict, Iterable + + +class PullRequestState(Enum): + OPEN = "open" + CLOSED = "closed" + + +@dataclass +class Label: + """ + A label of a pull request or issue + """ + + name: str + + +@dataclass +class Ref: + """ + A git branch reference + """ + + name: str + sha: str + + +@dataclass +class GitHubPullRequestEvent: + """ + Event data of a GitHub Pull Request + + https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#pull_request + """ + + draft: bool + number: int + labels: Iterable[str] + title: str + merged: bool + state: PullRequestState + base: Ref + head: Ref + + def __init__(self, pull_request_data: Dict[str, str]): + data = pull_request_data or {} + + self.draft = data.get("draft") + self.number = data.get("number") + self.labels = [Label(label.get("name")) for label in data.get("labels")] + self.title = data.get("title") + self.merged = data.get("merged") + self.state = PullRequestState(data.get("state")) + + base = data.get("base") or {} + self.base = Ref(base.get("ref"), base.get("sha")) + + head = data.get("head") or {} + self.head = Ref(head.get("ref"), head.get("sha")) + + +@dataclass +class GitHubEvent: + """ + GitHub Actions provides event data for the running action as JSON data in + a local file at the runner. + + The JSON data for the events is specified at + https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads + """ + + pull_request: GitHubPullRequestEvent + + def __init__(self, event_path: Path): + content = event_path.read_text(encoding="utf-8") + event_data = json.loads(content) if content else {} + pull_request_data = event_data.get("pull_request") + self.pull_request = ( + GitHubPullRequestEvent(pull_request_data) + if pull_request_data + else None + ) diff --git a/tests/github/actions/test-pull-request-event.json b/tests/github/actions/test-pull-request-event.json new file mode 100644 index 000000000..723e743ea --- /dev/null +++ b/tests/github/actions/test-pull-request-event.json @@ -0,0 +1,509 @@ +{ + "action": "labeled", + "label": { + "color": "a2eeef", + "default": true, + "description": "New feature or request", + "id": 3665050984, + "name": "enhancement", + "node_id": "LA_kwDOGkcHwM7adD1o", + "url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/labels/enhancement" + }, + "number": 1, + "pull_request": { + "_links": { + "comments": { + "href": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/issues/1/comments" + }, + "commits": { + "href": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/pulls/1/commits" + }, + "html": { + "href": "https://github.com/bjoernricks/pull-request-backport-action/pull/1" + }, + "issue": { + "href": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/issues/1" + }, + "review_comment": { + "href": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/pulls/comments{/number}" + }, + "review_comments": { + "href": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/pulls/1/comments" + }, + "self": { + "href": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/pulls/1" + }, + "statuses": { + "href": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/statuses/beeecfeee02f5a9e69c1f69dba6757df6e5c20f7" + } + }, + "active_lock_reason": null, + "additions": 25, + "assignee": null, + "assignees": [], + "author_association": "OWNER", + "auto_merge": null, + "base": { + "label": "bjoernricks:main", + "ref": "main", + "repo": { + "allow_auto_merge": false, + "allow_forking": true, + "allow_merge_commit": true, + "allow_rebase_merge": true, + "allow_squash_merge": true, + "allow_update_branch": false, + "archive_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/{archive_format}{/ref}", + "archived": false, + "assignees_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/assignees{/user}", + "blobs_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/git/blobs{/sha}", + "branches_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/branches{/branch}", + "clone_url": "https://github.com/bjoernricks/pull-request-backport-action.git", + "collaborators_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/collaborators{/collaborator}", + "comments_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/comments{/number}", + "commits_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/commits{/sha}", + "compare_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/compare/{base}...{head}", + "contents_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/contents/{+path}", + "contributors_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/contributors", + "created_at": "2021-12-22T13:13:11Z", + "default_branch": "main", + "delete_branch_on_merge": false, + "deployments_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/deployments", + "description": null, + "disabled": false, + "downloads_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/downloads", + "events_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/events", + "fork": false, + "forks": 0, + "forks_count": 0, + "forks_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/forks", + "full_name": "bjoernricks/pull-request-backport-action", + "git_commits_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/git/commits{/sha}", + "git_refs_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/git/refs{/sha}", + "git_tags_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/git/tags{/sha}", + "git_url": "git://github.com/bjoernricks/pull-request-backport-action.git", + "has_downloads": true, + "has_issues": true, + "has_pages": false, + "has_projects": true, + "has_wiki": true, + "homepage": null, + "hooks_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/hooks", + "html_url": "https://github.com/bjoernricks/pull-request-backport-action", + "id": 440862656, + "is_template": false, + "issue_comment_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/issues/comments{/number}", + "issue_events_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/issues/events{/number}", + "issues_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/issues{/number}", + "keys_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/keys{/key_id}", + "labels_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/labels{/name}", + "language": "Python", + "languages_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/languages", + "license": { + "key": "gpl-3.0", + "name": "GNU General Public License v3.0", + "node_id": "MDc6TGljZW5zZTk=", + "spdx_id": "GPL-3.0", + "url": "https://api.github.com/licenses/gpl-3.0" + }, + "merges_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/merges", + "milestones_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/milestones{/number}", + "mirror_url": null, + "name": "pull-request-backport-action", + "node_id": "R_kgDOGkcHwA", + "notifications_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/notifications{?since,all,participating}", + "open_issues": 1, + "open_issues_count": 1, + "owner": { + "avatar_url": "https://avatars.githubusercontent.com/u/897575?v=4", + "events_url": "https://api.github.com/users/bjoernricks/events{/privacy}", + "followers_url": "https://api.github.com/users/bjoernricks/followers", + "following_url": "https://api.github.com/users/bjoernricks/following{/other_user}", + "gists_url": "https://api.github.com/users/bjoernricks/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/bjoernricks", + "id": 897575, + "login": "bjoernricks", + "node_id": "MDQ6VXNlcjg5NzU3NQ==", + "organizations_url": "https://api.github.com/users/bjoernricks/orgs", + "received_events_url": "https://api.github.com/users/bjoernricks/received_events", + "repos_url": "https://api.github.com/users/bjoernricks/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/bjoernricks/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/bjoernricks/subscriptions", + "type": "User", + "url": "https://api.github.com/users/bjoernricks" + }, + "private": false, + "pulls_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/pulls{/number}", + "pushed_at": "2021-12-23T06:59:02Z", + "releases_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/releases{/id}", + "size": 41, + "ssh_url": "git@github.com:bjoernricks/pull-request-backport-action.git", + "stargazers_count": 0, + "stargazers_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/stargazers", + "statuses_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/statuses/{sha}", + "subscribers_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/subscribers", + "subscription_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/subscription", + "svn_url": "https://github.com/bjoernricks/pull-request-backport-action", + "tags_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/tags", + "teams_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/teams", + "topics": [], + "trees_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/git/trees{/sha}", + "updated_at": "2021-12-22T17:28:48Z", + "url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action", + "visibility": "public", + "watchers": 0, + "watchers_count": 0 + }, + "sha": "50c0fbe90d0c19dba08165b707e8b720d604ed5d", + "user": { + "avatar_url": "https://avatars.githubusercontent.com/u/897575?v=4", + "events_url": "https://api.github.com/users/bjoernricks/events{/privacy}", + "followers_url": "https://api.github.com/users/bjoernricks/followers", + "following_url": "https://api.github.com/users/bjoernricks/following{/other_user}", + "gists_url": "https://api.github.com/users/bjoernricks/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/bjoernricks", + "id": 897575, + "login": "bjoernricks", + "node_id": "MDQ6VXNlcjg5NzU3NQ==", + "organizations_url": "https://api.github.com/users/bjoernricks/orgs", + "received_events_url": "https://api.github.com/users/bjoernricks/received_events", + "repos_url": "https://api.github.com/users/bjoernricks/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/bjoernricks/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/bjoernricks/subscriptions", + "type": "User", + "url": "https://api.github.com/users/bjoernricks" + } + }, + "body": null, + "changed_files": 3, + "closed_at": null, + "comments": 0, + "comments_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/issues/1/comments", + "commits": 3, + "commits_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/pulls/1/commits", + "created_at": "2021-12-23T06:45:17Z", + "deletions": 1, + "diff_url": "https://github.com/bjoernricks/pull-request-backport-action/pull/1.diff", + "draft": false, + "head": { + "label": "bjoernricks:label-test", + "ref": "label-test", + "repo": { + "allow_auto_merge": false, + "allow_forking": true, + "allow_merge_commit": true, + "allow_rebase_merge": true, + "allow_squash_merge": true, + "allow_update_branch": false, + "archive_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/{archive_format}{/ref}", + "archived": false, + "assignees_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/assignees{/user}", + "blobs_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/git/blobs{/sha}", + "branches_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/branches{/branch}", + "clone_url": "https://github.com/bjoernricks/pull-request-backport-action.git", + "collaborators_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/collaborators{/collaborator}", + "comments_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/comments{/number}", + "commits_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/commits{/sha}", + "compare_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/compare/{base}...{head}", + "contents_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/contents/{+path}", + "contributors_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/contributors", + "created_at": "2021-12-22T13:13:11Z", + "default_branch": "main", + "delete_branch_on_merge": false, + "deployments_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/deployments", + "description": null, + "disabled": false, + "downloads_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/downloads", + "events_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/events", + "fork": false, + "forks": 0, + "forks_count": 0, + "forks_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/forks", + "full_name": "bjoernricks/pull-request-backport-action", + "git_commits_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/git/commits{/sha}", + "git_refs_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/git/refs{/sha}", + "git_tags_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/git/tags{/sha}", + "git_url": "git://github.com/bjoernricks/pull-request-backport-action.git", + "has_downloads": true, + "has_issues": true, + "has_pages": false, + "has_projects": true, + "has_wiki": true, + "homepage": null, + "hooks_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/hooks", + "html_url": "https://github.com/bjoernricks/pull-request-backport-action", + "id": 440862656, + "is_template": false, + "issue_comment_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/issues/comments{/number}", + "issue_events_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/issues/events{/number}", + "issues_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/issues{/number}", + "keys_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/keys{/key_id}", + "labels_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/labels{/name}", + "language": "Python", + "languages_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/languages", + "license": { + "key": "gpl-3.0", + "name": "GNU General Public License v3.0", + "node_id": "MDc6TGljZW5zZTk=", + "spdx_id": "GPL-3.0", + "url": "https://api.github.com/licenses/gpl-3.0" + }, + "merges_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/merges", + "milestones_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/milestones{/number}", + "mirror_url": null, + "name": "pull-request-backport-action", + "node_id": "R_kgDOGkcHwA", + "notifications_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/notifications{?since,all,participating}", + "open_issues": 1, + "open_issues_count": 1, + "owner": { + "avatar_url": "https://avatars.githubusercontent.com/u/897575?v=4", + "events_url": "https://api.github.com/users/bjoernricks/events{/privacy}", + "followers_url": "https://api.github.com/users/bjoernricks/followers", + "following_url": "https://api.github.com/users/bjoernricks/following{/other_user}", + "gists_url": "https://api.github.com/users/bjoernricks/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/bjoernricks", + "id": 897575, + "login": "bjoernricks", + "node_id": "MDQ6VXNlcjg5NzU3NQ==", + "organizations_url": "https://api.github.com/users/bjoernricks/orgs", + "received_events_url": "https://api.github.com/users/bjoernricks/received_events", + "repos_url": "https://api.github.com/users/bjoernricks/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/bjoernricks/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/bjoernricks/subscriptions", + "type": "User", + "url": "https://api.github.com/users/bjoernricks" + }, + "private": false, + "pulls_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/pulls{/number}", + "pushed_at": "2021-12-23T06:59:02Z", + "releases_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/releases{/id}", + "size": 41, + "ssh_url": "git@github.com:bjoernricks/pull-request-backport-action.git", + "stargazers_count": 0, + "stargazers_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/stargazers", + "statuses_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/statuses/{sha}", + "subscribers_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/subscribers", + "subscription_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/subscription", + "svn_url": "https://github.com/bjoernricks/pull-request-backport-action", + "tags_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/tags", + "teams_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/teams", + "topics": [], + "trees_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/git/trees{/sha}", + "updated_at": "2021-12-22T17:28:48Z", + "url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action", + "visibility": "public", + "watchers": 0, + "watchers_count": 0 + }, + "sha": "beeecfeee02f5a9e69c1f69dba6757df6e5c20f7", + "user": { + "avatar_url": "https://avatars.githubusercontent.com/u/897575?v=4", + "events_url": "https://api.github.com/users/bjoernricks/events{/privacy}", + "followers_url": "https://api.github.com/users/bjoernricks/followers", + "following_url": "https://api.github.com/users/bjoernricks/following{/other_user}", + "gists_url": "https://api.github.com/users/bjoernricks/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/bjoernricks", + "id": 897575, + "login": "bjoernricks", + "node_id": "MDQ6VXNlcjg5NzU3NQ==", + "organizations_url": "https://api.github.com/users/bjoernricks/orgs", + "received_events_url": "https://api.github.com/users/bjoernricks/received_events", + "repos_url": "https://api.github.com/users/bjoernricks/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/bjoernricks/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/bjoernricks/subscriptions", + "type": "User", + "url": "https://api.github.com/users/bjoernricks" + } + }, + "html_url": "https://github.com/bjoernricks/pull-request-backport-action/pull/1", + "id": 808914229, + "issue_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/issues/1", + "labels": [ + { + "color": "a2eeef", + "default": true, + "description": "New feature or request", + "id": 3665050984, + "name": "enhancement", + "node_id": "LA_kwDOGkcHwM7adD1o", + "url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/labels/enhancement" + } + ], + "locked": false, + "maintainer_can_modify": false, + "merge_commit_sha": "0e34b424155397fe4cfc6a52db4b4c4a7961db79", + "mergeable": true, + "mergeable_state": "unstable", + "merged": false, + "merged_at": null, + "merged_by": null, + "milestone": null, + "node_id": "PR_kwDOGkcHwM4wNw01", + "number": 1, + "patch_url": "https://github.com/bjoernricks/pull-request-backport-action/pull/1.patch", + "rebaseable": true, + "requested_reviewers": [], + "requested_teams": [], + "review_comment_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/pulls/comments{/number}", + "review_comments": 0, + "review_comments_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/pulls/1/comments", + "state": "open", + "statuses_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/statuses/beeecfeee02f5a9e69c1f69dba6757df6e5c20f7", + "title": "Add foo for bar", + "updated_at": "2021-12-23T06:59:30Z", + "url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/pulls/1", + "user": { + "avatar_url": "https://avatars.githubusercontent.com/u/897575?v=4", + "events_url": "https://api.github.com/users/bjoernricks/events{/privacy}", + "followers_url": "https://api.github.com/users/bjoernricks/followers", + "following_url": "https://api.github.com/users/bjoernricks/following{/other_user}", + "gists_url": "https://api.github.com/users/bjoernricks/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/bjoernricks", + "id": 897575, + "login": "bjoernricks", + "node_id": "MDQ6VXNlcjg5NzU3NQ==", + "organizations_url": "https://api.github.com/users/bjoernricks/orgs", + "received_events_url": "https://api.github.com/users/bjoernricks/received_events", + "repos_url": "https://api.github.com/users/bjoernricks/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/bjoernricks/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/bjoernricks/subscriptions", + "type": "User", + "url": "https://api.github.com/users/bjoernricks" + } + }, + "repository": { + "allow_forking": true, + "archive_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/{archive_format}{/ref}", + "archived": false, + "assignees_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/assignees{/user}", + "blobs_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/git/blobs{/sha}", + "branches_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/branches{/branch}", + "clone_url": "https://github.com/bjoernricks/pull-request-backport-action.git", + "collaborators_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/collaborators{/collaborator}", + "comments_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/comments{/number}", + "commits_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/commits{/sha}", + "compare_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/compare/{base}...{head}", + "contents_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/contents/{+path}", + "contributors_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/contributors", + "created_at": "2021-12-22T13:13:11Z", + "default_branch": "main", + "deployments_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/deployments", + "description": null, + "disabled": false, + "downloads_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/downloads", + "events_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/events", + "fork": false, + "forks": 0, + "forks_count": 0, + "forks_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/forks", + "full_name": "bjoernricks/pull-request-backport-action", + "git_commits_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/git/commits{/sha}", + "git_refs_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/git/refs{/sha}", + "git_tags_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/git/tags{/sha}", + "git_url": "git://github.com/bjoernricks/pull-request-backport-action.git", + "has_downloads": true, + "has_issues": true, + "has_pages": false, + "has_projects": true, + "has_wiki": true, + "homepage": null, + "hooks_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/hooks", + "html_url": "https://github.com/bjoernricks/pull-request-backport-action", + "id": 440862656, + "is_template": false, + "issue_comment_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/issues/comments{/number}", + "issue_events_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/issues/events{/number}", + "issues_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/issues{/number}", + "keys_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/keys{/key_id}", + "labels_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/labels{/name}", + "language": "Python", + "languages_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/languages", + "license": { + "key": "gpl-3.0", + "name": "GNU General Public License v3.0", + "node_id": "MDc6TGljZW5zZTk=", + "spdx_id": "GPL-3.0", + "url": "https://api.github.com/licenses/gpl-3.0" + }, + "merges_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/merges", + "milestones_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/milestones{/number}", + "mirror_url": null, + "name": "pull-request-backport-action", + "node_id": "R_kgDOGkcHwA", + "notifications_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/notifications{?since,all,participating}", + "open_issues": 1, + "open_issues_count": 1, + "owner": { + "avatar_url": "https://avatars.githubusercontent.com/u/897575?v=4", + "events_url": "https://api.github.com/users/bjoernricks/events{/privacy}", + "followers_url": "https://api.github.com/users/bjoernricks/followers", + "following_url": "https://api.github.com/users/bjoernricks/following{/other_user}", + "gists_url": "https://api.github.com/users/bjoernricks/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/bjoernricks", + "id": 897575, + "login": "bjoernricks", + "node_id": "MDQ6VXNlcjg5NzU3NQ==", + "organizations_url": "https://api.github.com/users/bjoernricks/orgs", + "received_events_url": "https://api.github.com/users/bjoernricks/received_events", + "repos_url": "https://api.github.com/users/bjoernricks/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/bjoernricks/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/bjoernricks/subscriptions", + "type": "User", + "url": "https://api.github.com/users/bjoernricks" + }, + "private": false, + "pulls_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/pulls{/number}", + "pushed_at": "2021-12-23T06:59:02Z", + "releases_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/releases{/id}", + "size": 41, + "ssh_url": "git@github.com:bjoernricks/pull-request-backport-action.git", + "stargazers_count": 0, + "stargazers_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/stargazers", + "statuses_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/statuses/{sha}", + "subscribers_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/subscribers", + "subscription_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/subscription", + "svn_url": "https://github.com/bjoernricks/pull-request-backport-action", + "tags_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/tags", + "teams_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/teams", + "topics": [], + "trees_url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action/git/trees{/sha}", + "updated_at": "2021-12-22T17:28:48Z", + "url": "https://api.github.com/repos/bjoernricks/pull-request-backport-action", + "visibility": "public", + "watchers": 0, + "watchers_count": 0 + }, + "sender": { + "avatar_url": "https://avatars.githubusercontent.com/u/897575?v=4", + "events_url": "https://api.github.com/users/bjoernricks/events{/privacy}", + "followers_url": "https://api.github.com/users/bjoernricks/followers", + "following_url": "https://api.github.com/users/bjoernricks/following{/other_user}", + "gists_url": "https://api.github.com/users/bjoernricks/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/bjoernricks", + "id": 897575, + "login": "bjoernricks", + "node_id": "MDQ6VXNlcjg5NzU3NQ==", + "organizations_url": "https://api.github.com/users/bjoernricks/orgs", + "received_events_url": "https://api.github.com/users/bjoernricks/received_events", + "repos_url": "https://api.github.com/users/bjoernricks/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/bjoernricks/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/bjoernricks/subscriptions", + "type": "User", + "url": "https://api.github.com/users/bjoernricks" + } +} diff --git a/tests/github/actions/test_event.py b/tests/github/actions/test_event.py new file mode 100644 index 000000000..98a7a79a6 --- /dev/null +++ b/tests/github/actions/test_event.py @@ -0,0 +1,60 @@ +# Copyright (C) 2021 Greenbone Networks GmbH +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import unittest + +from pathlib import Path + +from pontos.github.actions.event import GitHubEvent, PullRequestState + +here = Path(__file__).parent + + +class GitHubPullRequestEventTestCase(unittest.TestCase): + def setUp(self) -> None: + event_path = Path(here / "test-pull-request-event.json") + event = GitHubEvent(event_path) + self.pull_request = event.pull_request + + def test_draft(self): + self.assertFalse(self.pull_request.draft) + + def test_labels(self): + self.assertEqual(len(self.pull_request.labels), 1) + self.assertEqual(self.pull_request.labels[0].name, "enhancement") + + def test_number(self): + self.assertEqual(self.pull_request.number, 1) + + def test_title(self): + self.assertEqual(self.pull_request.title, "Add foo for bar") + + def test_state(self): + self.assertEqual(self.pull_request.state, PullRequestState.OPEN) + + def test_base(self): + base = self.pull_request.base + self.assertEqual(base.name, "main") + self.assertEqual(base.sha, "50c0fbe90d0c19dba08165b707e8b720d604ed5d") + + def test_head(self): + head = self.pull_request.head + self.assertEqual(head.name, "label-test") + self.assertEqual(head.sha, "beeecfeee02f5a9e69c1f69dba6757df6e5c20f7") + + def test_merged(self): + self.assertEqual(self.pull_request.merged, False)