diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 41dad12e5..537ff3ea8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -48,6 +48,8 @@ This repository contains [docker-compose.yml](./docker-compose.yml) for Before you run it, we suggest that you open the file and read all the comments. You can also run only certain pieces of packit-service for local development (e.g. worker, database or service/httpd). +You also need to populate `secrets/packit/dev/` manually, for instructions +see [deployment repo](https://github.com/packit/deployment/tree/main/secrets). When you are running service/httpd and making requests to it, make sure that `server_name` configuration file in `packit-service.yaml` is set. diff --git a/Makefile b/Makefile index 434f7dd92..fba67ad2b 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,10 @@ BASE_IMAGE ?= quay.io/packit/base +# true|false +PULL_BASE_IMAGE ?= true SERVICE_IMAGE ?= quay.io/packit/packit-service:dev WORKER_IMAGE ?= quay.io/packit/packit-worker:dev TEST_IMAGE ?= quay.io/packit/packit-service-tests:stg +# missing|always|never PULL_TEST_IMAGE ?= missing TEST_TARGET ?= ./tests/unit ./tests/integration/ CONTAINER_ENGINE ?= $(shell command -v podman 2> /dev/null || echo docker) @@ -16,12 +19,20 @@ COMPOSE ?= docker-compose MY_ID ?= `id -u` service: files/install-deps.yaml files/recipe.yaml - $(CONTAINER_ENGINE) pull $(BASE_IMAGE) - $(CONTAINER_ENGINE) build --rm -t $(SERVICE_IMAGE) -f files/docker/Dockerfile --build-arg SOURCE_BRANCH=$(SOURCE_BRANCH) . + $(CONTAINER_ENGINE) build --rm \ + --pull=$(PULL_BASE_IMAGE) \ + -t $(SERVICE_IMAGE) \ + -f files/docker/Dockerfile \ + --build-arg SOURCE_BRANCH=$(SOURCE_BRANCH) \ + . worker: files/install-deps-worker.yaml files/recipe-worker.yaml - $(CONTAINER_ENGINE) pull $(BASE_IMAGE) - $(CONTAINER_ENGINE) build --rm -t $(WORKER_IMAGE) -f files/docker/Dockerfile.worker --build-arg SOURCE_BRANCH=$(SOURCE_BRANCH) . + $(CONTAINER_ENGINE) build --rm \ + --pull=$(PULL_BASE_IMAGE) \ + -t $(WORKER_IMAGE) \ + -f files/docker/Dockerfile.worker \ + --build-arg SOURCE_BRANCH=$(SOURCE_BRANCH) \ + . check: find . -name "*.pyc" -exec rm {} \; @@ -29,8 +40,16 @@ check: # In most cases you don't need to build your test-image, the one in registry should be all you need. build-test-image: files/install-deps-worker.yaml files/install-deps.yaml files/recipe-tests.yaml - $(CONTAINER_ENGINE) build --rm -t $(TEST_IMAGE) -f files/docker/Dockerfile.tests --build-arg SOURCE_BRANCH=$(SOURCE_BRANCH) . + $(CONTAINER_ENGINE) build --rm \ + -t $(TEST_IMAGE) \ + -f files/docker/Dockerfile.tests \ + --build-arg SOURCE_BRANCH=$(SOURCE_BRANCH) \ + . +# We use a test image pre-built (by Github action) from latest commit in main. +# The PULL_TEST_IMAGE specifies whether the image is downloaded before running tests in a container. +# Default is 'missing', which means that it's downloaded/updated ONLY if missing. +# Set PULL_TEST_IMAGE=always to pull/update the test image before running tests. check-in-container: @# don't use -ti here in CI, TTY is not allocated in zuul echo $(SOURCE_BRANCH) diff --git a/docker-compose.yml b/docker-compose.yml index af575bb61..5d202811f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -52,7 +52,6 @@ services: SOURCE_BRANCH: main image: quay.io/packit/packit-worker:dev command: /usr/bin/run_worker.sh - #tty: true depends_on: - redis - postgres diff --git a/files/check-inside-openshift.yaml b/files/check-inside-openshift.yaml index 5b2063532..3daceeacc 100644 --- a/files/check-inside-openshift.yaml +++ b/files/check-inside-openshift.yaml @@ -25,26 +25,26 @@ k8s: host: "{{ oc_server.stdout }}" api_key: "{{ kubeconfig_token.stdout }}" - validate_certs: no + validate_certs: false namespace: "{{ oc_project.stdout }}" resource_definition: "{{ lookup('file', './test-src-pvc.yaml') }}" - name: Start pod which mounts test-src-pvc to /src k8s: host: "{{ oc_server.stdout }}" api_key: "{{ kubeconfig_token.stdout }}" - validate_certs: no + validate_certs: false namespace: "{{ oc_project.stdout }}" resource_definition: "{{ lookup('file', './test-src-mounter.yaml') }}" - name: Wait for the pod to be running so we can rsync the files k8s: host: "{{ oc_server.stdout }}" api_key: "{{ kubeconfig_token.stdout }}" - validate_certs: no + validate_certs: false namespace: "{{ oc_project.stdout }}" name: mount-src api_version: v1 kind: Pod - wait: yes + wait: true wait_condition: type: Ready wait_timeout: 100 @@ -54,7 +54,7 @@ k8s: host: "{{ oc_server.stdout }}" api_key: "{{ kubeconfig_token.stdout }}" - validate_certs: no + validate_certs: false namespace: "{{ oc_project.stdout }}" name: mount-src api_version: v1 @@ -65,7 +65,7 @@ k8s: host: "{{ oc_server.stdout }}" api_key: "{{ kubeconfig_token.stdout }}" - validate_certs: no + validate_certs: false namespace: "{{ oc_project.stdout }}" name: "{{ tests_job_name }}" api_version: v1 @@ -75,7 +75,7 @@ k8s: host: "{{ oc_server.stdout }}" api_key: "{{ kubeconfig_token.stdout }}" - validate_certs: no + validate_certs: false namespace: "{{ oc_project.stdout }}" name: get-requre-data api_version: v1 @@ -85,13 +85,13 @@ k8s: host: "{{ oc_server.stdout }}" api_key: "{{ kubeconfig_token.stdout }}" - validate_certs: no + validate_certs: false namespace: "{{ oc_project.stdout }}" name: test-data-pvc api_version: v1 kind: PersistentVolumeClaim state: absent - wait: yes + wait: true wait_condition: type: Complete wait_timeout: 300 @@ -104,21 +104,21 @@ k8s: host: "{{ oc_server.stdout }}" api_key: "{{ kubeconfig_token.stdout }}" - validate_certs: no + validate_certs: false namespace: "{{ oc_project.stdout }}" name: "{{ tests_job_name }}" api_version: v1 kind: Job - wait: yes + wait: true wait_condition: type: Complete wait_timeout: 300 - ignore_errors: yes # we want to see logs either way + ignore_errors: true # we want to see logs either way - name: get test results k8s_info: host: "{{ oc_server.stdout }}" api_key: "{{ kubeconfig_token.stdout }}" - validate_certs: no + validate_certs: false namespace: "{{ oc_project.stdout }}" kind: Job name: "{{ tests_job_name }}" @@ -136,12 +136,12 @@ k8s: host: "{{ oc_server.stdout }}" api_key: "{{ kubeconfig_token.stdout }}" - validate_certs: no + validate_certs: false namespace: "{{ oc_project.stdout }}" name: get-requre-data api_version: v1 kind: Pod - wait: yes + wait: true wait_condition: type: Ready wait_timeout: 100 diff --git a/files/deployment-check.yaml b/files/deployment-check.yaml index 3a62e1c7c..fa98ea6eb 100644 --- a/files/deployment-check.yaml +++ b/files/deployment-check.yaml @@ -1,3 +1,6 @@ +# Copyright Contributors to the Packit project. +# SPDX-License-Identifier: MIT + --- - name: Check packit-service deployment hosts: all diff --git a/files/deployment.yaml b/files/deployment.yaml index 1f5491a08..80d6153e3 100644 --- a/files/deployment.yaml +++ b/files/deployment.yaml @@ -1,3 +1,6 @@ +# Copyright Contributors to the Packit project. +# SPDX-License-Identifier: MIT + --- # This file is the entrypoint to deploy packit-service to an openshift cluster (e.g. in Zuul) - name: Deploy dev version of packit-service into zuul. @@ -33,7 +36,7 @@ git: repo: "https://github.com/packit/deployment.git" dest: "{{ deployment_dir }}" - clone: yes + clone: true when: zuul is not defined - name: Generate secrets @@ -61,7 +64,7 @@ - name: get minishift ip command: minishift ip register: minishift_ip - ignore_errors: True + ignore_errors: true - set_fact: cluster_ip: "{{ minishift_ip.stdout if not minishift_ip.failed else '127.0.0.1' }}" diff --git a/files/install-deps-worker.yaml b/files/install-deps-worker.yaml index 69d905b45..64313f6d8 100644 --- a/files/install-deps-worker.yaml +++ b/files/install-deps-worker.yaml @@ -1,3 +1,6 @@ +# Copyright Contributors to the Packit project. +# SPDX-License-Identifier: MIT + --- - name: Install dependencies for packit-service worker hosts: all diff --git a/files/install-deps.yaml b/files/install-deps.yaml index cd77df49d..8ea97437e 100644 --- a/files/install-deps.yaml +++ b/files/install-deps.yaml @@ -1,3 +1,6 @@ +# Copyright Contributors to the Packit project. +# SPDX-License-Identifier: MIT + --- - name: Install dependencies for packit-service hosts: all @@ -14,7 +17,6 @@ # httpd & deps - python3-mod_wsgi - mod_ssl - #- python3-packit # temporary workaround for sake of marhsmallow - python3-pip # not included in base fedora:31 image, needed for next task # temporary dependencies - krb5-devel diff --git a/files/recipe-tests.yaml b/files/recipe-tests.yaml index 9182fb912..a57a34276 100644 --- a/files/recipe-tests.yaml +++ b/files/recipe-tests.yaml @@ -1,3 +1,6 @@ +# Copyright Contributors to the Packit project. +# SPDX-License-Identifier: MIT + --- - name: This is a recipe for a container image where packit-service tests will run hosts: all diff --git a/files/recipe-worker.yaml b/files/recipe-worker.yaml index ef62c49c4..e13087b71 100644 --- a/files/recipe-worker.yaml +++ b/files/recipe-worker.yaml @@ -1,3 +1,6 @@ +# Copyright Contributors to the Packit project. +# SPDX-License-Identifier: MIT + --- - name: This is a recipe for how to cook with packit-service worker hosts: all diff --git a/files/recipe.yaml b/files/recipe.yaml index 8fb0b5b99..8ea6da948 100644 --- a/files/recipe.yaml +++ b/files/recipe.yaml @@ -1,3 +1,6 @@ +# Copyright Contributors to the Packit project. +# SPDX-License-Identifier: MIT + --- - name: This is a recipe for how to cook with packit-service hosts: all diff --git a/files/tasks/common.yaml b/files/tasks/common.yaml index 44fc5f285..14d56c966 100644 --- a/files/tasks/common.yaml +++ b/files/tasks/common.yaml @@ -1,33 +1,38 @@ -# Tasks common to all images +# Copyright Contributors to the Packit project. +# SPDX-License-Identifier: MIT +# Tasks common to all images +- - name: Create /usr/share/packit - file: + ansible.builtin.file: state: directory path: /usr/share/packit + mode: 0775 - name: make packit home dir - file: + ansible.builtin.file: state: directory path: "{{ home_path }}" mode: 0776 - name: stat {{ packit_service_path }} - stat: + ansible.builtin.stat: path: "{{ packit_service_path }}" tags: - no-cache register: src_path - name: Let's make sure {{ packit_service_path }} is present - assert: + ansible.builtin.assert: that: - src_path.stat.isdir - name: Install packit-service from {{ packit_service_path }} - pip: + ansible.builtin.pip: name: "{{ packit_service_path }}" executable: pip3 - name: Clean all the cache files (especially pip) - file: + ansible.builtin.file: state: absent path: ~/.cache/ - name: Copy setup_env_in_openshift.sh - copy: + ansible.builtin.copy: src: setup_env_in_openshift.sh dest: /usr/bin/setup_env_in_openshift.sh + mode: 0775 diff --git a/files/tasks/httpd.yaml b/files/tasks/httpd.yaml index 4fc9b86a6..e048ae712 100644 --- a/files/tasks/httpd.yaml +++ b/files/tasks/httpd.yaml @@ -2,12 +2,12 @@ # SPDX-License-Identifier: MIT - name: Copy packit.wsgi file - copy: + ansible.builtin.copy: src: packit.wsgi dest: /usr/share/packit/packit.wsgi mode: 0664 - name: Copy run_httpd.sh - copy: + ansible.builtin.copy: src: run_httpd.sh dest: /usr/bin/run_httpd.sh mode: 0775 diff --git a/files/tasks/install-ogr-deps.yaml b/files/tasks/install-ogr-deps.yaml index e918f6893..2c5a8fd08 100644 --- a/files/tasks/install-ogr-deps.yaml +++ b/files/tasks/install-ogr-deps.yaml @@ -1,24 +1,29 @@ +# Copyright Contributors to the Packit project. +# SPDX-License-Identifier: MIT + # Install dependencies from setup.cfg as rpm packages for ogr - name: Download script setupcfg2rpm.py - get_url: + ansible.builtin.get_url: url: https://raw.githubusercontent.com/packit/deployment/main/scripts/setupcfg2rpm.py dest: ./setupcfg2rpm.py - mode: "0744" + mode: 0775 register: fetch_setupcfg2rpm until: fetch_setupcfg2rpm is not failed retries: 6 - name: Download ogr setup.cfg - get_url: + ansible.builtin.get_url: # ogr has only main branch url: https://raw.githubusercontent.com/packit/ogr/main/setup.cfg dest: ./ogr_setup.cfg + mode: 0664 register: fetch_ogr_setup until: fetch_ogr_setup is not failed retries: 6 - name: Install ogr dependencies provided by setupcfg2rpm - shell: dnf install $(./setupcfg2rpm.py ogr_setup.cfg) -y + ansible.builtin.shell: dnf install $(./setupcfg2rpm.py ogr_setup.cfg) -y args: - warn: no + warn: false become: true + changed_when: true diff --git a/files/tasks/install-packit-deps.yaml b/files/tasks/install-packit-deps.yaml index 6a0528ad1..75110b8e3 100644 --- a/files/tasks/install-packit-deps.yaml +++ b/files/tasks/install-packit-deps.yaml @@ -1,39 +1,49 @@ +# Copyright Contributors to the Packit project. +# SPDX-License-Identifier: MIT + # Install dependencies for packit - name: Download script setupcfg2rpm.py - get_url: + ansible.builtin.get_url: url: https://raw.githubusercontent.com/packit/deployment/main/scripts/setupcfg2rpm.py dest: ./setupcfg2rpm.py - mode: "0744" + mode: 0775 register: fetch_setupcfg2rpm until: fetch_setupcfg2rpm is not failed retries: 6 - name: Download packit spec file - get_url: + ansible.builtin.get_url: url: https://raw.githubusercontent.com/packit/packit/{{ source_branch }}/packit.spec dest: ./packit.spec + mode: 0664 register: fetch_packit_spec until: fetch_packit_spec is not failed retries: 6 - name: Install packit RPM build dependencies from packit.spec - shell: dnf builddep packit.spec -y + ansible.builtin.command: dnf builddep packit.spec -y args: - warn: no + warn: false + changed_when: true - name: Install packit RPM runtime dependencies - shell: dnf install $(rpmspec -q --requires packit.spec | grep -v 'packit') -y + ansible.builtin.shell: | + set -o pipefail + dnf install $(rpmspec -q --requires packit.spec | grep -v 'packit') -y args: - warn: no + warn: false become: true + changed_when: true - name: Download packit setup.cfg - get_url: + ansible.builtin.get_url: url: https://raw.githubusercontent.com/packit/packit/{{ source_branch }}/setup.cfg dest: ./packit_setup.cfg + mode: 0664 register: fetch_packit_setup until: fetch_packit_setup is not failed retries: 6 - name: Install dependencies provided by setupcfg2rpm - shell: dnf install $(./setupcfg2rpm.py packit_setup.cfg) + ansible.builtin.shell: dnf install $(./setupcfg2rpm.py packit_setup.cfg) become: true + changed_when: true diff --git a/files/tasks/process-source-branch.yaml b/files/tasks/process-source-branch.yaml index 1326903c6..4d1bd4b24 100644 --- a/files/tasks/process-source-branch.yaml +++ b/files/tasks/process-source-branch.yaml @@ -1,17 +1,20 @@ +# Copyright Contributors to the Packit project. +# SPDX-License-Identifier: MIT + # Check and if necessary adjust source_branch variable - name: Fail on empty source_branch variable - fail: + ansible.builtin.fail: msg: Variable source_branch, which is set from env variable SOURCE_BRANCH is empty. - when: source_branch == '' + when: source_branch | length == 0 # Docker Hub CI image builds are performed from non contributor's branches (eg. packit:fix_hook), # but we need it to be main or stable - name: Change source branch to main if is not main/stable - set_fact: + ansible.builtin.set_fact: source_branch: "main" when: - source_branch != 'stable' - source_branch != 'main' - name: Check source_branch value - debug: + ansible.builtin.debug: msg: source_branch is set to {{ source_branch }} diff --git a/packit_service/worker/events/enums.py b/packit_service/worker/events/enums.py index 10197c15f..5d1fd95f5 100644 --- a/packit_service/worker/events/enums.py +++ b/packit_service/worker/events/enums.py @@ -11,9 +11,10 @@ class PullRequestAction(Enum): class GitlabEventAction(Enum): - opened = "opened" - reopen = "reopen" - update = "update" + opened = "opened" # from state + closed = "closed" # from state + reopen = "reopen" # from action + update = "update" # from action class PullRequestCommentAction(Enum): diff --git a/packit_service/worker/handlers/copr.py b/packit_service/worker/handlers/copr.py index e4b53aa1e..a1c5debdc 100644 --- a/packit_service/worker/handlers/copr.py +++ b/packit_service/worker/handlers/copr.py @@ -44,6 +44,7 @@ ) from packit_service.service.urls import get_copr_build_info_url, get_srpm_build_info_url from packit_service.utils import dump_job_config, dump_package_config +from packit_service.worker.events.enums import GitlabEventAction from packit_service.worker.helpers.build import CoprBuildJobHelper from packit_service.worker.handlers.abstract import ( JobHandler, @@ -137,6 +138,13 @@ def run(self) -> TaskResults: return self.copr_build_helper.run_copr_build() def pre_check(self) -> bool: + if ( + self.data.event_type == MergeRequestGitlabEvent.__name__ + and self.data.action == GitlabEventAction.closed.value + ): + # Not interested in closed merge requests + return False + if self.data.event_type in ( PushGitHubEvent.__name__, PushGitlabEvent.__name__, diff --git a/packit_service/worker/handlers/koji.py b/packit_service/worker/handlers/koji.py index 6774c54ff..436258693 100644 --- a/packit_service/worker/handlers/koji.py +++ b/packit_service/worker/handlers/koji.py @@ -25,6 +25,7 @@ from packit_service.service.urls import ( get_koji_build_info_url, ) +from packit_service.worker.events.enums import GitlabEventAction from packit_service.worker.helpers.build.koji_build import KojiBuildJobHelper from packit_service.worker.events import ( CheckRerunCommitEvent, @@ -104,6 +105,13 @@ def run(self) -> TaskResults: return self.koji_build_helper.run_koji_build() def pre_check(self) -> bool: + if ( + self.data.event_type == MergeRequestGitlabEvent.__name__ + and self.data.action == GitlabEventAction.closed.value + ): + # Not interested in closed merge requests + return False + if self.data.event_type in ( PushGitHubEvent.__name__, PushGitlabEvent.__name__, diff --git a/packit_service/worker/handlers/testing_farm.py b/packit_service/worker/handlers/testing_farm.py index 9ce888da5..faefc8ec3 100644 --- a/packit_service/worker/handlers/testing_farm.py +++ b/packit_service/worker/handlers/testing_farm.py @@ -36,6 +36,7 @@ get_testing_farm_info_url, get_copr_build_info_url, ) +from packit_service.worker.events.enums import GitlabEventAction from packit_service.worker.handlers import JobHandler from packit_service.worker.handlers.abstract import ( TaskName, @@ -119,6 +120,13 @@ def check_if_actor_can_run_job_and_report(self, actor: str) -> bool: return True def pre_check(self) -> bool: + if ( + self.data.event_type == MergeRequestGitlabEvent.__name__ + and self.data.action == GitlabEventAction.closed.value + ): + # Not interested in closed merge requests + return False + return not ( self.testing_farm_job_helper.skip_build and self.is_copr_build_comment_event() diff --git a/packit_service/worker/parser.py b/packit_service/worker/parser.py index aecdb614b..5af0c235e 100644 --- a/packit_service/worker/parser.py +++ b/packit_service/worker/parser.py @@ -151,7 +151,7 @@ def parse_mr_event(event) -> Optional[MergeRequestGitlabEvent]: return None state = event["object_attributes"]["state"] - if state != "opened": + if state not in {"opened", "closed"}: return None action = nested_get(event, "object_attributes", "action") if action not in {"reopen", "update"}: diff --git a/tests/data/webhooks/gitlab/mr_closed.json b/tests/data/webhooks/gitlab/mr_closed.json new file mode 100644 index 000000000..ba5b6301d --- /dev/null +++ b/tests/data/webhooks/gitlab/mr_closed.json @@ -0,0 +1,143 @@ +{ + "object_kind": "merge_request", + "event_type": "merge_request", + "user": { + "id": 2952463, + "name": "Jiri Popelka", + "username": "jpopelka", + "avatar_url": "https://gitlab.com/uploads/-/system/user/avatar/2952463/avatar.png", + "email": "[REDACTED]" + }, + "project": { + "id": 19258958, + "name": "hello-world", + "description": "The most progressive command-line tool in the world.", + "web_url": "https://gitlab.com/packit-service/hello-world", + "avatar_url": null, + "git_ssh_url": "git@gitlab.com:packit-service/hello-world.git", + "git_http_url": "https://gitlab.com/packit-service/hello-world.git", + "namespace": "packit-service", + "visibility_level": 20, + "path_with_namespace": "packit-service/hello-world", + "default_branch": "master", + "ci_config_path": "", + "homepage": "https://gitlab.com/packit-service/hello-world", + "url": "git@gitlab.com:packit-service/hello-world.git", + "ssh_url": "git@gitlab.com:packit-service/hello-world.git", + "http_url": "https://gitlab.com/packit-service/hello-world.git" + }, + "object_attributes": { + "assignee_id": 2952463, + "author_id": 2952463, + "created_at": "2022-05-06 15:08:42 UTC", + "description": "", + "head_pipeline_id": null, + "id": 153884270, + "iid": 19, + "last_edited_at": null, + "last_edited_by_id": null, + "merge_commit_sha": null, + "merge_error": null, + "merge_params": { + "force_remove_source_branch": "1" + }, + "merge_status": "can_be_merged", + "merge_user_id": null, + "merge_when_pipeline_succeeds": false, + "milestone_id": null, + "source_branch": "innocent-change", + "source_project_id": 35945041, + "state_id": 2, + "target_branch": "master", + "target_project_id": 19258958, + "time_estimate": 0, + "title": "ja nic, to samo", + "updated_at": "2022-05-06 15:11:26 UTC", + "updated_by_id": null, + "url": "https://gitlab.com/packit-service/hello-world/-/merge_requests/19", + "source": { + "id": 35945041, + "name": "hello-world", + "description": "The most progressive command-line tool in the world.", + "web_url": "https://gitlab.com/jpopelka/hello-world", + "avatar_url": null, + "git_ssh_url": "git@gitlab.com:jpopelka/hello-world.git", + "git_http_url": "https://gitlab.com/jpopelka/hello-world.git", + "namespace": "Jiri Popelka", + "visibility_level": 20, + "path_with_namespace": "jpopelka/hello-world", + "default_branch": "master", + "ci_config_path": "", + "homepage": "https://gitlab.com/jpopelka/hello-world", + "url": "git@gitlab.com:jpopelka/hello-world.git", + "ssh_url": "git@gitlab.com:jpopelka/hello-world.git", + "http_url": "https://gitlab.com/jpopelka/hello-world.git" + }, + "target": { + "id": 19258958, + "name": "hello-world", + "description": "The most progressive command-line tool in the world.", + "web_url": "https://gitlab.com/packit-service/hello-world", + "avatar_url": null, + "git_ssh_url": "git@gitlab.com:packit-service/hello-world.git", + "git_http_url": "https://gitlab.com/packit-service/hello-world.git", + "namespace": "packit-service", + "visibility_level": 20, + "path_with_namespace": "packit-service/hello-world", + "default_branch": "master", + "ci_config_path": "", + "homepage": "https://gitlab.com/packit-service/hello-world", + "url": "git@gitlab.com:packit-service/hello-world.git", + "ssh_url": "git@gitlab.com:packit-service/hello-world.git", + "http_url": "https://gitlab.com/packit-service/hello-world.git" + }, + "last_commit": { + "id": "769beb0807cf0bafeb3357e787f8c2f8fd3ea42b", + "message": "the best improvement ever seen to mankind\n", + "title": "the best improvement ever seen to mankind", + "timestamp": "2022-05-06T17:06:07+02:00", + "url": "https://gitlab.com/packit-service/hello-world/-/commit/769beb0807cf0bafeb3357e787f8c2f8fd3ea42b", + "author": { + "name": "Jiri Popelka", + "email": "jpopelka@redhat.com" + } + }, + "work_in_progress": false, + "total_time_spent": 0, + "time_change": 0, + "human_total_time_spent": null, + "human_time_change": null, + "human_time_estimate": null, + "assignee_ids": [2952463], + "labels": [], + "state": "closed", + "blocking_discussions_resolved": true, + "action": "close" + }, + "labels": [], + "changes": { + "state_id": { + "previous": 1, + "current": 2 + }, + "updated_at": { + "previous": "2022-05-06 15:08:42 UTC", + "current": "2022-05-06 15:11:26 UTC" + } + }, + "repository": { + "name": "hello-world", + "url": "git@gitlab.com:packit-service/hello-world.git", + "description": "The most progressive command-line tool in the world.", + "homepage": "https://gitlab.com/packit-service/hello-world" + }, + "assignees": [ + { + "id": 2952463, + "name": "Jiri Popelka", + "username": "jpopelka", + "avatar_url": "https://gitlab.com/uploads/-/system/user/avatar/2952463/avatar.png", + "email": "[REDACTED]" + } + ] +} diff --git a/tests/unit/test_events.py b/tests/unit/test_events.py index 749e50da3..2c3d5877c 100644 --- a/tests/unit/test_events.py +++ b/tests/unit/test_events.py @@ -136,6 +136,11 @@ def merge_request_update(self): with open(DATA_DIR / "webhooks" / "gitlab" / "mr_update_event.json") as outfile: return json.load(outfile) + @pytest.fixture() + def merge_request_closed(self): + with open(DATA_DIR / "webhooks" / "gitlab" / "mr_closed.json") as outfile: + return json.load(outfile) + @pytest.fixture() def github_pr_comment_empty(self): with open( @@ -334,6 +339,11 @@ def test_parse_mr_action(self, merge_request_update): ).once() assert event_object.package_config + def test_parse_mr_closed(self, merge_request_closed): + event_object = Parser.parse_event(merge_request_closed) + assert isinstance(event_object, MergeRequestGitlabEvent) + assert event_object.action == GitlabEventAction.closed + def test_parse_pr(self, github_pr_webhook): event_object = Parser.parse_event(github_pr_webhook)